]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blame - test/grsecurity-2.9.1-3.9.8-201306302052.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.9.8-201306302052.patch
CommitLineData
bebe49c2
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 8ccbf27..afffeb4 100644
233--- a/Documentation/kernel-parameters.txt
234+++ b/Documentation/kernel-parameters.txt
235@@ -948,6 +948,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@@ -2147,6 +2151,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 b013cbe..4ca639b 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@@ -780,6 +840,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@@ -789,7 +851,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@@ -833,6 +895,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@@ -940,6 +1003,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@@ -955,7 +1020,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@@ -1021,7 +1086,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@@ -1061,6 +1126,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@@ -1221,6 +1287,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@@ -1357,17 +1425,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@@ -1377,11 +1449,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 70cd012..71b82cd 100644
815--- a/arch/arm/Kconfig
816+++ b/arch/arm/Kconfig
817@@ -1860,7 +1860,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 c79f61f..9ac0642 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 static inline u64 atomic64_read(const atomic64_t *v)
1133@@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1134 return result;
1135 }
1136
1137+static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1138+{
1139+ u64 result;
1140+
1141+ __asm__ __volatile__("@ atomic64_read_unchecked\n"
1142+" ldrexd %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 u64 tmp;
1153@@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1154 : "cc");
1155 }
1156
1157+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1158+{
1159+ u64 tmp;
1160+
1161+ __asm__ __volatile__("@ atomic64_set_unchecked\n"
1162+"1: ldrexd %0, %H0, [%2]\n"
1163+" strexd %0, %3, %H3, [%2]\n"
1164+" teq %0, #0\n"
1165+" bne 1b"
1166+ : "=&r" (tmp), "=Qo" (v->counter)
1167+ : "r" (&v->counter), "r" (i)
1168+ : "cc");
1169+}
1170+
1171 static inline void atomic64_add(u64 i, atomic64_t *v)
1172 {
1173 u64 result;
1174@@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1175 __asm__ __volatile__("@ atomic64_add\n"
1176 "1: ldrexd %0, %H0, [%3]\n"
1177 " adds %0, %0, %4\n"
1178+" adcs %H0, %H0, %H4\n"
1179+
1180+#ifdef CONFIG_PAX_REFCOUNT
1181+" bvc 3f\n"
1182+"2: bkpt 0xf103\n"
1183+"3:\n"
1184+#endif
1185+
1186+" strexd %1, %0, %H0, [%3]\n"
1187+" teq %1, #0\n"
1188+" bne 1b"
1189+
1190+#ifdef CONFIG_PAX_REFCOUNT
1191+"\n4:\n"
1192+ _ASM_EXTABLE(2b, 4b)
1193+#endif
1194+
1195+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1196+ : "r" (&v->counter), "r" (i)
1197+ : "cc");
1198+}
1199+
1200+static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1201+{
1202+ u64 result;
1203+ unsigned long tmp;
1204+
1205+ __asm__ __volatile__("@ atomic64_add_unchecked\n"
1206+"1: ldrexd %0, %H0, [%3]\n"
1207+" adds %0, %0, %4\n"
1208 " adc %H0, %H0, %H4\n"
1209 " strexd %1, %0, %H0, [%3]\n"
1210 " teq %1, #0\n"
1211@@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1212
1213 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1214 {
1215- u64 result;
1216- unsigned long tmp;
1217+ u64 result, tmp;
1218
1219 smp_mb();
1220
1221 __asm__ __volatile__("@ atomic64_add_return\n"
1222+"1: ldrexd %1, %H1, [%3]\n"
1223+" adds %0, %1, %4\n"
1224+" adcs %H0, %H1, %H4\n"
1225+
1226+#ifdef CONFIG_PAX_REFCOUNT
1227+" bvc 3f\n"
1228+" mov %0, %1\n"
1229+" mov %H0, %H1\n"
1230+"2: bkpt 0xf103\n"
1231+"3:\n"
1232+#endif
1233+
1234+" strexd %1, %0, %H0, [%3]\n"
1235+" teq %1, #0\n"
1236+" bne 1b"
1237+
1238+#ifdef CONFIG_PAX_REFCOUNT
1239+"\n4:\n"
1240+ _ASM_EXTABLE(2b, 4b)
1241+#endif
1242+
1243+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1244+ : "r" (&v->counter), "r" (i)
1245+ : "cc");
1246+
1247+ smp_mb();
1248+
1249+ return result;
1250+}
1251+
1252+static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1253+{
1254+ u64 result;
1255+ unsigned long tmp;
1256+
1257+ smp_mb();
1258+
1259+ __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1260 "1: ldrexd %0, %H0, [%3]\n"
1261 " adds %0, %0, %4\n"
1262 " adc %H0, %H0, %H4\n"
1263@@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1264 __asm__ __volatile__("@ atomic64_sub\n"
1265 "1: ldrexd %0, %H0, [%3]\n"
1266 " subs %0, %0, %4\n"
1267+" sbcs %H0, %H0, %H4\n"
1268+
1269+#ifdef CONFIG_PAX_REFCOUNT
1270+" bvc 3f\n"
1271+"2: bkpt 0xf103\n"
1272+"3:\n"
1273+#endif
1274+
1275+" strexd %1, %0, %H0, [%3]\n"
1276+" teq %1, #0\n"
1277+" bne 1b"
1278+
1279+#ifdef CONFIG_PAX_REFCOUNT
1280+"\n4:\n"
1281+ _ASM_EXTABLE(2b, 4b)
1282+#endif
1283+
1284+ : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1285+ : "r" (&v->counter), "r" (i)
1286+ : "cc");
1287+}
1288+
1289+static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1290+{
1291+ u64 result;
1292+ unsigned long tmp;
1293+
1294+ __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1295+"1: ldrexd %0, %H0, [%3]\n"
1296+" subs %0, %0, %4\n"
1297 " sbc %H0, %H0, %H4\n"
1298 " strexd %1, %0, %H0, [%3]\n"
1299 " teq %1, #0\n"
1300@@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1301
1302 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1303 {
1304- u64 result;
1305- unsigned long tmp;
1306+ u64 result, tmp;
1307
1308 smp_mb();
1309
1310 __asm__ __volatile__("@ atomic64_sub_return\n"
1311-"1: ldrexd %0, %H0, [%3]\n"
1312-" subs %0, %0, %4\n"
1313-" sbc %H0, %H0, %H4\n"
1314+"1: ldrexd %1, %H1, [%3]\n"
1315+" subs %0, %1, %4\n"
1316+" sbcs %H0, %H1, %H4\n"
1317+
1318+#ifdef CONFIG_PAX_REFCOUNT
1319+" bvc 3f\n"
1320+" mov %0, %1\n"
1321+" mov %H0, %H1\n"
1322+"2: bkpt 0xf103\n"
1323+"3:\n"
1324+#endif
1325+
1326 " strexd %1, %0, %H0, [%3]\n"
1327 " teq %1, #0\n"
1328 " bne 1b"
1329+
1330+#ifdef CONFIG_PAX_REFCOUNT
1331+"\n4:\n"
1332+ _ASM_EXTABLE(2b, 4b)
1333+#endif
1334+
1335 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1336 : "r" (&v->counter), "r" (i)
1337 : "cc");
1338@@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1339 return oldval;
1340 }
1341
1342+static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1343+{
1344+ u64 oldval;
1345+ unsigned long res;
1346+
1347+ smp_mb();
1348+
1349+ do {
1350+ __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1351+ "ldrexd %1, %H1, [%3]\n"
1352+ "mov %0, #0\n"
1353+ "teq %1, %4\n"
1354+ "teqeq %H1, %H4\n"
1355+ "strexdeq %0, %5, %H5, [%3]"
1356+ : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1357+ : "r" (&ptr->counter), "r" (old), "r" (new)
1358+ : "cc");
1359+ } while (res);
1360+
1361+ smp_mb();
1362+
1363+ return oldval;
1364+}
1365+
1366 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1367 {
1368 u64 result;
1369@@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1370
1371 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1372 {
1373- u64 result;
1374- unsigned long tmp;
1375+ u64 result, tmp;
1376
1377 smp_mb();
1378
1379 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1380-"1: ldrexd %0, %H0, [%3]\n"
1381-" subs %0, %0, #1\n"
1382-" sbc %H0, %H0, #0\n"
1383+"1: ldrexd %1, %H1, [%3]\n"
1384+" subs %0, %1, #1\n"
1385+" sbcs %H0, %H1, #0\n"
1386+
1387+#ifdef CONFIG_PAX_REFCOUNT
1388+" bvc 3f\n"
1389+" mov %0, %1\n"
1390+" mov %H0, %H1\n"
1391+"2: bkpt 0xf103\n"
1392+"3:\n"
1393+#endif
1394+
1395 " teq %H0, #0\n"
1396-" bmi 2f\n"
1397+" bmi 4f\n"
1398 " strexd %1, %0, %H0, [%3]\n"
1399 " teq %1, #0\n"
1400 " bne 1b\n"
1401-"2:"
1402+"4:\n"
1403+
1404+#ifdef CONFIG_PAX_REFCOUNT
1405+ _ASM_EXTABLE(2b, 4b)
1406+#endif
1407+
1408 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1409 : "r" (&v->counter)
1410 : "cc");
1411@@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1412 " teq %0, %5\n"
1413 " teqeq %H0, %H5\n"
1414 " moveq %1, #0\n"
1415-" beq 2f\n"
1416+" beq 4f\n"
1417 " adds %0, %0, %6\n"
1418-" adc %H0, %H0, %H6\n"
1419+" adcs %H0, %H0, %H6\n"
1420+
1421+#ifdef CONFIG_PAX_REFCOUNT
1422+" bvc 3f\n"
1423+"2: bkpt 0xf103\n"
1424+"3:\n"
1425+#endif
1426+
1427 " strexd %2, %0, %H0, [%4]\n"
1428 " teq %2, #0\n"
1429 " bne 1b\n"
1430-"2:"
1431+"4:\n"
1432+
1433+#ifdef CONFIG_PAX_REFCOUNT
1434+ _ASM_EXTABLE(2b, 4b)
1435+#endif
1436+
1437 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1438 : "r" (&v->counter), "r" (u), "r" (a)
1439 : "cc");
1440@@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1441
1442 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1443 #define atomic64_inc(v) atomic64_add(1LL, (v))
1444+#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1445 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1446+#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1447 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1448 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1449 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1450+#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1451 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1452 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1453 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1454diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1455index 75fe66b..ba3dee4 100644
1456--- a/arch/arm/include/asm/cache.h
1457+++ b/arch/arm/include/asm/cache.h
1458@@ -4,8 +4,10 @@
1459 #ifndef __ASMARM_CACHE_H
1460 #define __ASMARM_CACHE_H
1461
1462+#include <linux/const.h>
1463+
1464 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1465-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1466+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1467
1468 /*
1469 * Memory returned by kmalloc() may be used for DMA, so we must make
1470@@ -24,5 +26,6 @@
1471 #endif
1472
1473 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1474+#define __read_only __attribute__ ((__section__(".data..read_only")))
1475
1476 #endif
1477diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1478index e1489c5..d418304 100644
1479--- a/arch/arm/include/asm/cacheflush.h
1480+++ b/arch/arm/include/asm/cacheflush.h
1481@@ -116,7 +116,7 @@ struct cpu_cache_fns {
1482 void (*dma_unmap_area)(const void *, size_t, int);
1483
1484 void (*dma_flush_range)(const void *, const void *);
1485-};
1486+} __no_const;
1487
1488 /*
1489 * Select the calling method
1490diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1491index 6dcc164..b14d917 100644
1492--- a/arch/arm/include/asm/checksum.h
1493+++ b/arch/arm/include/asm/checksum.h
1494@@ -37,7 +37,19 @@ __wsum
1495 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1496
1497 __wsum
1498-csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1499+__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1500+
1501+static inline __wsum
1502+csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1503+{
1504+ __wsum ret;
1505+ pax_open_userland();
1506+ ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1507+ pax_close_userland();
1508+ return ret;
1509+}
1510+
1511+
1512
1513 /*
1514 * Fold a partial checksum without adding pseudo headers
1515diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1516index 4f009c1..466c59b 100644
1517--- a/arch/arm/include/asm/cmpxchg.h
1518+++ b/arch/arm/include/asm/cmpxchg.h
1519@@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1520
1521 #define xchg(ptr,x) \
1522 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1523+#define xchg_unchecked(ptr,x) \
1524+ ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1525
1526 #include <asm-generic/cmpxchg-local.h>
1527
1528diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1529index 6ddbe44..b5e38b1 100644
1530--- a/arch/arm/include/asm/domain.h
1531+++ b/arch/arm/include/asm/domain.h
1532@@ -48,18 +48,37 @@
1533 * Domain types
1534 */
1535 #define DOMAIN_NOACCESS 0
1536-#define DOMAIN_CLIENT 1
1537 #ifdef CONFIG_CPU_USE_DOMAINS
1538+#define DOMAIN_USERCLIENT 1
1539+#define DOMAIN_KERNELCLIENT 1
1540 #define DOMAIN_MANAGER 3
1541+#define DOMAIN_VECTORS DOMAIN_USER
1542 #else
1543+
1544+#ifdef CONFIG_PAX_KERNEXEC
1545 #define DOMAIN_MANAGER 1
1546+#define DOMAIN_KERNEXEC 3
1547+#else
1548+#define DOMAIN_MANAGER 1
1549+#endif
1550+
1551+#ifdef CONFIG_PAX_MEMORY_UDEREF
1552+#define DOMAIN_USERCLIENT 0
1553+#define DOMAIN_UDEREF 1
1554+#define DOMAIN_VECTORS DOMAIN_KERNEL
1555+#else
1556+#define DOMAIN_USERCLIENT 1
1557+#define DOMAIN_VECTORS DOMAIN_USER
1558+#endif
1559+#define DOMAIN_KERNELCLIENT 1
1560+
1561 #endif
1562
1563 #define domain_val(dom,type) ((type) << (2*(dom)))
1564
1565 #ifndef __ASSEMBLY__
1566
1567-#ifdef CONFIG_CPU_USE_DOMAINS
1568+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1569 static inline void set_domain(unsigned val)
1570 {
1571 asm volatile(
1572@@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1573 isb();
1574 }
1575
1576-#define modify_domain(dom,type) \
1577- do { \
1578- struct thread_info *thread = current_thread_info(); \
1579- unsigned int domain = thread->cpu_domain; \
1580- domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1581- thread->cpu_domain = domain | domain_val(dom, type); \
1582- set_domain(thread->cpu_domain); \
1583- } while (0)
1584-
1585+extern void modify_domain(unsigned int dom, unsigned int type);
1586 #else
1587 static inline void set_domain(unsigned val) { }
1588 static inline void modify_domain(unsigned dom, unsigned type) { }
1589diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1590index 38050b1..9d90e8b 100644
1591--- a/arch/arm/include/asm/elf.h
1592+++ b/arch/arm/include/asm/elf.h
1593@@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1594 the loader. We need to make sure that it is out of the way of the program
1595 that it will "exec", and that there is sufficient room for the brk. */
1596
1597-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1598+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1599+
1600+#ifdef CONFIG_PAX_ASLR
1601+#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1602+
1603+#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1604+#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1605+#endif
1606
1607 /* When the program starts, a1 contains a pointer to a function to be
1608 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1609@@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1610 extern void elf_set_personality(const struct elf32_hdr *);
1611 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1612
1613-struct mm_struct;
1614-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1615-#define arch_randomize_brk arch_randomize_brk
1616-
1617 #endif
1618diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1619index de53547..52b9a28 100644
1620--- a/arch/arm/include/asm/fncpy.h
1621+++ b/arch/arm/include/asm/fncpy.h
1622@@ -81,7 +81,9 @@
1623 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1624 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1625 \
1626+ pax_open_kernel(); \
1627 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1628+ pax_close_kernel(); \
1629 flush_icache_range((unsigned long)(dest_buf), \
1630 (unsigned long)(dest_buf) + (size)); \
1631 \
1632diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1633index e42cf59..7b94b8f 100644
1634--- a/arch/arm/include/asm/futex.h
1635+++ b/arch/arm/include/asm/futex.h
1636@@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1637 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1638 return -EFAULT;
1639
1640+ pax_open_userland();
1641+
1642 smp_mb();
1643 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1644 "1: ldrex %1, [%4]\n"
1645@@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1646 : "cc", "memory");
1647 smp_mb();
1648
1649+ pax_close_userland();
1650+
1651 *uval = val;
1652 return ret;
1653 }
1654@@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1655 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1656 return -EFAULT;
1657
1658+ pax_open_userland();
1659+
1660 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1661 "1: " TUSER(ldr) " %1, [%4]\n"
1662 " teq %1, %2\n"
1663@@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1664 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1665 : "cc", "memory");
1666
1667+ pax_close_userland();
1668+
1669 *uval = val;
1670 return ret;
1671 }
1672@@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1673 return -EFAULT;
1674
1675 pagefault_disable(); /* implies preempt_disable() */
1676+ pax_open_userland();
1677
1678 switch (op) {
1679 case FUTEX_OP_SET:
1680@@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1681 ret = -ENOSYS;
1682 }
1683
1684+ pax_close_userland();
1685 pagefault_enable(); /* subsumes preempt_enable() */
1686
1687 if (!ret) {
1688diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1689index 83eb2f7..ed77159 100644
1690--- a/arch/arm/include/asm/kmap_types.h
1691+++ b/arch/arm/include/asm/kmap_types.h
1692@@ -4,6 +4,6 @@
1693 /*
1694 * This is the "bare minimum". AIO seems to require this.
1695 */
1696-#define KM_TYPE_NR 16
1697+#define KM_TYPE_NR 17
1698
1699 #endif
1700diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1701index 9e614a1..3302cca 100644
1702--- a/arch/arm/include/asm/mach/dma.h
1703+++ b/arch/arm/include/asm/mach/dma.h
1704@@ -22,7 +22,7 @@ struct dma_ops {
1705 int (*residue)(unsigned int, dma_t *); /* optional */
1706 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1707 const char *type;
1708-};
1709+} __do_const;
1710
1711 struct dma_struct {
1712 void *addr; /* single DMA address */
1713diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1714index 2fe141f..192dc01 100644
1715--- a/arch/arm/include/asm/mach/map.h
1716+++ b/arch/arm/include/asm/mach/map.h
1717@@ -27,13 +27,16 @@ struct map_desc {
1718 #define MT_MINICLEAN 6
1719 #define MT_LOW_VECTORS 7
1720 #define MT_HIGH_VECTORS 8
1721-#define MT_MEMORY 9
1722+#define MT_MEMORY_RWX 9
1723 #define MT_ROM 10
1724-#define MT_MEMORY_NONCACHED 11
1725+#define MT_MEMORY_NONCACHED_RX 11
1726 #define MT_MEMORY_DTCM 12
1727 #define MT_MEMORY_ITCM 13
1728 #define MT_MEMORY_SO 14
1729 #define MT_MEMORY_DMA_READY 15
1730+#define MT_MEMORY_RW 16
1731+#define MT_MEMORY_RX 17
1732+#define MT_MEMORY_NONCACHED_RW 18
1733
1734 #ifdef CONFIG_MMU
1735 extern void iotable_init(struct map_desc *, int);
1736diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1737index 12f71a1..04e063c 100644
1738--- a/arch/arm/include/asm/outercache.h
1739+++ b/arch/arm/include/asm/outercache.h
1740@@ -35,7 +35,7 @@ struct outer_cache_fns {
1741 #endif
1742 void (*set_debug)(unsigned long);
1743 void (*resume)(void);
1744-};
1745+} __no_const;
1746
1747 #ifdef CONFIG_OUTER_CACHE
1748
1749diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1750index 812a494..71fc0b6 100644
1751--- a/arch/arm/include/asm/page.h
1752+++ b/arch/arm/include/asm/page.h
1753@@ -114,7 +114,7 @@ struct cpu_user_fns {
1754 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1755 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1756 unsigned long vaddr, struct vm_area_struct *vma);
1757-};
1758+} __no_const;
1759
1760 #ifdef MULTI_USER
1761 extern struct cpu_user_fns cpu_user;
1762diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1763index 943504f..c37a730 100644
1764--- a/arch/arm/include/asm/pgalloc.h
1765+++ b/arch/arm/include/asm/pgalloc.h
1766@@ -17,6 +17,7 @@
1767 #include <asm/processor.h>
1768 #include <asm/cacheflush.h>
1769 #include <asm/tlbflush.h>
1770+#include <asm/system_info.h>
1771
1772 #define check_pgt_cache() do { } while (0)
1773
1774@@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1775 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1776 }
1777
1778+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1779+{
1780+ pud_populate(mm, pud, pmd);
1781+}
1782+
1783 #else /* !CONFIG_ARM_LPAE */
1784
1785 /*
1786@@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1787 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1788 #define pmd_free(mm, pmd) do { } while (0)
1789 #define pud_populate(mm,pmd,pte) BUG()
1790+#define pud_populate_kernel(mm,pmd,pte) BUG()
1791
1792 #endif /* CONFIG_ARM_LPAE */
1793
1794@@ -126,6 +133,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1795 __free_page(pte);
1796 }
1797
1798+static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1799+{
1800+#ifdef CONFIG_ARM_LPAE
1801+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1802+#else
1803+ if (addr & SECTION_SIZE)
1804+ pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1805+ else
1806+ pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1807+#endif
1808+ flush_pmd_entry(pmdp);
1809+}
1810+
1811 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1812 pmdval_t prot)
1813 {
1814@@ -155,7 +175,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1815 static inline void
1816 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1817 {
1818- __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1819+ __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1820 }
1821 #define pmd_pgtable(pmd) pmd_page(pmd)
1822
1823diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1824index 5cfba15..f415e1a 100644
1825--- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1826+++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1827@@ -20,12 +20,15 @@
1828 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1829 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1830 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1831+#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1832 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1833 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1834 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1835+
1836 /*
1837 * - section
1838 */
1839+#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1840 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1841 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1842 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1843@@ -37,6 +40,7 @@
1844 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1845 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1846 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1847+#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1848
1849 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1850 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1851@@ -66,6 +70,7 @@
1852 * - extended small page/tiny page
1853 */
1854 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1855+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1856 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1857 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1858 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1859diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1860index f97ee02..07f1be5 100644
1861--- a/arch/arm/include/asm/pgtable-2level.h
1862+++ b/arch/arm/include/asm/pgtable-2level.h
1863@@ -125,6 +125,7 @@
1864 #define L_PTE_XN (_AT(pteval_t, 1) << 9)
1865 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1866 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1867+#define L_PTE_PXN (_AT(pteval_t, 1) << 12) /* v7*/
1868
1869 /*
1870 * These are the memory types, defined to be compatible with
1871diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1872index 18f5cef..25b8f43 100644
1873--- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1874+++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1875@@ -41,6 +41,7 @@
1876 */
1877 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1878 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1879+#define PMD_SECT_RDONLY (_AT(pmdval_t, 1) << 7)
1880 #define PMD_SECT_S (_AT(pmdval_t, 3) << 8)
1881 #define PMD_SECT_AF (_AT(pmdval_t, 1) << 10)
1882 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 11)
1883@@ -71,6 +72,7 @@
1884 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1885 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1886 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1887+#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1888 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1889
1890 /*
1891diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1892index 86b8fe3..e25f975 100644
1893--- a/arch/arm/include/asm/pgtable-3level.h
1894+++ b/arch/arm/include/asm/pgtable-3level.h
1895@@ -74,6 +74,7 @@
1896 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1897 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1898 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1899+#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1900 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1901 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1902 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1903@@ -82,6 +83,7 @@
1904 /*
1905 * To be used in assembly code with the upper page attributes.
1906 */
1907+#define L_PTE_PXN_HIGH (1 << (53 - 32))
1908 #define L_PTE_XN_HIGH (1 << (54 - 32))
1909 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
1910
1911diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
1912index 9bcd262..fba731c 100644
1913--- a/arch/arm/include/asm/pgtable.h
1914+++ b/arch/arm/include/asm/pgtable.h
1915@@ -30,6 +30,9 @@
1916 #include <asm/pgtable-2level.h>
1917 #endif
1918
1919+#define ktla_ktva(addr) (addr)
1920+#define ktva_ktla(addr) (addr)
1921+
1922 /*
1923 * Just any arbitrary offset to the start of the vmalloc VM area: the
1924 * current 8MB value just means that there will be a 8MB "hole" after the
1925@@ -45,6 +48,9 @@
1926 #define LIBRARY_TEXT_START 0x0c000000
1927
1928 #ifndef __ASSEMBLY__
1929+extern pteval_t __supported_pte_mask;
1930+extern pmdval_t __supported_pmd_mask;
1931+
1932 extern void __pte_error(const char *file, int line, pte_t);
1933 extern void __pmd_error(const char *file, int line, pmd_t);
1934 extern void __pgd_error(const char *file, int line, pgd_t);
1935@@ -53,6 +59,50 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1936 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
1937 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
1938
1939+#define __HAVE_ARCH_PAX_OPEN_KERNEL
1940+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
1941+
1942+#ifdef CONFIG_PAX_KERNEXEC
1943+#include <asm/domain.h>
1944+#include <linux/thread_info.h>
1945+#include <linux/preempt.h>
1946+#endif
1947+
1948+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1949+static inline int test_domain(int domain, int domaintype)
1950+{
1951+ return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
1952+}
1953+#endif
1954+
1955+#ifdef CONFIG_PAX_KERNEXEC
1956+static inline unsigned long pax_open_kernel(void) {
1957+#ifdef CONFIG_ARM_LPAE
1958+ /* TODO */
1959+#else
1960+ preempt_disable();
1961+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
1962+ modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
1963+#endif
1964+ return 0;
1965+}
1966+
1967+static inline unsigned long pax_close_kernel(void) {
1968+#ifdef CONFIG_ARM_LPAE
1969+ /* TODO */
1970+#else
1971+ BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
1972+ /* DOMAIN_MANAGER = "client" under KERNEXEC */
1973+ modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
1974+ preempt_enable_no_resched();
1975+#endif
1976+ return 0;
1977+}
1978+#else
1979+static inline unsigned long pax_open_kernel(void) { return 0; }
1980+static inline unsigned long pax_close_kernel(void) { return 0; }
1981+#endif
1982+
1983 /*
1984 * This is the lowest virtual address we can permit any user space
1985 * mapping to be mapped at. This is particularly important for
1986@@ -72,8 +122,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
1987 /*
1988 * The pgprot_* and protection_map entries will be fixed up in runtime
1989 * to include the cachable and bufferable bits based on memory policy,
1990- * as well as any architecture dependent bits like global/ASID and SMP
1991- * shared mapping bits.
1992+ * as well as any architecture dependent bits like global/ASID, PXN,
1993+ * and SMP shared mapping bits.
1994 */
1995 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
1996
1997@@ -257,7 +307,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
1998 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
1999 {
2000 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2001- L_PTE_NONE | L_PTE_VALID;
2002+ L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2003 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2004 return pte;
2005 }
2006diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2007index f3628fb..a0672dd 100644
2008--- a/arch/arm/include/asm/proc-fns.h
2009+++ b/arch/arm/include/asm/proc-fns.h
2010@@ -75,7 +75,7 @@ extern struct processor {
2011 unsigned int suspend_size;
2012 void (*do_suspend)(void *);
2013 void (*do_resume)(void *);
2014-} processor;
2015+} __do_const processor;
2016
2017 #ifndef MULTI_CPU
2018 extern void cpu_proc_init(void);
2019diff --git a/arch/arm/include/asm/processor.h b/arch/arm/include/asm/processor.h
2020index 06e7d50..8a8e251 100644
2021--- a/arch/arm/include/asm/processor.h
2022+++ b/arch/arm/include/asm/processor.h
2023@@ -65,9 +65,8 @@ struct thread_struct {
2024 regs->ARM_cpsr |= PSR_ENDSTATE; \
2025 regs->ARM_pc = pc & ~1; /* pc */ \
2026 regs->ARM_sp = sp; /* sp */ \
2027- regs->ARM_r2 = stack[2]; /* r2 (envp) */ \
2028- regs->ARM_r1 = stack[1]; /* r1 (argv) */ \
2029- regs->ARM_r0 = stack[0]; /* r0 (argc) */ \
2030+ /* r2 (envp), r1 (argv), r0 (argc) */ \
2031+ (void)copy_from_user(&regs->ARM_r0, (const char __user *)stack, 3 * sizeof(unsigned long)); \
2032 nommu_start_thread(regs); \
2033 })
2034
2035diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2036index ce0dbe7..c085b6f 100644
2037--- a/arch/arm/include/asm/psci.h
2038+++ b/arch/arm/include/asm/psci.h
2039@@ -29,7 +29,7 @@ struct psci_operations {
2040 int (*cpu_off)(struct psci_power_state state);
2041 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2042 int (*migrate)(unsigned long cpuid);
2043-};
2044+} __no_const;
2045
2046 extern struct psci_operations psci_ops;
2047
2048diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2049index d3a22be..3a69ad5 100644
2050--- a/arch/arm/include/asm/smp.h
2051+++ b/arch/arm/include/asm/smp.h
2052@@ -107,7 +107,7 @@ struct smp_operations {
2053 int (*cpu_disable)(unsigned int cpu);
2054 #endif
2055 #endif
2056-};
2057+} __no_const;
2058
2059 /*
2060 * set platform specific SMP operations
2061diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2062index cddda1f..ff357f7 100644
2063--- a/arch/arm/include/asm/thread_info.h
2064+++ b/arch/arm/include/asm/thread_info.h
2065@@ -77,9 +77,9 @@ struct thread_info {
2066 .flags = 0, \
2067 .preempt_count = INIT_PREEMPT_COUNT, \
2068 .addr_limit = KERNEL_DS, \
2069- .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2070- domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2071- domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2072+ .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2073+ domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2074+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2075 .restart_block = { \
2076 .fn = do_no_restart_syscall, \
2077 }, \
2078@@ -152,6 +152,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2079 #define TIF_SYSCALL_AUDIT 9
2080 #define TIF_SYSCALL_TRACEPOINT 10
2081 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2082+
2083+/* within 8 bits of TIF_SYSCALL_TRACE
2084+ * to meet flexible second operand requirements
2085+ */
2086+#define TIF_GRSEC_SETXID 12
2087+
2088 #define TIF_USING_IWMMXT 17
2089 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2090 #define TIF_RESTORE_SIGMASK 20
2091@@ -165,10 +171,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2092 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2093 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2094 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2095+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2096
2097 /* Checks for any syscall work in entry-common.S */
2098 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2099- _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2100+ _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2101
2102 /*
2103 * Change these and you break ASM code in entry-common.S
2104diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2105index 7e1f760..752fcb7 100644
2106--- a/arch/arm/include/asm/uaccess.h
2107+++ b/arch/arm/include/asm/uaccess.h
2108@@ -18,6 +18,7 @@
2109 #include <asm/domain.h>
2110 #include <asm/unified.h>
2111 #include <asm/compiler.h>
2112+#include <asm/pgtable.h>
2113
2114 #define VERIFY_READ 0
2115 #define VERIFY_WRITE 1
2116@@ -60,10 +61,34 @@ extern int __put_user_bad(void);
2117 #define USER_DS TASK_SIZE
2118 #define get_fs() (current_thread_info()->addr_limit)
2119
2120+static inline void pax_open_userland(void)
2121+{
2122+
2123+#ifdef CONFIG_PAX_MEMORY_UDEREF
2124+ if (get_fs() == USER_DS) {
2125+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2126+ modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2127+ }
2128+#endif
2129+
2130+}
2131+
2132+static inline void pax_close_userland(void)
2133+{
2134+
2135+#ifdef CONFIG_PAX_MEMORY_UDEREF
2136+ if (get_fs() == USER_DS) {
2137+ BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2138+ modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2139+ }
2140+#endif
2141+
2142+}
2143+
2144 static inline void set_fs(mm_segment_t fs)
2145 {
2146 current_thread_info()->addr_limit = fs;
2147- modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2148+ modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2149 }
2150
2151 #define segment_eq(a,b) ((a) == (b))
2152@@ -143,8 +168,12 @@ extern int __get_user_4(void *);
2153
2154 #define get_user(x,p) \
2155 ({ \
2156+ int __e; \
2157 might_fault(); \
2158- __get_user_check(x,p); \
2159+ pax_open_userland(); \
2160+ __e = __get_user_check(x,p); \
2161+ pax_close_userland(); \
2162+ __e; \
2163 })
2164
2165 extern int __put_user_1(void *, unsigned int);
2166@@ -188,8 +217,12 @@ extern int __put_user_8(void *, unsigned long long);
2167
2168 #define put_user(x,p) \
2169 ({ \
2170+ int __e; \
2171 might_fault(); \
2172- __put_user_check(x,p); \
2173+ pax_open_userland(); \
2174+ __e = __put_user_check(x,p); \
2175+ pax_close_userland(); \
2176+ __e; \
2177 })
2178
2179 #else /* CONFIG_MMU */
2180@@ -230,13 +263,17 @@ static inline void set_fs(mm_segment_t fs)
2181 #define __get_user(x,ptr) \
2182 ({ \
2183 long __gu_err = 0; \
2184+ pax_open_userland(); \
2185 __get_user_err((x),(ptr),__gu_err); \
2186+ pax_close_userland(); \
2187 __gu_err; \
2188 })
2189
2190 #define __get_user_error(x,ptr,err) \
2191 ({ \
2192+ pax_open_userland(); \
2193 __get_user_err((x),(ptr),err); \
2194+ pax_close_userland(); \
2195 (void) 0; \
2196 })
2197
2198@@ -312,13 +349,17 @@ do { \
2199 #define __put_user(x,ptr) \
2200 ({ \
2201 long __pu_err = 0; \
2202+ pax_open_userland(); \
2203 __put_user_err((x),(ptr),__pu_err); \
2204+ pax_close_userland(); \
2205 __pu_err; \
2206 })
2207
2208 #define __put_user_error(x,ptr,err) \
2209 ({ \
2210+ pax_open_userland(); \
2211 __put_user_err((x),(ptr),err); \
2212+ pax_close_userland(); \
2213 (void) 0; \
2214 })
2215
2216@@ -418,11 +459,44 @@ do { \
2217
2218
2219 #ifdef CONFIG_MMU
2220-extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2221-extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2222+extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2223+extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2224+
2225+static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2226+{
2227+ unsigned long ret;
2228+
2229+ check_object_size(to, n, false);
2230+ pax_open_userland();
2231+ ret = ___copy_from_user(to, from, n);
2232+ pax_close_userland();
2233+ return ret;
2234+}
2235+
2236+static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2237+{
2238+ unsigned long ret;
2239+
2240+ check_object_size(from, n, true);
2241+ pax_open_userland();
2242+ ret = ___copy_to_user(to, from, n);
2243+ pax_close_userland();
2244+ return ret;
2245+}
2246+
2247 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2248-extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2249+extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2250 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2251+
2252+static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2253+{
2254+ unsigned long ret;
2255+ pax_open_userland();
2256+ ret = ___clear_user(addr, n);
2257+ pax_close_userland();
2258+ return ret;
2259+}
2260+
2261 #else
2262 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2263 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2264@@ -431,6 +505,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2265
2266 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2267 {
2268+ if ((long)n < 0)
2269+ return n;
2270+
2271 if (access_ok(VERIFY_READ, from, n))
2272 n = __copy_from_user(to, from, n);
2273 else /* security hole - plug it */
2274@@ -440,6 +517,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2275
2276 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2277 {
2278+ if ((long)n < 0)
2279+ return n;
2280+
2281 if (access_ok(VERIFY_WRITE, to, n))
2282 n = __copy_to_user(to, from, n);
2283 return n;
2284diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2285index 96ee092..37f1844 100644
2286--- a/arch/arm/include/uapi/asm/ptrace.h
2287+++ b/arch/arm/include/uapi/asm/ptrace.h
2288@@ -73,7 +73,7 @@
2289 * ARMv7 groups of PSR bits
2290 */
2291 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2292-#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2293+#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2294 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2295 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2296
2297diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2298index 60d3b73..d27ee09 100644
2299--- a/arch/arm/kernel/armksyms.c
2300+++ b/arch/arm/kernel/armksyms.c
2301@@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2302 #ifdef CONFIG_MMU
2303 EXPORT_SYMBOL(copy_page);
2304
2305-EXPORT_SYMBOL(__copy_from_user);
2306-EXPORT_SYMBOL(__copy_to_user);
2307-EXPORT_SYMBOL(__clear_user);
2308+EXPORT_SYMBOL(___copy_from_user);
2309+EXPORT_SYMBOL(___copy_to_user);
2310+EXPORT_SYMBOL(___clear_user);
2311
2312 EXPORT_SYMBOL(__get_user_1);
2313 EXPORT_SYMBOL(__get_user_2);
2314diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2315index 0f82098..fb3d3d5 100644
2316--- a/arch/arm/kernel/entry-armv.S
2317+++ b/arch/arm/kernel/entry-armv.S
2318@@ -47,6 +47,87 @@
2319 9997:
2320 .endm
2321
2322+ .macro pax_enter_kernel
2323+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2324+ @ make aligned space for saved DACR
2325+ sub sp, sp, #8
2326+ @ save regs
2327+ stmdb sp!, {r1, r2}
2328+ @ read DACR from cpu_domain into r1
2329+ mov r2, sp
2330+ @ assume 8K pages, since we have to split the immediate in two
2331+ bic r2, r2, #(0x1fc0)
2332+ bic r2, r2, #(0x3f)
2333+ ldr r1, [r2, #TI_CPU_DOMAIN]
2334+ @ store old DACR on stack
2335+ str r1, [sp, #8]
2336+#ifdef CONFIG_PAX_KERNEXEC
2337+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2338+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2339+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2340+#endif
2341+#ifdef CONFIG_PAX_MEMORY_UDEREF
2342+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2343+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2344+#endif
2345+ @ write r1 to current_thread_info()->cpu_domain
2346+ str r1, [r2, #TI_CPU_DOMAIN]
2347+ @ write r1 to DACR
2348+ mcr p15, 0, r1, c3, c0, 0
2349+ @ instruction sync
2350+ instr_sync
2351+ @ restore regs
2352+ ldmia sp!, {r1, r2}
2353+#endif
2354+ .endm
2355+
2356+ .macro pax_open_userland
2357+#ifdef CONFIG_PAX_MEMORY_UDEREF
2358+ @ save regs
2359+ stmdb sp!, {r0, r1}
2360+ @ read DACR from cpu_domain into r1
2361+ mov r0, sp
2362+ @ assume 8K pages, since we have to split the immediate in two
2363+ bic r0, r0, #(0x1fc0)
2364+ bic r0, r0, #(0x3f)
2365+ ldr r1, [r0, #TI_CPU_DOMAIN]
2366+ @ set current DOMAIN_USER to DOMAIN_CLIENT
2367+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2368+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2369+ @ write r1 to current_thread_info()->cpu_domain
2370+ str r1, [r0, #TI_CPU_DOMAIN]
2371+ @ write r1 to DACR
2372+ mcr p15, 0, r1, c3, c0, 0
2373+ @ instruction sync
2374+ instr_sync
2375+ @ restore regs
2376+ ldmia sp!, {r0, r1}
2377+#endif
2378+ .endm
2379+
2380+ .macro pax_close_userland
2381+#ifdef CONFIG_PAX_MEMORY_UDEREF
2382+ @ save regs
2383+ stmdb sp!, {r0, r1}
2384+ @ read DACR from cpu_domain into r1
2385+ mov r0, sp
2386+ @ assume 8K pages, since we have to split the immediate in two
2387+ bic r0, r0, #(0x1fc0)
2388+ bic r0, r0, #(0x3f)
2389+ ldr r1, [r0, #TI_CPU_DOMAIN]
2390+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2391+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2392+ @ write r1 to current_thread_info()->cpu_domain
2393+ str r1, [r0, #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!, {r0, r1}
2400+#endif
2401+ .endm
2402+
2403 .macro pabt_helper
2404 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2405 #ifdef MULTI_PABORT
2406@@ -89,11 +170,15 @@
2407 * Invalid mode handlers
2408 */
2409 .macro inv_entry, reason
2410+
2411+ pax_enter_kernel
2412+
2413 sub sp, sp, #S_FRAME_SIZE
2414 ARM( stmib sp, {r1 - lr} )
2415 THUMB( stmia sp, {r0 - r12} )
2416 THUMB( str sp, [sp, #S_SP] )
2417 THUMB( str lr, [sp, #S_LR] )
2418+
2419 mov r1, #\reason
2420 .endm
2421
2422@@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2423 .macro svc_entry, stack_hole=0
2424 UNWIND(.fnstart )
2425 UNWIND(.save {r0 - pc} )
2426+
2427+ pax_enter_kernel
2428+
2429 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2430+
2431 #ifdef CONFIG_THUMB2_KERNEL
2432 SPFIX( str r0, [sp] ) @ temporarily saved
2433 SPFIX( mov r0, sp )
2434@@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2435 ldmia r0, {r3 - r5}
2436 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2437 mov r6, #-1 @ "" "" "" ""
2438+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2439+ @ offset sp by 8 as done in pax_enter_kernel
2440+ add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2441+#else
2442 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2443+#endif
2444 SPFIX( addeq r2, r2, #4 )
2445 str r3, [sp, #-4]! @ save the "real" r0 copied
2446 @ from the exception stack
2447@@ -359,6 +453,9 @@ ENDPROC(__pabt_svc)
2448 .macro usr_entry
2449 UNWIND(.fnstart )
2450 UNWIND(.cantunwind ) @ don't unwind the user space
2451+
2452+ pax_enter_kernel_user
2453+
2454 sub sp, sp, #S_FRAME_SIZE
2455 ARM( stmib sp, {r1 - r12} )
2456 THUMB( stmia sp, {r0 - r12} )
2457@@ -456,7 +553,9 @@ __und_usr:
2458 tst r3, #PSR_T_BIT @ Thumb mode?
2459 bne __und_usr_thumb
2460 sub r4, r2, #4 @ ARM instr at LR - 4
2461+ pax_open_userland
2462 1: ldrt r0, [r4]
2463+ pax_close_userland
2464 #ifdef CONFIG_CPU_ENDIAN_BE8
2465 rev r0, r0 @ little endian instruction
2466 #endif
2467@@ -491,10 +590,14 @@ __und_usr_thumb:
2468 */
2469 .arch armv6t2
2470 #endif
2471+ pax_open_userland
2472 2: ldrht r5, [r4]
2473+ pax_close_userland
2474 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2475 blo __und_usr_fault_16 @ 16bit undefined instruction
2476+ pax_open_userland
2477 3: ldrht r0, [r2]
2478+ pax_close_userland
2479 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2480 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2481 orr r0, r0, r5, lsl #16
2482@@ -733,7 +836,7 @@ ENTRY(__switch_to)
2483 THUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stack
2484 THUMB( str sp, [ip], #4 )
2485 THUMB( str lr, [ip], #4 )
2486-#ifdef CONFIG_CPU_USE_DOMAINS
2487+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2488 ldr r6, [r2, #TI_CPU_DOMAIN]
2489 #endif
2490 set_tls r3, r4, r5
2491@@ -742,7 +845,7 @@ ENTRY(__switch_to)
2492 ldr r8, =__stack_chk_guard
2493 ldr r7, [r7, #TSK_STACK_CANARY]
2494 #endif
2495-#ifdef CONFIG_CPU_USE_DOMAINS
2496+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2497 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2498 #endif
2499 mov r5, r0
2500diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2501index fefd7f9..e6f250e 100644
2502--- a/arch/arm/kernel/entry-common.S
2503+++ b/arch/arm/kernel/entry-common.S
2504@@ -10,18 +10,46 @@
2505
2506 #include <asm/unistd.h>
2507 #include <asm/ftrace.h>
2508+#include <asm/domain.h>
2509 #include <asm/unwind.h>
2510
2511+#include "entry-header.S"
2512+
2513 #ifdef CONFIG_NEED_RET_TO_USER
2514 #include <mach/entry-macro.S>
2515 #else
2516 .macro arch_ret_to_user, tmp1, tmp2
2517+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2518+ @ save regs
2519+ stmdb sp!, {r1, r2}
2520+ @ read DACR from cpu_domain into r1
2521+ mov r2, sp
2522+ @ assume 8K pages, since we have to split the immediate in two
2523+ bic r2, r2, #(0x1fc0)
2524+ bic r2, r2, #(0x3f)
2525+ ldr r1, [r2, #TI_CPU_DOMAIN]
2526+#ifdef CONFIG_PAX_KERNEXEC
2527+ @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2528+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2529+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2530+#endif
2531+#ifdef CONFIG_PAX_MEMORY_UDEREF
2532+ @ set current DOMAIN_USER to DOMAIN_UDEREF
2533+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2534+ orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2535+#endif
2536+ @ write r1 to current_thread_info()->cpu_domain
2537+ str r1, [r2, #TI_CPU_DOMAIN]
2538+ @ write r1 to DACR
2539+ mcr p15, 0, r1, c3, c0, 0
2540+ @ instruction sync
2541+ instr_sync
2542+ @ restore regs
2543+ ldmia sp!, {r1, r2}
2544+#endif
2545 .endm
2546 #endif
2547
2548-#include "entry-header.S"
2549-
2550-
2551 .align 5
2552 /*
2553 * This is the fast syscall return path. We do as little as
2554@@ -351,6 +379,7 @@ ENDPROC(ftrace_stub)
2555
2556 .align 5
2557 ENTRY(vector_swi)
2558+
2559 sub sp, sp, #S_FRAME_SIZE
2560 stmia sp, {r0 - r12} @ Calling r0 - r12
2561 ARM( add r8, sp, #S_PC )
2562@@ -400,6 +429,12 @@ ENTRY(vector_swi)
2563 ldr scno, [lr, #-4] @ get SWI instruction
2564 #endif
2565
2566+ /*
2567+ * do this here to avoid a performance hit of wrapping the code above
2568+ * that directly dereferences userland to parse the SWI instruction
2569+ */
2570+ pax_enter_kernel_user
2571+
2572 #ifdef CONFIG_ALIGNMENT_TRAP
2573 ldr ip, __cr_alignment
2574 ldr ip, [ip]
2575diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2576index 9a8531e..812e287 100644
2577--- a/arch/arm/kernel/entry-header.S
2578+++ b/arch/arm/kernel/entry-header.S
2579@@ -73,9 +73,66 @@
2580 msr cpsr_c, \rtemp @ switch back to the SVC mode
2581 .endm
2582
2583+ .macro pax_enter_kernel_user
2584+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2585+ @ save regs
2586+ stmdb sp!, {r0, r1}
2587+ @ read DACR from cpu_domain into r1
2588+ mov r0, sp
2589+ @ assume 8K pages, since we have to split the immediate in two
2590+ bic r0, r0, #(0x1fc0)
2591+ bic r0, r0, #(0x3f)
2592+ ldr r1, [r0, #TI_CPU_DOMAIN]
2593+#ifdef CONFIG_PAX_MEMORY_UDEREF
2594+ @ set current DOMAIN_USER to DOMAIN_NOACCESS
2595+ bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2596+#endif
2597+#ifdef CONFIG_PAX_KERNEXEC
2598+ @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2599+ bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2600+ orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2601+#endif
2602+ @ write r1 to current_thread_info()->cpu_domain
2603+ str r1, [r0, #TI_CPU_DOMAIN]
2604+ @ write r1 to DACR
2605+ mcr p15, 0, r1, c3, c0, 0
2606+ @ instruction sync
2607+ instr_sync
2608+ @ restore regs
2609+ ldmia sp!, {r0, r1}
2610+#endif
2611+ .endm
2612+
2613+ .macro pax_exit_kernel
2614+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2615+ @ save regs
2616+ stmdb sp!, {r0, r1}
2617+ @ read old DACR from stack into r1
2618+ ldr r1, [sp, #(8 + S_SP)]
2619+ sub r1, r1, #8
2620+ ldr r1, [r1]
2621+
2622+ @ write r1 to current_thread_info()->cpu_domain
2623+ mov r0, sp
2624+ @ assume 8K pages, since we have to split the immediate in two
2625+ bic r0, r0, #(0x1fc0)
2626+ bic r0, r0, #(0x3f)
2627+ str r1, [r0, #TI_CPU_DOMAIN]
2628+ @ write r1 to DACR
2629+ mcr p15, 0, r1, c3, c0, 0
2630+ @ instruction sync
2631+ instr_sync
2632+ @ restore regs
2633+ ldmia sp!, {r0, r1}
2634+#endif
2635+ .endm
2636+
2637 #ifndef CONFIG_THUMB2_KERNEL
2638 .macro svc_exit, rpsr
2639 msr spsr_cxsf, \rpsr
2640+
2641+ pax_exit_kernel
2642+
2643 #if defined(CONFIG_CPU_V6)
2644 ldr r0, [sp]
2645 strex r1, r2, [sp] @ clear the exclusive monitor
2646@@ -121,6 +178,9 @@
2647 .endm
2648 #else /* CONFIG_THUMB2_KERNEL */
2649 .macro svc_exit, rpsr
2650+
2651+ pax_exit_kernel
2652+
2653 ldr lr, [sp, #S_SP] @ top of the stack
2654 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2655 clrex @ clear the exclusive monitor
2656diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2657index 2adda11..7fbe958 100644
2658--- a/arch/arm/kernel/fiq.c
2659+++ b/arch/arm/kernel/fiq.c
2660@@ -82,7 +82,9 @@ void set_fiq_handler(void *start, unsigned int length)
2661 #if defined(CONFIG_CPU_USE_DOMAINS)
2662 memcpy((void *)0xffff001c, start, length);
2663 #else
2664+ pax_open_kernel();
2665 memcpy(vectors_page + 0x1c, start, length);
2666+ pax_close_kernel();
2667 #endif
2668 flush_icache_range(0xffff001c, 0xffff001c + length);
2669 if (!vectors_high())
2670diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2671index 8bac553..caee108 100644
2672--- a/arch/arm/kernel/head.S
2673+++ b/arch/arm/kernel/head.S
2674@@ -52,7 +52,9 @@
2675 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2676
2677 .macro pgtbl, rd, phys
2678- add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2679+ mov \rd, #TEXT_OFFSET
2680+ sub \rd, #PG_DIR_SIZE
2681+ add \rd, \rd, \phys
2682 .endm
2683
2684 /*
2685@@ -434,7 +436,7 @@ __enable_mmu:
2686 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2687 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2688 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2689- domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2690+ domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2691 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2692 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2693 #endif
2694diff --git a/arch/arm/kernel/hw_breakpoint.c b/arch/arm/kernel/hw_breakpoint.c
2695index 1fd749e..47adb08 100644
2696--- a/arch/arm/kernel/hw_breakpoint.c
2697+++ b/arch/arm/kernel/hw_breakpoint.c
2698@@ -1029,7 +1029,7 @@ static int __cpuinit dbg_reset_notify(struct notifier_block *self,
2699 return NOTIFY_OK;
2700 }
2701
2702-static struct notifier_block __cpuinitdata dbg_reset_nb = {
2703+static struct notifier_block dbg_reset_nb = {
2704 .notifier_call = dbg_reset_notify,
2705 };
2706
2707diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2708index 1e9be5d..03edbc2 100644
2709--- a/arch/arm/kernel/module.c
2710+++ b/arch/arm/kernel/module.c
2711@@ -37,12 +37,37 @@
2712 #endif
2713
2714 #ifdef CONFIG_MMU
2715-void *module_alloc(unsigned long size)
2716+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2717 {
2718+ if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2719+ return NULL;
2720 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2721- GFP_KERNEL, PAGE_KERNEL_EXEC, -1,
2722+ GFP_KERNEL, prot, -1,
2723 __builtin_return_address(0));
2724 }
2725+
2726+void *module_alloc(unsigned long size)
2727+{
2728+
2729+#ifdef CONFIG_PAX_KERNEXEC
2730+ return __module_alloc(size, PAGE_KERNEL);
2731+#else
2732+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2733+#endif
2734+
2735+}
2736+
2737+#ifdef CONFIG_PAX_KERNEXEC
2738+void module_free_exec(struct module *mod, void *module_region)
2739+{
2740+ module_free(mod, module_region);
2741+}
2742+
2743+void *module_alloc_exec(unsigned long size)
2744+{
2745+ return __module_alloc(size, PAGE_KERNEL_EXEC);
2746+}
2747+#endif
2748 #endif
2749
2750 int
2751diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2752index 07314af..c46655c 100644
2753--- a/arch/arm/kernel/patch.c
2754+++ b/arch/arm/kernel/patch.c
2755@@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2756 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2757 int size;
2758
2759+ pax_open_kernel();
2760 if (thumb2 && __opcode_is_thumb16(insn)) {
2761 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2762 size = sizeof(u16);
2763@@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2764 *(u32 *)addr = insn;
2765 size = sizeof(u32);
2766 }
2767+ pax_close_kernel();
2768
2769 flush_icache_range((uintptr_t)(addr),
2770 (uintptr_t)(addr) + size);
2771diff --git a/arch/arm/kernel/perf_event_cpu.c b/arch/arm/kernel/perf_event_cpu.c
2772index 1f2740e..b36e225 100644
2773--- a/arch/arm/kernel/perf_event_cpu.c
2774+++ b/arch/arm/kernel/perf_event_cpu.c
2775@@ -171,7 +171,7 @@ static int __cpuinit cpu_pmu_notify(struct notifier_block *b,
2776 return NOTIFY_OK;
2777 }
2778
2779-static struct notifier_block __cpuinitdata cpu_pmu_hotplug_notifier = {
2780+static struct notifier_block cpu_pmu_hotplug_notifier = {
2781 .notifier_call = cpu_pmu_notify,
2782 };
2783
2784diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2785index 047d3e4..7e96107 100644
2786--- a/arch/arm/kernel/process.c
2787+++ b/arch/arm/kernel/process.c
2788@@ -28,7 +28,6 @@
2789 #include <linux/tick.h>
2790 #include <linux/utsname.h>
2791 #include <linux/uaccess.h>
2792-#include <linux/random.h>
2793 #include <linux/hw_breakpoint.h>
2794 #include <linux/cpuidle.h>
2795 #include <linux/leds.h>
2796@@ -251,9 +250,10 @@ void machine_power_off(void)
2797 machine_shutdown();
2798 if (pm_power_off)
2799 pm_power_off();
2800+ BUG();
2801 }
2802
2803-void machine_restart(char *cmd)
2804+__noreturn void machine_restart(char *cmd)
2805 {
2806 machine_shutdown();
2807
2808@@ -278,8 +278,8 @@ void __show_regs(struct pt_regs *regs)
2809 init_utsname()->release,
2810 (int)strcspn(init_utsname()->version, " "),
2811 init_utsname()->version);
2812- print_symbol("PC is at %s\n", instruction_pointer(regs));
2813- print_symbol("LR is at %s\n", regs->ARM_lr);
2814+ printk("PC is at %pA\n", instruction_pointer(regs));
2815+ printk("LR is at %pA\n", regs->ARM_lr);
2816 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2817 "sp : %08lx ip : %08lx fp : %08lx\n",
2818 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2819@@ -447,12 +447,6 @@ unsigned long get_wchan(struct task_struct *p)
2820 return 0;
2821 }
2822
2823-unsigned long arch_randomize_brk(struct mm_struct *mm)
2824-{
2825- unsigned long range_end = mm->brk + 0x02000000;
2826- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2827-}
2828-
2829 #ifdef CONFIG_MMU
2830 /*
2831 * The vectors page is always readable from user space for the
2832@@ -465,9 +459,8 @@ static int __init gate_vma_init(void)
2833 {
2834 gate_vma.vm_start = 0xffff0000;
2835 gate_vma.vm_end = 0xffff0000 + PAGE_SIZE;
2836- gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2837- gate_vma.vm_flags = VM_READ | VM_EXEC |
2838- VM_MAYREAD | VM_MAYEXEC;
2839+ gate_vma.vm_flags = VM_NONE;
2840+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2841 return 0;
2842 }
2843 arch_initcall(gate_vma_init);
2844diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2845index 3653164..d83e55d 100644
2846--- a/arch/arm/kernel/psci.c
2847+++ b/arch/arm/kernel/psci.c
2848@@ -24,7 +24,7 @@
2849 #include <asm/opcodes-virt.h>
2850 #include <asm/psci.h>
2851
2852-struct psci_operations psci_ops;
2853+struct psci_operations psci_ops __read_only;
2854
2855 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2856
2857diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2858index 03deeff..741ce88 100644
2859--- a/arch/arm/kernel/ptrace.c
2860+++ b/arch/arm/kernel/ptrace.c
2861@@ -937,10 +937,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2862 return current_thread_info()->syscall;
2863 }
2864
2865+#ifdef CONFIG_GRKERNSEC_SETXID
2866+extern void gr_delayed_cred_worker(void);
2867+#endif
2868+
2869 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2870 {
2871 current_thread_info()->syscall = scno;
2872
2873+#ifdef CONFIG_GRKERNSEC_SETXID
2874+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2875+ gr_delayed_cred_worker();
2876+#endif
2877+
2878 /* Do the secure computing check first; failures should be fast. */
2879 if (secure_computing(scno) == -1)
2880 return -1;
2881diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2882index 234e339..81264a1 100644
2883--- a/arch/arm/kernel/setup.c
2884+++ b/arch/arm/kernel/setup.c
2885@@ -96,21 +96,23 @@ EXPORT_SYMBOL(system_serial_high);
2886 unsigned int elf_hwcap __read_mostly;
2887 EXPORT_SYMBOL(elf_hwcap);
2888
2889+pteval_t __supported_pte_mask __read_only;
2890+pmdval_t __supported_pmd_mask __read_only;
2891
2892 #ifdef MULTI_CPU
2893-struct processor processor __read_mostly;
2894+struct processor processor;
2895 #endif
2896 #ifdef MULTI_TLB
2897-struct cpu_tlb_fns cpu_tlb __read_mostly;
2898+struct cpu_tlb_fns cpu_tlb __read_only;
2899 #endif
2900 #ifdef MULTI_USER
2901-struct cpu_user_fns cpu_user __read_mostly;
2902+struct cpu_user_fns cpu_user __read_only;
2903 #endif
2904 #ifdef MULTI_CACHE
2905-struct cpu_cache_fns cpu_cache __read_mostly;
2906+struct cpu_cache_fns cpu_cache __read_only;
2907 #endif
2908 #ifdef CONFIG_OUTER_CACHE
2909-struct outer_cache_fns outer_cache __read_mostly;
2910+struct outer_cache_fns outer_cache __read_only;
2911 EXPORT_SYMBOL(outer_cache);
2912 #endif
2913
2914@@ -235,9 +237,13 @@ static int __get_cpu_architecture(void)
2915 asm("mrc p15, 0, %0, c0, c1, 4"
2916 : "=r" (mmfr0));
2917 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
2918- (mmfr0 & 0x000000f0) >= 0x00000030)
2919+ (mmfr0 & 0x000000f0) >= 0x00000030) {
2920 cpu_arch = CPU_ARCH_ARMv7;
2921- else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2922+ if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
2923+ __supported_pte_mask |= L_PTE_PXN;
2924+ __supported_pmd_mask |= PMD_PXNTABLE;
2925+ }
2926+ } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
2927 (mmfr0 & 0x000000f0) == 0x00000020)
2928 cpu_arch = CPU_ARCH_ARMv6;
2929 else
2930@@ -478,7 +484,7 @@ static void __init setup_processor(void)
2931 __cpu_architecture = __get_cpu_architecture();
2932
2933 #ifdef MULTI_CPU
2934- processor = *list->proc;
2935+ memcpy((void *)&processor, list->proc, sizeof processor);
2936 #endif
2937 #ifdef MULTI_TLB
2938 cpu_tlb = *list->tlb;
2939diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
2940index 296786b..a8d4dd5 100644
2941--- a/arch/arm/kernel/signal.c
2942+++ b/arch/arm/kernel/signal.c
2943@@ -396,22 +396,14 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
2944 __put_user(sigreturn_codes[idx+1], rc+1))
2945 return 1;
2946
2947- if (cpsr & MODE32_BIT) {
2948- /*
2949- * 32-bit code can use the new high-page
2950- * signal return code support.
2951- */
2952- retcode = KERN_SIGRETURN_CODE + (idx << 2) + thumb;
2953- } else {
2954- /*
2955- * Ensure that the instruction cache sees
2956- * the return code written onto the stack.
2957- */
2958- flush_icache_range((unsigned long)rc,
2959- (unsigned long)(rc + 2));
2960+ /*
2961+ * Ensure that the instruction cache sees
2962+ * the return code written onto the stack.
2963+ */
2964+ flush_icache_range((unsigned long)rc,
2965+ (unsigned long)(rc + 2));
2966
2967- retcode = ((unsigned long)rc) + thumb;
2968- }
2969+ retcode = ((unsigned long)rc) + thumb;
2970 }
2971
2972 regs->ARM_r0 = map_sig(ksig->sig);
2973diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
2974index 1f2cccc..f40c02e 100644
2975--- a/arch/arm/kernel/smp.c
2976+++ b/arch/arm/kernel/smp.c
2977@@ -70,7 +70,7 @@ enum ipi_msg_type {
2978
2979 static DECLARE_COMPLETION(cpu_running);
2980
2981-static struct smp_operations smp_ops;
2982+static struct smp_operations smp_ops __read_only;
2983
2984 void __init smp_set_ops(struct smp_operations *ops)
2985 {
2986diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
2987index 1c08911..264f009 100644
2988--- a/arch/arm/kernel/traps.c
2989+++ b/arch/arm/kernel/traps.c
2990@@ -57,7 +57,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
2991 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
2992 {
2993 #ifdef CONFIG_KALLSYMS
2994- printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
2995+ printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
2996 #else
2997 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
2998 #endif
2999@@ -266,6 +266,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3000 static int die_owner = -1;
3001 static unsigned int die_nest_count;
3002
3003+extern void gr_handle_kernel_exploit(void);
3004+
3005 static unsigned long oops_begin(void)
3006 {
3007 int cpu;
3008@@ -308,6 +310,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3009 panic("Fatal exception in interrupt");
3010 if (panic_on_oops)
3011 panic("Fatal exception");
3012+
3013+ gr_handle_kernel_exploit();
3014+
3015 if (signr)
3016 do_exit(signr);
3017 }
3018@@ -601,7 +606,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3019 * The user helper at 0xffff0fe0 must be used instead.
3020 * (see entry-armv.S for details)
3021 */
3022+ pax_open_kernel();
3023 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3024+ pax_close_kernel();
3025 }
3026 return 0;
3027
3028@@ -841,13 +848,10 @@ void __init early_trap_init(void *vectors_base)
3029 */
3030 kuser_get_tls_init(vectors);
3031
3032- /*
3033- * Copy signal return handlers into the vector page, and
3034- * set sigreturn to be a pointer to these.
3035- */
3036- memcpy((void *)(vectors + KERN_SIGRETURN_CODE - CONFIG_VECTORS_BASE),
3037- sigreturn_codes, sizeof(sigreturn_codes));
3038-
3039 flush_icache_range(vectors, vectors + PAGE_SIZE);
3040- modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3041+
3042+#ifndef CONFIG_PAX_MEMORY_UDEREF
3043+ modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3044+#endif
3045+
3046 }
3047diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3048index b571484..4b2fc9b 100644
3049--- a/arch/arm/kernel/vmlinux.lds.S
3050+++ b/arch/arm/kernel/vmlinux.lds.S
3051@@ -8,7 +8,11 @@
3052 #include <asm/thread_info.h>
3053 #include <asm/memory.h>
3054 #include <asm/page.h>
3055-
3056+
3057+#ifdef CONFIG_PAX_KERNEXEC
3058+#include <asm/pgtable.h>
3059+#endif
3060+
3061 #define PROC_INFO \
3062 . = ALIGN(4); \
3063 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3064@@ -94,6 +98,11 @@ SECTIONS
3065 _text = .;
3066 HEAD_TEXT
3067 }
3068+
3069+#ifdef CONFIG_PAX_KERNEXEC
3070+ . = ALIGN(1<<SECTION_SHIFT);
3071+#endif
3072+
3073 .text : { /* Real text segment */
3074 _stext = .; /* Text and read-only data */
3075 __exception_text_start = .;
3076@@ -116,6 +125,8 @@ SECTIONS
3077 ARM_CPU_KEEP(PROC_INFO)
3078 }
3079
3080+ _etext = .; /* End of text section */
3081+
3082 RO_DATA(PAGE_SIZE)
3083
3084 . = ALIGN(4);
3085@@ -146,7 +157,9 @@ SECTIONS
3086
3087 NOTES
3088
3089- _etext = .; /* End of text and rodata section */
3090+#ifdef CONFIG_PAX_KERNEXEC
3091+ . = ALIGN(1<<SECTION_SHIFT);
3092+#endif
3093
3094 #ifndef CONFIG_XIP_KERNEL
3095 . = ALIGN(PAGE_SIZE);
3096@@ -207,6 +220,11 @@ SECTIONS
3097 . = PAGE_OFFSET + TEXT_OFFSET;
3098 #else
3099 __init_end = .;
3100+
3101+#ifdef CONFIG_PAX_KERNEXEC
3102+ . = ALIGN(1<<SECTION_SHIFT);
3103+#endif
3104+
3105 . = ALIGN(THREAD_SIZE);
3106 __data_loc = .;
3107 #endif
3108diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3109index 14a0d98..7771a7d 100644
3110--- a/arch/arm/lib/clear_user.S
3111+++ b/arch/arm/lib/clear_user.S
3112@@ -12,14 +12,14 @@
3113
3114 .text
3115
3116-/* Prototype: int __clear_user(void *addr, size_t sz)
3117+/* Prototype: int ___clear_user(void *addr, size_t sz)
3118 * Purpose : clear some user memory
3119 * Params : addr - user memory address to clear
3120 * : sz - number of bytes to clear
3121 * Returns : number of bytes NOT cleared
3122 */
3123 ENTRY(__clear_user_std)
3124-WEAK(__clear_user)
3125+WEAK(___clear_user)
3126 stmfd sp!, {r1, lr}
3127 mov r2, #0
3128 cmp r1, #4
3129@@ -44,7 +44,7 @@ WEAK(__clear_user)
3130 USER( strnebt r2, [r0])
3131 mov r0, #0
3132 ldmfd sp!, {r1, pc}
3133-ENDPROC(__clear_user)
3134+ENDPROC(___clear_user)
3135 ENDPROC(__clear_user_std)
3136
3137 .pushsection .fixup,"ax"
3138diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3139index 66a477a..bee61d3 100644
3140--- a/arch/arm/lib/copy_from_user.S
3141+++ b/arch/arm/lib/copy_from_user.S
3142@@ -16,7 +16,7 @@
3143 /*
3144 * Prototype:
3145 *
3146- * size_t __copy_from_user(void *to, const void *from, size_t n)
3147+ * size_t ___copy_from_user(void *to, const void *from, size_t n)
3148 *
3149 * Purpose:
3150 *
3151@@ -84,11 +84,11 @@
3152
3153 .text
3154
3155-ENTRY(__copy_from_user)
3156+ENTRY(___copy_from_user)
3157
3158 #include "copy_template.S"
3159
3160-ENDPROC(__copy_from_user)
3161+ENDPROC(___copy_from_user)
3162
3163 .pushsection .fixup,"ax"
3164 .align 0
3165diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3166index 6ee2f67..d1cce76 100644
3167--- a/arch/arm/lib/copy_page.S
3168+++ b/arch/arm/lib/copy_page.S
3169@@ -10,6 +10,7 @@
3170 * ASM optimised string functions
3171 */
3172 #include <linux/linkage.h>
3173+#include <linux/const.h>
3174 #include <asm/assembler.h>
3175 #include <asm/asm-offsets.h>
3176 #include <asm/cache.h>
3177diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3178index d066df6..df28194 100644
3179--- a/arch/arm/lib/copy_to_user.S
3180+++ b/arch/arm/lib/copy_to_user.S
3181@@ -16,7 +16,7 @@
3182 /*
3183 * Prototype:
3184 *
3185- * size_t __copy_to_user(void *to, const void *from, size_t n)
3186+ * size_t ___copy_to_user(void *to, const void *from, size_t n)
3187 *
3188 * Purpose:
3189 *
3190@@ -88,11 +88,11 @@
3191 .text
3192
3193 ENTRY(__copy_to_user_std)
3194-WEAK(__copy_to_user)
3195+WEAK(___copy_to_user)
3196
3197 #include "copy_template.S"
3198
3199-ENDPROC(__copy_to_user)
3200+ENDPROC(___copy_to_user)
3201 ENDPROC(__copy_to_user_std)
3202
3203 .pushsection .fixup,"ax"
3204diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3205index 7d08b43..f7ca7ea 100644
3206--- a/arch/arm/lib/csumpartialcopyuser.S
3207+++ b/arch/arm/lib/csumpartialcopyuser.S
3208@@ -57,8 +57,8 @@
3209 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3210 */
3211
3212-#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3213-#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3214+#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3215+#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3216
3217 #include "csumpartialcopygeneric.S"
3218
3219diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3220index 64dbfa5..84a3fd9 100644
3221--- a/arch/arm/lib/delay.c
3222+++ b/arch/arm/lib/delay.c
3223@@ -28,7 +28,7 @@
3224 /*
3225 * Default to the loop-based delay implementation.
3226 */
3227-struct arm_delay_ops arm_delay_ops = {
3228+struct arm_delay_ops arm_delay_ops __read_only = {
3229 .delay = __loop_delay,
3230 .const_udelay = __loop_const_udelay,
3231 .udelay = __loop_udelay,
3232diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3233index 025f742..8432b08 100644
3234--- a/arch/arm/lib/uaccess_with_memcpy.c
3235+++ b/arch/arm/lib/uaccess_with_memcpy.c
3236@@ -104,7 +104,7 @@ out:
3237 }
3238
3239 unsigned long
3240-__copy_to_user(void __user *to, const void *from, unsigned long n)
3241+___copy_to_user(void __user *to, const void *from, unsigned long n)
3242 {
3243 /*
3244 * This test is stubbed out of the main function above to keep
3245diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3246index 49792a0..f192052 100644
3247--- a/arch/arm/mach-kirkwood/common.c
3248+++ b/arch/arm/mach-kirkwood/common.c
3249@@ -150,7 +150,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3250 clk_gate_ops.disable(hw);
3251 }
3252
3253-static struct clk_ops clk_gate_fn_ops;
3254+static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3255+{
3256+ return clk_gate_ops.is_enabled(hw);
3257+}
3258+
3259+static struct clk_ops clk_gate_fn_ops = {
3260+ .enable = clk_gate_fn_enable,
3261+ .disable = clk_gate_fn_disable,
3262+ .is_enabled = clk_gate_fn_is_enabled,
3263+};
3264
3265 static struct clk __init *clk_register_gate_fn(struct device *dev,
3266 const char *name,
3267@@ -184,14 +193,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3268 gate_fn->fn_en = fn_en;
3269 gate_fn->fn_dis = fn_dis;
3270
3271- /* ops is the gate ops, but with our enable/disable functions */
3272- if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3273- clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3274- clk_gate_fn_ops = clk_gate_ops;
3275- clk_gate_fn_ops.enable = clk_gate_fn_enable;
3276- clk_gate_fn_ops.disable = clk_gate_fn_disable;
3277- }
3278-
3279 clk = clk_register(dev, &gate_fn->gate.hw);
3280
3281 if (IS_ERR(clk))
3282diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3283index f6eeb87..cc90868 100644
3284--- a/arch/arm/mach-omap2/board-n8x0.c
3285+++ b/arch/arm/mach-omap2/board-n8x0.c
3286@@ -631,7 +631,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3287 }
3288 #endif
3289
3290-static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3291+static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3292 .late_init = n8x0_menelaus_late_init,
3293 };
3294
3295diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3296index 410e1ba..1d2dd59 100644
3297--- a/arch/arm/mach-omap2/gpmc.c
3298+++ b/arch/arm/mach-omap2/gpmc.c
3299@@ -145,7 +145,6 @@ struct omap3_gpmc_regs {
3300 };
3301
3302 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3303-static struct irq_chip gpmc_irq_chip;
3304 static unsigned gpmc_irq_start;
3305
3306 static struct resource gpmc_mem_root;
3307@@ -707,6 +706,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3308
3309 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3310
3311+static struct irq_chip gpmc_irq_chip = {
3312+ .name = "gpmc",
3313+ .irq_startup = gpmc_irq_noop_ret,
3314+ .irq_enable = gpmc_irq_enable,
3315+ .irq_disable = gpmc_irq_disable,
3316+ .irq_shutdown = gpmc_irq_noop,
3317+ .irq_ack = gpmc_irq_noop,
3318+ .irq_mask = gpmc_irq_noop,
3319+ .irq_unmask = gpmc_irq_noop,
3320+
3321+};
3322+
3323 static int gpmc_setup_irq(void)
3324 {
3325 int i;
3326@@ -721,15 +732,6 @@ static int gpmc_setup_irq(void)
3327 return gpmc_irq_start;
3328 }
3329
3330- gpmc_irq_chip.name = "gpmc";
3331- gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3332- gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3333- gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3334- gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3335- gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3336- gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3337- gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3338-
3339 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3340 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3341
3342diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3343index f8bb3b9..831e7b8 100644
3344--- a/arch/arm/mach-omap2/omap-wakeupgen.c
3345+++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3346@@ -339,7 +339,7 @@ static int __cpuinit irq_cpu_hotplug_notify(struct notifier_block *self,
3347 return NOTIFY_OK;
3348 }
3349
3350-static struct notifier_block __refdata irq_hotplug_notifier = {
3351+static struct notifier_block irq_hotplug_notifier = {
3352 .notifier_call = irq_cpu_hotplug_notify,
3353 };
3354
3355diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3356index 381be7a..89b9c7e 100644
3357--- a/arch/arm/mach-omap2/omap_device.c
3358+++ b/arch/arm/mach-omap2/omap_device.c
3359@@ -499,7 +499,7 @@ void omap_device_delete(struct omap_device *od)
3360 struct platform_device __init *omap_device_build(const char *pdev_name,
3361 int pdev_id,
3362 struct omap_hwmod *oh,
3363- void *pdata, int pdata_len)
3364+ const void *pdata, int pdata_len)
3365 {
3366 struct omap_hwmod *ohs[] = { oh };
3367
3368@@ -527,7 +527,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3369 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3370 int pdev_id,
3371 struct omap_hwmod **ohs,
3372- int oh_cnt, void *pdata,
3373+ int oh_cnt, const void *pdata,
3374 int pdata_len)
3375 {
3376 int ret = -ENOMEM;
3377diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3378index 044c31d..2ee0861 100644
3379--- a/arch/arm/mach-omap2/omap_device.h
3380+++ b/arch/arm/mach-omap2/omap_device.h
3381@@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3382 /* Core code interface */
3383
3384 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3385- struct omap_hwmod *oh, void *pdata,
3386+ struct omap_hwmod *oh, const void *pdata,
3387 int pdata_len);
3388
3389 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3390 struct omap_hwmod **oh, int oh_cnt,
3391- void *pdata, int pdata_len);
3392+ const void *pdata, int pdata_len);
3393
3394 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3395 struct omap_hwmod **ohs, int oh_cnt);
3396diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3397index 3a750de..4c9b88f 100644
3398--- a/arch/arm/mach-omap2/omap_hwmod.c
3399+++ b/arch/arm/mach-omap2/omap_hwmod.c
3400@@ -191,10 +191,10 @@ struct omap_hwmod_soc_ops {
3401 int (*init_clkdm)(struct omap_hwmod *oh);
3402 void (*update_context_lost)(struct omap_hwmod *oh);
3403 int (*get_context_lost)(struct omap_hwmod *oh);
3404-};
3405+} __no_const;
3406
3407 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3408-static struct omap_hwmod_soc_ops soc_ops;
3409+static struct omap_hwmod_soc_ops soc_ops __read_only;
3410
3411 /* omap_hwmod_list contains all registered struct omap_hwmods */
3412 static LIST_HEAD(omap_hwmod_list);
3413diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3414index d15c7bb..b2d1f0c 100644
3415--- a/arch/arm/mach-omap2/wd_timer.c
3416+++ b/arch/arm/mach-omap2/wd_timer.c
3417@@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3418 struct omap_hwmod *oh;
3419 char *oh_name = "wd_timer2";
3420 char *dev_name = "omap_wdt";
3421- struct omap_wd_timer_platform_data pdata;
3422+ static struct omap_wd_timer_platform_data pdata = {
3423+ .read_reset_sources = prm_read_reset_sources
3424+ };
3425
3426 if (!cpu_class_is_omap2() || of_have_populated_dt())
3427 return 0;
3428@@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3429 return -EINVAL;
3430 }
3431
3432- pdata.read_reset_sources = prm_read_reset_sources;
3433-
3434 pdev = omap_device_build(dev_name, id, oh, &pdata,
3435 sizeof(struct omap_wd_timer_platform_data));
3436 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3437diff --git a/arch/arm/mach-ux500/include/mach/setup.h b/arch/arm/mach-ux500/include/mach/setup.h
3438index bddce2b..3eb04e2 100644
3439--- a/arch/arm/mach-ux500/include/mach/setup.h
3440+++ b/arch/arm/mach-ux500/include/mach/setup.h
3441@@ -37,13 +37,6 @@ extern void ux500_timer_init(void);
3442 .type = MT_DEVICE, \
3443 }
3444
3445-#define __MEM_DEV_DESC(x, sz) { \
3446- .virtual = IO_ADDRESS(x), \
3447- .pfn = __phys_to_pfn(x), \
3448- .length = sz, \
3449- .type = MT_MEMORY, \
3450-}
3451-
3452 extern struct smp_operations ux500_smp_ops;
3453 extern void ux500_cpu_die(unsigned int cpu);
3454
3455diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3456index 4045c49..4e26c79 100644
3457--- a/arch/arm/mm/Kconfig
3458+++ b/arch/arm/mm/Kconfig
3459@@ -425,7 +425,7 @@ config CPU_32v5
3460
3461 config CPU_32v6
3462 bool
3463- select CPU_USE_DOMAINS if CPU_V6 && MMU
3464+ select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC
3465 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3466
3467 config CPU_32v6K
3468@@ -574,6 +574,7 @@ config CPU_CP15_MPU
3469
3470 config CPU_USE_DOMAINS
3471 bool
3472+ depends on !ARM_LPAE && !PAX_KERNEXEC
3473 help
3474 This option enables or disables the use of domain switching
3475 via the set_fs() function.
3476diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3477index db26e2e..ee44569 100644
3478--- a/arch/arm/mm/alignment.c
3479+++ b/arch/arm/mm/alignment.c
3480@@ -211,10 +211,12 @@ union offset_union {
3481 #define __get16_unaligned_check(ins,val,addr) \
3482 do { \
3483 unsigned int err = 0, v, a = addr; \
3484+ pax_open_userland(); \
3485 __get8_unaligned_check(ins,v,a,err); \
3486 val = v << ((BE) ? 8 : 0); \
3487 __get8_unaligned_check(ins,v,a,err); \
3488 val |= v << ((BE) ? 0 : 8); \
3489+ pax_close_userland(); \
3490 if (err) \
3491 goto fault; \
3492 } while (0)
3493@@ -228,6 +230,7 @@ union offset_union {
3494 #define __get32_unaligned_check(ins,val,addr) \
3495 do { \
3496 unsigned int err = 0, v, a = addr; \
3497+ pax_open_userland(); \
3498 __get8_unaligned_check(ins,v,a,err); \
3499 val = v << ((BE) ? 24 : 0); \
3500 __get8_unaligned_check(ins,v,a,err); \
3501@@ -236,6 +239,7 @@ union offset_union {
3502 val |= v << ((BE) ? 8 : 16); \
3503 __get8_unaligned_check(ins,v,a,err); \
3504 val |= v << ((BE) ? 0 : 24); \
3505+ pax_close_userland(); \
3506 if (err) \
3507 goto fault; \
3508 } while (0)
3509@@ -249,6 +253,7 @@ union offset_union {
3510 #define __put16_unaligned_check(ins,val,addr) \
3511 do { \
3512 unsigned int err = 0, v = val, a = addr; \
3513+ pax_open_userland(); \
3514 __asm__( FIRST_BYTE_16 \
3515 ARM( "1: "ins" %1, [%2], #1\n" ) \
3516 THUMB( "1: "ins" %1, [%2]\n" ) \
3517@@ -268,6 +273,7 @@ union offset_union {
3518 " .popsection\n" \
3519 : "=r" (err), "=&r" (v), "=&r" (a) \
3520 : "0" (err), "1" (v), "2" (a)); \
3521+ pax_close_userland(); \
3522 if (err) \
3523 goto fault; \
3524 } while (0)
3525@@ -281,6 +287,7 @@ union offset_union {
3526 #define __put32_unaligned_check(ins,val,addr) \
3527 do { \
3528 unsigned int err = 0, v = val, a = addr; \
3529+ pax_open_userland(); \
3530 __asm__( FIRST_BYTE_32 \
3531 ARM( "1: "ins" %1, [%2], #1\n" ) \
3532 THUMB( "1: "ins" %1, [%2]\n" ) \
3533@@ -310,6 +317,7 @@ union offset_union {
3534 " .popsection\n" \
3535 : "=r" (err), "=&r" (v), "=&r" (a) \
3536 : "0" (err), "1" (v), "2" (a)); \
3537+ pax_close_userland(); \
3538 if (err) \
3539 goto fault; \
3540 } while (0)
3541diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3542index 5dbf13f..1a60561 100644
3543--- a/arch/arm/mm/fault.c
3544+++ b/arch/arm/mm/fault.c
3545@@ -25,6 +25,7 @@
3546 #include <asm/system_misc.h>
3547 #include <asm/system_info.h>
3548 #include <asm/tlbflush.h>
3549+#include <asm/sections.h>
3550
3551 #include "fault.h"
3552
3553@@ -138,6 +139,20 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3554 if (fixup_exception(regs))
3555 return;
3556
3557+#ifdef CONFIG_PAX_KERNEXEC
3558+ if ((fsr & FSR_WRITE) &&
3559+ (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3560+ (MODULES_VADDR <= addr && addr < MODULES_END)))
3561+ {
3562+ if (current->signal->curr_ip)
3563+ 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),
3564+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3565+ else
3566+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3567+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3568+ }
3569+#endif
3570+
3571 /*
3572 * No handler, we'll have to terminate things with extreme prejudice.
3573 */
3574@@ -174,6 +189,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3575 }
3576 #endif
3577
3578+#ifdef CONFIG_PAX_PAGEEXEC
3579+ if (fsr & FSR_LNX_PF) {
3580+ pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3581+ do_group_exit(SIGKILL);
3582+ }
3583+#endif
3584+
3585 tsk->thread.address = addr;
3586 tsk->thread.error_code = fsr;
3587 tsk->thread.trap_no = 14;
3588@@ -398,6 +420,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3589 }
3590 #endif /* CONFIG_MMU */
3591
3592+#ifdef CONFIG_PAX_PAGEEXEC
3593+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3594+{
3595+ long i;
3596+
3597+ printk(KERN_ERR "PAX: bytes at PC: ");
3598+ for (i = 0; i < 20; i++) {
3599+ unsigned char c;
3600+ if (get_user(c, (__force unsigned char __user *)pc+i))
3601+ printk(KERN_CONT "?? ");
3602+ else
3603+ printk(KERN_CONT "%02x ", c);
3604+ }
3605+ printk("\n");
3606+
3607+ printk(KERN_ERR "PAX: bytes at SP-4: ");
3608+ for (i = -1; i < 20; i++) {
3609+ unsigned long c;
3610+ if (get_user(c, (__force unsigned long __user *)sp+i))
3611+ printk(KERN_CONT "???????? ");
3612+ else
3613+ printk(KERN_CONT "%08lx ", c);
3614+ }
3615+ printk("\n");
3616+}
3617+#endif
3618+
3619 /*
3620 * First Level Translation Fault Handler
3621 *
3622@@ -543,9 +592,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3623 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3624 struct siginfo info;
3625
3626+#ifdef CONFIG_PAX_MEMORY_UDEREF
3627+ if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3628+ if (current->signal->curr_ip)
3629+ 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),
3630+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3631+ else
3632+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3633+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3634+ goto die;
3635+ }
3636+#endif
3637+
3638 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3639 return;
3640
3641+die:
3642 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3643 inf->name, fsr, addr);
3644
3645@@ -575,9 +637,49 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3646 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3647 struct siginfo info;
3648
3649+ if (user_mode(regs)) {
3650+ if (addr == 0xffff0fe0UL) {
3651+ /*
3652+ * PaX: __kuser_get_tls emulation
3653+ */
3654+ regs->ARM_r0 = current_thread_info()->tp_value;
3655+ regs->ARM_pc = regs->ARM_lr;
3656+ return;
3657+ }
3658+ }
3659+
3660+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3661+ else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
3662+ if (current->signal->curr_ip)
3663+ 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),
3664+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3665+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3666+ else
3667+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
3668+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
3669+ addr >= TASK_SIZE ? "non-executable kernel" : "userland", addr);
3670+ goto die;
3671+ }
3672+#endif
3673+
3674+#ifdef CONFIG_PAX_REFCOUNT
3675+ if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
3676+ unsigned int bkpt;
3677+
3678+ if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
3679+ current->thread.error_code = ifsr;
3680+ current->thread.trap_no = 0;
3681+ pax_report_refcount_overflow(regs);
3682+ fixup_exception(regs);
3683+ return;
3684+ }
3685+ }
3686+#endif
3687+
3688 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
3689 return;
3690
3691+die:
3692 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
3693 inf->name, ifsr, addr);
3694
3695diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
3696index cf08bdf..772656c 100644
3697--- a/arch/arm/mm/fault.h
3698+++ b/arch/arm/mm/fault.h
3699@@ -3,6 +3,7 @@
3700
3701 /*
3702 * Fault status register encodings. We steal bit 31 for our own purposes.
3703+ * Set when the FSR value is from an instruction fault.
3704 */
3705 #define FSR_LNX_PF (1 << 31)
3706 #define FSR_WRITE (1 << 11)
3707@@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
3708 }
3709 #endif
3710
3711+/* valid for LPAE and !LPAE */
3712+static inline int is_xn_fault(unsigned int fsr)
3713+{
3714+ return ((fsr_fs(fsr) & 0x3c) == 0xc);
3715+}
3716+
3717+static inline int is_domain_fault(unsigned int fsr)
3718+{
3719+ return ((fsr_fs(fsr) & 0xD) == 0x9);
3720+}
3721+
3722 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
3723 unsigned long search_exception_table(unsigned long addr);
3724
3725diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
3726index ad722f1..763fdd3 100644
3727--- a/arch/arm/mm/init.c
3728+++ b/arch/arm/mm/init.c
3729@@ -30,6 +30,8 @@
3730 #include <asm/setup.h>
3731 #include <asm/tlb.h>
3732 #include <asm/fixmap.h>
3733+#include <asm/system_info.h>
3734+#include <asm/cp15.h>
3735
3736 #include <asm/mach/arch.h>
3737 #include <asm/mach/map.h>
3738@@ -736,7 +738,46 @@ void free_initmem(void)
3739 {
3740 #ifdef CONFIG_HAVE_TCM
3741 extern char __tcm_start, __tcm_end;
3742+#endif
3743
3744+#ifdef CONFIG_PAX_KERNEXEC
3745+ unsigned long addr;
3746+ pgd_t *pgd;
3747+ pud_t *pud;
3748+ pmd_t *pmd;
3749+ int cpu_arch = cpu_architecture();
3750+ unsigned int cr = get_cr();
3751+
3752+ if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
3753+ /* make pages tables, etc before .text NX */
3754+ for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
3755+ pgd = pgd_offset_k(addr);
3756+ pud = pud_offset(pgd, addr);
3757+ pmd = pmd_offset(pud, addr);
3758+ __section_update(pmd, addr, PMD_SECT_XN);
3759+ }
3760+ /* make init NX */
3761+ for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
3762+ pgd = pgd_offset_k(addr);
3763+ pud = pud_offset(pgd, addr);
3764+ pmd = pmd_offset(pud, addr);
3765+ __section_update(pmd, addr, PMD_SECT_XN);
3766+ }
3767+ /* make kernel code/rodata RX */
3768+ for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
3769+ pgd = pgd_offset_k(addr);
3770+ pud = pud_offset(pgd, addr);
3771+ pmd = pmd_offset(pud, addr);
3772+#ifdef CONFIG_ARM_LPAE
3773+ __section_update(pmd, addr, PMD_SECT_RDONLY);
3774+#else
3775+ __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
3776+#endif
3777+ }
3778+ }
3779+#endif
3780+
3781+#ifdef CONFIG_HAVE_TCM
3782 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
3783 totalram_pages += free_area(__phys_to_pfn(__pa(&__tcm_start)),
3784 __phys_to_pfn(__pa(&__tcm_end)),
3785diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
3786index 04d9006..c547d85 100644
3787--- a/arch/arm/mm/ioremap.c
3788+++ b/arch/arm/mm/ioremap.c
3789@@ -392,9 +392,9 @@ __arm_ioremap_exec(unsigned long phys_addr, size_t size, bool cached)
3790 unsigned int mtype;
3791
3792 if (cached)
3793- mtype = MT_MEMORY;
3794+ mtype = MT_MEMORY_RX;
3795 else
3796- mtype = MT_MEMORY_NONCACHED;
3797+ mtype = MT_MEMORY_NONCACHED_RX;
3798
3799 return __arm_ioremap_caller(phys_addr, size, mtype,
3800 __builtin_return_address(0));
3801diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
3802index 10062ce..8695745 100644
3803--- a/arch/arm/mm/mmap.c
3804+++ b/arch/arm/mm/mmap.c
3805@@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3806 struct vm_area_struct *vma;
3807 int do_align = 0;
3808 int aliasing = cache_is_vipt_aliasing();
3809+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3810 struct vm_unmapped_area_info info;
3811
3812 /*
3813@@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3814 if (len > TASK_SIZE)
3815 return -ENOMEM;
3816
3817+#ifdef CONFIG_PAX_RANDMMAP
3818+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3819+#endif
3820+
3821 if (addr) {
3822 if (do_align)
3823 addr = COLOUR_ALIGN(addr, pgoff);
3824@@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3825 addr = PAGE_ALIGN(addr);
3826
3827 vma = find_vma(mm, addr);
3828- if (TASK_SIZE - len >= addr &&
3829- (!vma || addr + len <= vma->vm_start))
3830+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3831 return addr;
3832 }
3833
3834@@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
3835 info.high_limit = TASK_SIZE;
3836 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3837 info.align_offset = pgoff << PAGE_SHIFT;
3838+ info.threadstack_offset = offset;
3839 return vm_unmapped_area(&info);
3840 }
3841
3842@@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3843 unsigned long addr = addr0;
3844 int do_align = 0;
3845 int aliasing = cache_is_vipt_aliasing();
3846+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
3847 struct vm_unmapped_area_info info;
3848
3849 /*
3850@@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3851 return addr;
3852 }
3853
3854+#ifdef CONFIG_PAX_RANDMMAP
3855+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3856+#endif
3857+
3858 /* requesting a specific address */
3859 if (addr) {
3860 if (do_align)
3861@@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3862 else
3863 addr = PAGE_ALIGN(addr);
3864 vma = find_vma(mm, addr);
3865- if (TASK_SIZE - len >= addr &&
3866- (!vma || addr + len <= vma->vm_start))
3867+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
3868 return addr;
3869 }
3870
3871@@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
3872 info.high_limit = mm->mmap_base;
3873 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
3874 info.align_offset = pgoff << PAGE_SHIFT;
3875+ info.threadstack_offset = offset;
3876 addr = vm_unmapped_area(&info);
3877
3878 /*
3879@@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3880 {
3881 unsigned long random_factor = 0UL;
3882
3883+#ifdef CONFIG_PAX_RANDMMAP
3884+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
3885+#endif
3886+
3887 /* 8 bits of randomness in 20 address space bits */
3888 if ((current->flags & PF_RANDOMIZE) &&
3889 !(current->personality & ADDR_NO_RANDOMIZE))
3890@@ -180,10 +194,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3891
3892 if (mmap_is_legacy()) {
3893 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
3894+
3895+#ifdef CONFIG_PAX_RANDMMAP
3896+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3897+ mm->mmap_base += mm->delta_mmap;
3898+#endif
3899+
3900 mm->get_unmapped_area = arch_get_unmapped_area;
3901 mm->unmap_area = arch_unmap_area;
3902 } else {
3903 mm->mmap_base = mmap_base(random_factor);
3904+
3905+#ifdef CONFIG_PAX_RANDMMAP
3906+ if (mm->pax_flags & MF_PAX_RANDMMAP)
3907+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
3908+#endif
3909+
3910 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
3911 mm->unmap_area = arch_unmap_area_topdown;
3912 }
3913diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
3914index a84ff76..f221c1d 100644
3915--- a/arch/arm/mm/mmu.c
3916+++ b/arch/arm/mm/mmu.c
3917@@ -36,6 +36,22 @@
3918 #include "mm.h"
3919 #include "tcm.h"
3920
3921+#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
3922+void modify_domain(unsigned int dom, unsigned int type)
3923+{
3924+ struct thread_info *thread = current_thread_info();
3925+ unsigned int domain = thread->cpu_domain;
3926+ /*
3927+ * DOMAIN_MANAGER might be defined to some other value,
3928+ * use the arch-defined constant
3929+ */
3930+ domain &= ~domain_val(dom, 3);
3931+ thread->cpu_domain = domain | domain_val(dom, type);
3932+ set_domain(thread->cpu_domain);
3933+}
3934+EXPORT_SYMBOL(modify_domain);
3935+#endif
3936+
3937 /*
3938 * empty_zero_page is a special page that is used for
3939 * zero-initialized data and COW.
3940@@ -211,10 +227,18 @@ void adjust_cr(unsigned long mask, unsigned long set)
3941 }
3942 #endif
3943
3944-#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
3945+#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
3946 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
3947
3948-static struct mem_type mem_types[] = {
3949+#ifdef CONFIG_PAX_KERNEXEC
3950+#define L_PTE_KERNEXEC L_PTE_RDONLY
3951+#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
3952+#else
3953+#define L_PTE_KERNEXEC L_PTE_DIRTY
3954+#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
3955+#endif
3956+
3957+static struct mem_type mem_types[] __read_only = {
3958 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
3959 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
3960 L_PTE_SHARED,
3961@@ -243,16 +267,16 @@ static struct mem_type mem_types[] = {
3962 [MT_UNCACHED] = {
3963 .prot_pte = PROT_PTE_DEVICE,
3964 .prot_l1 = PMD_TYPE_TABLE,
3965- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3966+ .prot_sect = PROT_SECT_DEVICE,
3967 .domain = DOMAIN_IO,
3968 },
3969 [MT_CACHECLEAN] = {
3970- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
3971+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
3972 .domain = DOMAIN_KERNEL,
3973 },
3974 #ifndef CONFIG_ARM_LPAE
3975 [MT_MINICLEAN] = {
3976- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
3977+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
3978 .domain = DOMAIN_KERNEL,
3979 },
3980 #endif
3981@@ -260,36 +284,54 @@ static struct mem_type mem_types[] = {
3982 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3983 L_PTE_RDONLY,
3984 .prot_l1 = PMD_TYPE_TABLE,
3985- .domain = DOMAIN_USER,
3986+ .domain = DOMAIN_VECTORS,
3987 },
3988 [MT_HIGH_VECTORS] = {
3989 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
3990- L_PTE_USER | L_PTE_RDONLY,
3991+ L_PTE_RDONLY,
3992 .prot_l1 = PMD_TYPE_TABLE,
3993- .domain = DOMAIN_USER,
3994+ .domain = DOMAIN_VECTORS,
3995 },
3996- [MT_MEMORY] = {
3997+ [MT_MEMORY_RWX] = {
3998 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
3999 .prot_l1 = PMD_TYPE_TABLE,
4000 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4001 .domain = DOMAIN_KERNEL,
4002 },
4003+ [MT_MEMORY_RW] = {
4004+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4005+ .prot_l1 = PMD_TYPE_TABLE,
4006+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4007+ .domain = DOMAIN_KERNEL,
4008+ },
4009+ [MT_MEMORY_RX] = {
4010+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4011+ .prot_l1 = PMD_TYPE_TABLE,
4012+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4013+ .domain = DOMAIN_KERNEL,
4014+ },
4015 [MT_ROM] = {
4016- .prot_sect = PMD_TYPE_SECT,
4017+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4018 .domain = DOMAIN_KERNEL,
4019 },
4020- [MT_MEMORY_NONCACHED] = {
4021+ [MT_MEMORY_NONCACHED_RW] = {
4022 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4023 L_PTE_MT_BUFFERABLE,
4024 .prot_l1 = PMD_TYPE_TABLE,
4025 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4026 .domain = DOMAIN_KERNEL,
4027 },
4028+ [MT_MEMORY_NONCACHED_RX] = {
4029+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4030+ L_PTE_MT_BUFFERABLE,
4031+ .prot_l1 = PMD_TYPE_TABLE,
4032+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4033+ .domain = DOMAIN_KERNEL,
4034+ },
4035 [MT_MEMORY_DTCM] = {
4036- .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4037- L_PTE_XN,
4038+ .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4039 .prot_l1 = PMD_TYPE_TABLE,
4040- .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4041+ .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4042 .domain = DOMAIN_KERNEL,
4043 },
4044 [MT_MEMORY_ITCM] = {
4045@@ -299,10 +341,10 @@ static struct mem_type mem_types[] = {
4046 },
4047 [MT_MEMORY_SO] = {
4048 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4049- L_PTE_MT_UNCACHED | L_PTE_XN,
4050+ L_PTE_MT_UNCACHED,
4051 .prot_l1 = PMD_TYPE_TABLE,
4052 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4053- PMD_SECT_UNCACHED | PMD_SECT_XN,
4054+ PMD_SECT_UNCACHED,
4055 .domain = DOMAIN_KERNEL,
4056 },
4057 [MT_MEMORY_DMA_READY] = {
4058@@ -388,9 +430,35 @@ static void __init build_mem_type_table(void)
4059 * to prevent speculative instruction fetches.
4060 */
4061 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4062+ mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4063 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4064+ mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4065 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4066+ mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4067 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4068+ mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4069+
4070+ /* Mark other regions on ARMv6+ as execute-never */
4071+
4072+#ifdef CONFIG_PAX_KERNEXEC
4073+ mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4074+ mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4075+ mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4076+ mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4077+#ifndef CONFIG_ARM_LPAE
4078+ mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4079+ mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4080+#endif
4081+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4082+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4083+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4084+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4085+ mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4086+ mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4087+#endif
4088+
4089+ mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4090+ mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4091 }
4092 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4093 /*
4094@@ -451,6 +519,9 @@ static void __init build_mem_type_table(void)
4095 * from SVC mode and no access from userspace.
4096 */
4097 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4098+#ifdef CONFIG_PAX_KERNEXEC
4099+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4100+#endif
4101 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4102 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4103 #endif
4104@@ -468,11 +539,17 @@ static void __init build_mem_type_table(void)
4105 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4106 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4107 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4108- mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4109- mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4110+ mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4111+ mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4112+ mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4113+ mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4114+ mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4115+ mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4116 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4117- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4118- mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4119+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4120+ mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4121+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4122+ mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4123 }
4124 }
4125
4126@@ -483,15 +560,20 @@ static void __init build_mem_type_table(void)
4127 if (cpu_arch >= CPU_ARCH_ARMv6) {
4128 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4129 /* Non-cacheable Normal is XCB = 001 */
4130- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4131+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4132+ PMD_SECT_BUFFERED;
4133+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4134 PMD_SECT_BUFFERED;
4135 } else {
4136 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4137- mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4138+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4139+ PMD_SECT_TEX(1);
4140+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4141 PMD_SECT_TEX(1);
4142 }
4143 } else {
4144- mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4145+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4146+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4147 }
4148
4149 #ifdef CONFIG_ARM_LPAE
4150@@ -507,6 +589,8 @@ static void __init build_mem_type_table(void)
4151 vecs_pgprot |= PTE_EXT_AF;
4152 #endif
4153
4154+ user_pgprot |= __supported_pte_mask;
4155+
4156 for (i = 0; i < 16; i++) {
4157 pteval_t v = pgprot_val(protection_map[i]);
4158 protection_map[i] = __pgprot(v | user_pgprot);
4159@@ -524,10 +608,15 @@ static void __init build_mem_type_table(void)
4160
4161 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4162 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4163- mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4164- mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4165+ mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4166+ mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4167+ mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4168+ mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4169+ mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4170+ mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4171 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4172- mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4173+ mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4174+ mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4175 mem_types[MT_ROM].prot_sect |= cp->pmd;
4176
4177 switch (cp->pmd) {
4178@@ -1147,18 +1236,15 @@ void __init arm_mm_memblock_reserve(void)
4179 * called function. This means you can't use any function or debugging
4180 * method which may touch any device, otherwise the kernel _will_ crash.
4181 */
4182+
4183+static char vectors[PAGE_SIZE] __read_only __aligned(PAGE_SIZE);
4184+
4185 static void __init devicemaps_init(struct machine_desc *mdesc)
4186 {
4187 struct map_desc map;
4188 unsigned long addr;
4189- void *vectors;
4190
4191- /*
4192- * Allocate the vector page early.
4193- */
4194- vectors = early_alloc(PAGE_SIZE);
4195-
4196- early_trap_init(vectors);
4197+ early_trap_init(&vectors);
4198
4199 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4200 pmd_clear(pmd_off_k(addr));
4201@@ -1198,7 +1284,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
4202 * location (0xffff0000). If we aren't using high-vectors, also
4203 * create a mapping at the low-vectors virtual address.
4204 */
4205- map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4206+ map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4207 map.virtual = 0xffff0000;
4208 map.length = PAGE_SIZE;
4209 map.type = MT_HIGH_VECTORS;
4210@@ -1256,8 +1342,39 @@ static void __init map_lowmem(void)
4211 map.pfn = __phys_to_pfn(start);
4212 map.virtual = __phys_to_virt(start);
4213 map.length = end - start;
4214- map.type = MT_MEMORY;
4215
4216+#ifdef CONFIG_PAX_KERNEXEC
4217+ if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4218+ struct map_desc kernel;
4219+ struct map_desc initmap;
4220+
4221+ /* when freeing initmem we will make this RW */
4222+ initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4223+ initmap.virtual = (unsigned long)__init_begin;
4224+ initmap.length = _sdata - __init_begin;
4225+ initmap.type = MT_MEMORY_RWX;
4226+ create_mapping(&initmap);
4227+
4228+ /* when freeing initmem we will make this RX */
4229+ kernel.pfn = __phys_to_pfn(__pa(_stext));
4230+ kernel.virtual = (unsigned long)_stext;
4231+ kernel.length = __init_begin - _stext;
4232+ kernel.type = MT_MEMORY_RWX;
4233+ create_mapping(&kernel);
4234+
4235+ if (map.virtual < (unsigned long)_stext) {
4236+ map.length = (unsigned long)_stext - map.virtual;
4237+ map.type = MT_MEMORY_RWX;
4238+ create_mapping(&map);
4239+ }
4240+
4241+ map.pfn = __phys_to_pfn(__pa(_sdata));
4242+ map.virtual = (unsigned long)_sdata;
4243+ map.length = end - __pa(_sdata);
4244+ }
4245+#endif
4246+
4247+ map.type = MT_MEMORY_RW;
4248 create_mapping(&map);
4249 }
4250 }
4251diff --git a/arch/arm/mm/proc-v7-2level.S b/arch/arm/mm/proc-v7-2level.S
4252index 78f520b..31f0cb6 100644
4253--- a/arch/arm/mm/proc-v7-2level.S
4254+++ b/arch/arm/mm/proc-v7-2level.S
4255@@ -99,6 +99,9 @@ ENTRY(cpu_v7_set_pte_ext)
4256 tst r1, #L_PTE_XN
4257 orrne r3, r3, #PTE_EXT_XN
4258
4259+ tst r1, #L_PTE_PXN
4260+ orrne r3, r3, #PTE_EXT_PXN
4261+
4262 tst r1, #L_PTE_YOUNG
4263 tstne r1, #L_PTE_VALID
4264 #ifndef CONFIG_CPU_USE_DOMAINS
4265diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4266index a5bc92d..0bb4730 100644
4267--- a/arch/arm/plat-omap/sram.c
4268+++ b/arch/arm/plat-omap/sram.c
4269@@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4270 * Looks like we need to preserve some bootloader code at the
4271 * beginning of SRAM for jumping to flash for reboot to work...
4272 */
4273+ pax_open_kernel();
4274 memset_io(omap_sram_base + omap_sram_skip, 0,
4275 omap_sram_size - omap_sram_skip);
4276+ pax_close_kernel();
4277 }
4278diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4279index 1141782..0959d64 100644
4280--- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4281+++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4282@@ -48,7 +48,7 @@ struct samsung_dma_ops {
4283 int (*started)(unsigned ch);
4284 int (*flush)(unsigned ch);
4285 int (*stop)(unsigned ch);
4286-};
4287+} __no_const;
4288
4289 extern void *samsung_dmadev_get_ops(void);
4290 extern void *s3c_dma_get_ops(void);
4291diff --git a/arch/arm64/kernel/debug-monitors.c b/arch/arm64/kernel/debug-monitors.c
4292index f4726dc..39ed646 100644
4293--- a/arch/arm64/kernel/debug-monitors.c
4294+++ b/arch/arm64/kernel/debug-monitors.c
4295@@ -149,7 +149,7 @@ static int __cpuinit os_lock_notify(struct notifier_block *self,
4296 return NOTIFY_OK;
4297 }
4298
4299-static struct notifier_block __cpuinitdata os_lock_nb = {
4300+static struct notifier_block os_lock_nb = {
4301 .notifier_call = os_lock_notify,
4302 };
4303
4304diff --git a/arch/arm64/kernel/hw_breakpoint.c b/arch/arm64/kernel/hw_breakpoint.c
4305index 5ab825c..96aaec8 100644
4306--- a/arch/arm64/kernel/hw_breakpoint.c
4307+++ b/arch/arm64/kernel/hw_breakpoint.c
4308@@ -831,7 +831,7 @@ static int __cpuinit hw_breakpoint_reset_notify(struct notifier_block *self,
4309 return NOTIFY_OK;
4310 }
4311
4312-static struct notifier_block __cpuinitdata hw_breakpoint_reset_nb = {
4313+static struct notifier_block hw_breakpoint_reset_nb = {
4314 .notifier_call = hw_breakpoint_reset_notify,
4315 };
4316
4317diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4318index c3a58a1..78fbf54 100644
4319--- a/arch/avr32/include/asm/cache.h
4320+++ b/arch/avr32/include/asm/cache.h
4321@@ -1,8 +1,10 @@
4322 #ifndef __ASM_AVR32_CACHE_H
4323 #define __ASM_AVR32_CACHE_H
4324
4325+#include <linux/const.h>
4326+
4327 #define L1_CACHE_SHIFT 5
4328-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4329+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4330
4331 /*
4332 * Memory returned by kmalloc() may be used for DMA, so we must make
4333diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4334index d232888..87c8df1 100644
4335--- a/arch/avr32/include/asm/elf.h
4336+++ b/arch/avr32/include/asm/elf.h
4337@@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4338 the loader. We need to make sure that it is out of the way of the program
4339 that it will "exec", and that there is sufficient room for the brk. */
4340
4341-#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4342+#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4343
4344+#ifdef CONFIG_PAX_ASLR
4345+#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4346+
4347+#define PAX_DELTA_MMAP_LEN 15
4348+#define PAX_DELTA_STACK_LEN 15
4349+#endif
4350
4351 /* This yields a mask that user programs can use to figure out what
4352 instruction set this CPU supports. This could be done in user space,
4353diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4354index 479330b..53717a8 100644
4355--- a/arch/avr32/include/asm/kmap_types.h
4356+++ b/arch/avr32/include/asm/kmap_types.h
4357@@ -2,9 +2,9 @@
4358 #define __ASM_AVR32_KMAP_TYPES_H
4359
4360 #ifdef CONFIG_DEBUG_HIGHMEM
4361-# define KM_TYPE_NR 29
4362+# define KM_TYPE_NR 30
4363 #else
4364-# define KM_TYPE_NR 14
4365+# define KM_TYPE_NR 15
4366 #endif
4367
4368 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4369diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4370index b2f2d2d..d1c85cb 100644
4371--- a/arch/avr32/mm/fault.c
4372+++ b/arch/avr32/mm/fault.c
4373@@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4374
4375 int exception_trace = 1;
4376
4377+#ifdef CONFIG_PAX_PAGEEXEC
4378+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4379+{
4380+ unsigned long i;
4381+
4382+ printk(KERN_ERR "PAX: bytes at PC: ");
4383+ for (i = 0; i < 20; i++) {
4384+ unsigned char c;
4385+ if (get_user(c, (unsigned char *)pc+i))
4386+ printk(KERN_CONT "???????? ");
4387+ else
4388+ printk(KERN_CONT "%02x ", c);
4389+ }
4390+ printk("\n");
4391+}
4392+#endif
4393+
4394 /*
4395 * This routine handles page faults. It determines the address and the
4396 * problem, and then passes it off to one of the appropriate routines.
4397@@ -174,6 +191,16 @@ bad_area:
4398 up_read(&mm->mmap_sem);
4399
4400 if (user_mode(regs)) {
4401+
4402+#ifdef CONFIG_PAX_PAGEEXEC
4403+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4404+ if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4405+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4406+ do_group_exit(SIGKILL);
4407+ }
4408+ }
4409+#endif
4410+
4411 if (exception_trace && printk_ratelimit())
4412 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4413 "sp %08lx ecr %lu\n",
4414diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4415index 568885a..f8008df 100644
4416--- a/arch/blackfin/include/asm/cache.h
4417+++ b/arch/blackfin/include/asm/cache.h
4418@@ -7,6 +7,7 @@
4419 #ifndef __ARCH_BLACKFIN_CACHE_H
4420 #define __ARCH_BLACKFIN_CACHE_H
4421
4422+#include <linux/const.h>
4423 #include <linux/linkage.h> /* for asmlinkage */
4424
4425 /*
4426@@ -14,7 +15,7 @@
4427 * Blackfin loads 32 bytes for cache
4428 */
4429 #define L1_CACHE_SHIFT 5
4430-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4431+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4432 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4433
4434 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4435diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4436index aea2718..3639a60 100644
4437--- a/arch/cris/include/arch-v10/arch/cache.h
4438+++ b/arch/cris/include/arch-v10/arch/cache.h
4439@@ -1,8 +1,9 @@
4440 #ifndef _ASM_ARCH_CACHE_H
4441 #define _ASM_ARCH_CACHE_H
4442
4443+#include <linux/const.h>
4444 /* Etrax 100LX have 32-byte cache-lines. */
4445-#define L1_CACHE_BYTES 32
4446 #define L1_CACHE_SHIFT 5
4447+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4448
4449 #endif /* _ASM_ARCH_CACHE_H */
4450diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4451index 7caf25d..ee65ac5 100644
4452--- a/arch/cris/include/arch-v32/arch/cache.h
4453+++ b/arch/cris/include/arch-v32/arch/cache.h
4454@@ -1,11 +1,12 @@
4455 #ifndef _ASM_CRIS_ARCH_CACHE_H
4456 #define _ASM_CRIS_ARCH_CACHE_H
4457
4458+#include <linux/const.h>
4459 #include <arch/hwregs/dma.h>
4460
4461 /* A cache-line is 32 bytes. */
4462-#define L1_CACHE_BYTES 32
4463 #define L1_CACHE_SHIFT 5
4464+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4465
4466 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4467
4468diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4469index b86329d..6709906 100644
4470--- a/arch/frv/include/asm/atomic.h
4471+++ b/arch/frv/include/asm/atomic.h
4472@@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4473 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4474 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4475
4476+#define atomic64_read_unchecked(v) atomic64_read(v)
4477+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4478+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4479+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4480+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4481+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4482+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4483+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4484+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4485+
4486 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4487 {
4488 int c, old;
4489diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4490index 2797163..c2a401d 100644
4491--- a/arch/frv/include/asm/cache.h
4492+++ b/arch/frv/include/asm/cache.h
4493@@ -12,10 +12,11 @@
4494 #ifndef __ASM_CACHE_H
4495 #define __ASM_CACHE_H
4496
4497+#include <linux/const.h>
4498
4499 /* bytes per L1 cache line */
4500 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4501-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4502+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4503
4504 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4505 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4506diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4507index 43901f2..0d8b865 100644
4508--- a/arch/frv/include/asm/kmap_types.h
4509+++ b/arch/frv/include/asm/kmap_types.h
4510@@ -2,6 +2,6 @@
4511 #ifndef _ASM_KMAP_TYPES_H
4512 #define _ASM_KMAP_TYPES_H
4513
4514-#define KM_TYPE_NR 17
4515+#define KM_TYPE_NR 18
4516
4517 #endif
4518diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4519index 836f147..4cf23f5 100644
4520--- a/arch/frv/mm/elf-fdpic.c
4521+++ b/arch/frv/mm/elf-fdpic.c
4522@@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4523 {
4524 struct vm_area_struct *vma;
4525 struct vm_unmapped_area_info info;
4526+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4527
4528 if (len > TASK_SIZE)
4529 return -ENOMEM;
4530@@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4531 if (addr) {
4532 addr = PAGE_ALIGN(addr);
4533 vma = find_vma(current->mm, addr);
4534- if (TASK_SIZE - len >= addr &&
4535- (!vma || addr + len <= vma->vm_start))
4536+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4537 goto success;
4538 }
4539
4540@@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4541 info.high_limit = (current->mm->start_stack - 0x00200000);
4542 info.align_mask = 0;
4543 info.align_offset = 0;
4544+ info.threadstack_offset = offset;
4545 addr = vm_unmapped_area(&info);
4546 if (!(addr & ~PAGE_MASK))
4547 goto success;
4548diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4549index f4ca594..adc72fd6 100644
4550--- a/arch/hexagon/include/asm/cache.h
4551+++ b/arch/hexagon/include/asm/cache.h
4552@@ -21,9 +21,11 @@
4553 #ifndef __ASM_CACHE_H
4554 #define __ASM_CACHE_H
4555
4556+#include <linux/const.h>
4557+
4558 /* Bytes per L1 cache line */
4559-#define L1_CACHE_SHIFT (5)
4560-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4561+#define L1_CACHE_SHIFT 5
4562+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4563
4564 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4565 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4566diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4567index 6e6fe18..a6ae668 100644
4568--- a/arch/ia64/include/asm/atomic.h
4569+++ b/arch/ia64/include/asm/atomic.h
4570@@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4571 #define atomic64_inc(v) atomic64_add(1, (v))
4572 #define atomic64_dec(v) atomic64_sub(1, (v))
4573
4574+#define atomic64_read_unchecked(v) atomic64_read(v)
4575+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4576+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4577+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4578+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4579+#define atomic64_inc_unchecked(v) atomic64_inc(v)
4580+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4581+#define atomic64_dec_unchecked(v) atomic64_dec(v)
4582+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4583+
4584 /* Atomic operations are already serializing */
4585 #define smp_mb__before_atomic_dec() barrier()
4586 #define smp_mb__after_atomic_dec() barrier()
4587diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4588index 988254a..e1ee885 100644
4589--- a/arch/ia64/include/asm/cache.h
4590+++ b/arch/ia64/include/asm/cache.h
4591@@ -1,6 +1,7 @@
4592 #ifndef _ASM_IA64_CACHE_H
4593 #define _ASM_IA64_CACHE_H
4594
4595+#include <linux/const.h>
4596
4597 /*
4598 * Copyright (C) 1998-2000 Hewlett-Packard Co
4599@@ -9,7 +10,7 @@
4600
4601 /* Bytes per L1 (data) cache line. */
4602 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4603-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4604+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4605
4606 #ifdef CONFIG_SMP
4607 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4608diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4609index 5a83c5c..4d7f553 100644
4610--- a/arch/ia64/include/asm/elf.h
4611+++ b/arch/ia64/include/asm/elf.h
4612@@ -42,6 +42,13 @@
4613 */
4614 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4615
4616+#ifdef CONFIG_PAX_ASLR
4617+#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4618+
4619+#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4620+#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4621+#endif
4622+
4623 #define PT_IA_64_UNWIND 0x70000001
4624
4625 /* IA-64 relocations: */
4626diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4627index 96a8d92..617a1cf 100644
4628--- a/arch/ia64/include/asm/pgalloc.h
4629+++ b/arch/ia64/include/asm/pgalloc.h
4630@@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4631 pgd_val(*pgd_entry) = __pa(pud);
4632 }
4633
4634+static inline void
4635+pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4636+{
4637+ pgd_populate(mm, pgd_entry, pud);
4638+}
4639+
4640 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4641 {
4642 return quicklist_alloc(0, GFP_KERNEL, NULL);
4643@@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4644 pud_val(*pud_entry) = __pa(pmd);
4645 }
4646
4647+static inline void
4648+pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4649+{
4650+ pud_populate(mm, pud_entry, pmd);
4651+}
4652+
4653 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
4654 {
4655 return quicklist_alloc(0, GFP_KERNEL, NULL);
4656diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
4657index 815810c..d60bd4c 100644
4658--- a/arch/ia64/include/asm/pgtable.h
4659+++ b/arch/ia64/include/asm/pgtable.h
4660@@ -12,7 +12,7 @@
4661 * David Mosberger-Tang <davidm@hpl.hp.com>
4662 */
4663
4664-
4665+#include <linux/const.h>
4666 #include <asm/mman.h>
4667 #include <asm/page.h>
4668 #include <asm/processor.h>
4669@@ -142,6 +142,17 @@
4670 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4671 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4672 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
4673+
4674+#ifdef CONFIG_PAX_PAGEEXEC
4675+# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
4676+# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4677+# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
4678+#else
4679+# define PAGE_SHARED_NOEXEC PAGE_SHARED
4680+# define PAGE_READONLY_NOEXEC PAGE_READONLY
4681+# define PAGE_COPY_NOEXEC PAGE_COPY
4682+#endif
4683+
4684 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
4685 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
4686 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
4687diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
4688index 54ff557..70c88b7 100644
4689--- a/arch/ia64/include/asm/spinlock.h
4690+++ b/arch/ia64/include/asm/spinlock.h
4691@@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
4692 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
4693
4694 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
4695- ACCESS_ONCE(*p) = (tmp + 2) & ~1;
4696+ ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
4697 }
4698
4699 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
4700diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
4701index 449c8c0..18965fb 100644
4702--- a/arch/ia64/include/asm/uaccess.h
4703+++ b/arch/ia64/include/asm/uaccess.h
4704@@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
4705 static inline unsigned long
4706 __copy_to_user (void __user *to, const void *from, unsigned long count)
4707 {
4708+ if (count > INT_MAX)
4709+ return count;
4710+
4711+ if (!__builtin_constant_p(count))
4712+ check_object_size(from, count, true);
4713+
4714 return __copy_user(to, (__force void __user *) from, count);
4715 }
4716
4717 static inline unsigned long
4718 __copy_from_user (void *to, const void __user *from, unsigned long count)
4719 {
4720+ if (count > INT_MAX)
4721+ return count;
4722+
4723+ if (!__builtin_constant_p(count))
4724+ check_object_size(to, count, false);
4725+
4726 return __copy_user((__force void __user *) to, from, count);
4727 }
4728
4729@@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4730 ({ \
4731 void __user *__cu_to = (to); \
4732 const void *__cu_from = (from); \
4733- long __cu_len = (n); \
4734+ unsigned long __cu_len = (n); \
4735 \
4736- if (__access_ok(__cu_to, __cu_len, get_fs())) \
4737+ if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
4738+ if (!__builtin_constant_p(n)) \
4739+ check_object_size(__cu_from, __cu_len, true); \
4740 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
4741+ } \
4742 __cu_len; \
4743 })
4744
4745@@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
4746 ({ \
4747 void *__cu_to = (to); \
4748 const void __user *__cu_from = (from); \
4749- long __cu_len = (n); \
4750+ unsigned long __cu_len = (n); \
4751 \
4752 __chk_user_ptr(__cu_from); \
4753- if (__access_ok(__cu_from, __cu_len, get_fs())) \
4754+ if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
4755+ if (!__builtin_constant_p(n)) \
4756+ check_object_size(__cu_to, __cu_len, false); \
4757 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
4758+ } \
4759 __cu_len; \
4760 })
4761
4762diff --git a/arch/ia64/kernel/err_inject.c b/arch/ia64/kernel/err_inject.c
4763index 2d67317..07d8bfa 100644
4764--- a/arch/ia64/kernel/err_inject.c
4765+++ b/arch/ia64/kernel/err_inject.c
4766@@ -256,7 +256,7 @@ static int __cpuinit err_inject_cpu_callback(struct notifier_block *nfb,
4767 return NOTIFY_OK;
4768 }
4769
4770-static struct notifier_block __cpuinitdata err_inject_cpu_notifier =
4771+static struct notifier_block err_inject_cpu_notifier =
4772 {
4773 .notifier_call = err_inject_cpu_callback,
4774 };
4775diff --git a/arch/ia64/kernel/mca.c b/arch/ia64/kernel/mca.c
4776index d7396db..b33e873 100644
4777--- a/arch/ia64/kernel/mca.c
4778+++ b/arch/ia64/kernel/mca.c
4779@@ -1922,7 +1922,7 @@ static int __cpuinit mca_cpu_callback(struct notifier_block *nfb,
4780 return NOTIFY_OK;
4781 }
4782
4783-static struct notifier_block mca_cpu_notifier __cpuinitdata = {
4784+static struct notifier_block mca_cpu_notifier = {
4785 .notifier_call = mca_cpu_callback
4786 };
4787
4788diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
4789index 24603be..948052d 100644
4790--- a/arch/ia64/kernel/module.c
4791+++ b/arch/ia64/kernel/module.c
4792@@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
4793 void
4794 module_free (struct module *mod, void *module_region)
4795 {
4796- if (mod && mod->arch.init_unw_table &&
4797- module_region == mod->module_init) {
4798+ if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
4799 unw_remove_unwind_table(mod->arch.init_unw_table);
4800 mod->arch.init_unw_table = NULL;
4801 }
4802@@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
4803 }
4804
4805 static inline int
4806+in_init_rx (const struct module *mod, uint64_t addr)
4807+{
4808+ return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
4809+}
4810+
4811+static inline int
4812+in_init_rw (const struct module *mod, uint64_t addr)
4813+{
4814+ return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
4815+}
4816+
4817+static inline int
4818 in_init (const struct module *mod, uint64_t addr)
4819 {
4820- return addr - (uint64_t) mod->module_init < mod->init_size;
4821+ return in_init_rx(mod, addr) || in_init_rw(mod, addr);
4822+}
4823+
4824+static inline int
4825+in_core_rx (const struct module *mod, uint64_t addr)
4826+{
4827+ return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
4828+}
4829+
4830+static inline int
4831+in_core_rw (const struct module *mod, uint64_t addr)
4832+{
4833+ return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
4834 }
4835
4836 static inline int
4837 in_core (const struct module *mod, uint64_t addr)
4838 {
4839- return addr - (uint64_t) mod->module_core < mod->core_size;
4840+ return in_core_rx(mod, addr) || in_core_rw(mod, addr);
4841 }
4842
4843 static inline int
4844@@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
4845 break;
4846
4847 case RV_BDREL:
4848- val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
4849+ if (in_init_rx(mod, val))
4850+ val -= (uint64_t) mod->module_init_rx;
4851+ else if (in_init_rw(mod, val))
4852+ val -= (uint64_t) mod->module_init_rw;
4853+ else if (in_core_rx(mod, val))
4854+ val -= (uint64_t) mod->module_core_rx;
4855+ else if (in_core_rw(mod, val))
4856+ val -= (uint64_t) mod->module_core_rw;
4857 break;
4858
4859 case RV_LTV:
4860@@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
4861 * addresses have been selected...
4862 */
4863 uint64_t gp;
4864- if (mod->core_size > MAX_LTOFF)
4865+ if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
4866 /*
4867 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
4868 * at the end of the module.
4869 */
4870- gp = mod->core_size - MAX_LTOFF / 2;
4871+ gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
4872 else
4873- gp = mod->core_size / 2;
4874- gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
4875+ gp = (mod->core_size_rx + mod->core_size_rw) / 2;
4876+ gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
4877 mod->arch.gp = gp;
4878 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
4879 }
4880diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
4881index 79521d5..43dddff 100644
4882--- a/arch/ia64/kernel/palinfo.c
4883+++ b/arch/ia64/kernel/palinfo.c
4884@@ -1006,7 +1006,7 @@ static int __cpuinit palinfo_cpu_callback(struct notifier_block *nfb,
4885 return NOTIFY_OK;
4886 }
4887
4888-static struct notifier_block __refdata palinfo_cpu_notifier =
4889+static struct notifier_block palinfo_cpu_notifier =
4890 {
4891 .notifier_call = palinfo_cpu_callback,
4892 .priority = 0,
4893diff --git a/arch/ia64/kernel/salinfo.c b/arch/ia64/kernel/salinfo.c
4894index aa527d7..f237752 100644
4895--- a/arch/ia64/kernel/salinfo.c
4896+++ b/arch/ia64/kernel/salinfo.c
4897@@ -616,7 +616,7 @@ salinfo_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu
4898 return NOTIFY_OK;
4899 }
4900
4901-static struct notifier_block salinfo_cpu_notifier __cpuinitdata =
4902+static struct notifier_block salinfo_cpu_notifier =
4903 {
4904 .notifier_call = salinfo_cpu_callback,
4905 .priority = 0,
4906diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
4907index 41e33f8..65180b2 100644
4908--- a/arch/ia64/kernel/sys_ia64.c
4909+++ b/arch/ia64/kernel/sys_ia64.c
4910@@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4911 unsigned long align_mask = 0;
4912 struct mm_struct *mm = current->mm;
4913 struct vm_unmapped_area_info info;
4914+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4915
4916 if (len > RGN_MAP_LIMIT)
4917 return -ENOMEM;
4918@@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4919 if (REGION_NUMBER(addr) == RGN_HPAGE)
4920 addr = 0;
4921 #endif
4922+
4923+#ifdef CONFIG_PAX_RANDMMAP
4924+ if (mm->pax_flags & MF_PAX_RANDMMAP)
4925+ addr = mm->free_area_cache;
4926+ else
4927+#endif
4928+
4929 if (!addr)
4930 addr = TASK_UNMAPPED_BASE;
4931
4932@@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
4933 info.high_limit = TASK_SIZE;
4934 info.align_mask = align_mask;
4935 info.align_offset = 0;
4936+ info.threadstack_offset = offset;
4937 return vm_unmapped_area(&info);
4938 }
4939
4940diff --git a/arch/ia64/kernel/topology.c b/arch/ia64/kernel/topology.c
4941index dc00b2c..cce53c2 100644
4942--- a/arch/ia64/kernel/topology.c
4943+++ b/arch/ia64/kernel/topology.c
4944@@ -445,7 +445,7 @@ static int __cpuinit cache_cpu_callback(struct notifier_block *nfb,
4945 return NOTIFY_OK;
4946 }
4947
4948-static struct notifier_block __cpuinitdata cache_cpu_notifier =
4949+static struct notifier_block cache_cpu_notifier =
4950 {
4951 .notifier_call = cache_cpu_callback
4952 };
4953diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
4954index 0ccb28f..8992469 100644
4955--- a/arch/ia64/kernel/vmlinux.lds.S
4956+++ b/arch/ia64/kernel/vmlinux.lds.S
4957@@ -198,7 +198,7 @@ SECTIONS {
4958 /* Per-cpu data: */
4959 . = ALIGN(PERCPU_PAGE_SIZE);
4960 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
4961- __phys_per_cpu_start = __per_cpu_load;
4962+ __phys_per_cpu_start = per_cpu_load;
4963 /*
4964 * ensure percpu data fits
4965 * into percpu page size
4966diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
4967index 6cf0341..d352594 100644
4968--- a/arch/ia64/mm/fault.c
4969+++ b/arch/ia64/mm/fault.c
4970@@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
4971 return pte_present(pte);
4972 }
4973
4974+#ifdef CONFIG_PAX_PAGEEXEC
4975+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4976+{
4977+ unsigned long i;
4978+
4979+ printk(KERN_ERR "PAX: bytes at PC: ");
4980+ for (i = 0; i < 8; i++) {
4981+ unsigned int c;
4982+ if (get_user(c, (unsigned int *)pc+i))
4983+ printk(KERN_CONT "???????? ");
4984+ else
4985+ printk(KERN_CONT "%08x ", c);
4986+ }
4987+ printk("\n");
4988+}
4989+#endif
4990+
4991 # define VM_READ_BIT 0
4992 # define VM_WRITE_BIT 1
4993 # define VM_EXEC_BIT 2
4994@@ -149,8 +166,21 @@ retry:
4995 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
4996 goto bad_area;
4997
4998- if ((vma->vm_flags & mask) != mask)
4999+ if ((vma->vm_flags & mask) != mask) {
5000+
5001+#ifdef CONFIG_PAX_PAGEEXEC
5002+ if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5003+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5004+ goto bad_area;
5005+
5006+ up_read(&mm->mmap_sem);
5007+ pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5008+ do_group_exit(SIGKILL);
5009+ }
5010+#endif
5011+
5012 goto bad_area;
5013+ }
5014
5015 /*
5016 * If for any reason at all we couldn't handle the fault, make
5017diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5018index 76069c1..c2aa816 100644
5019--- a/arch/ia64/mm/hugetlbpage.c
5020+++ b/arch/ia64/mm/hugetlbpage.c
5021@@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5022 unsigned long pgoff, unsigned long flags)
5023 {
5024 struct vm_unmapped_area_info info;
5025+ unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5026
5027 if (len > RGN_MAP_LIMIT)
5028 return -ENOMEM;
5029@@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5030 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5031 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5032 info.align_offset = 0;
5033+ info.threadstack_offset = offset;
5034 return vm_unmapped_area(&info);
5035 }
5036
5037diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5038index 20bc967..a26993e 100644
5039--- a/arch/ia64/mm/init.c
5040+++ b/arch/ia64/mm/init.c
5041@@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5042 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5043 vma->vm_end = vma->vm_start + PAGE_SIZE;
5044 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5045+
5046+#ifdef CONFIG_PAX_PAGEEXEC
5047+ if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5048+ vma->vm_flags &= ~VM_EXEC;
5049+
5050+#ifdef CONFIG_PAX_MPROTECT
5051+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
5052+ vma->vm_flags &= ~VM_MAYEXEC;
5053+#endif
5054+
5055+ }
5056+#endif
5057+
5058 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5059 down_write(&current->mm->mmap_sem);
5060 if (insert_vm_struct(current->mm, vma)) {
5061diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5062index 40b3ee9..8c2c112 100644
5063--- a/arch/m32r/include/asm/cache.h
5064+++ b/arch/m32r/include/asm/cache.h
5065@@ -1,8 +1,10 @@
5066 #ifndef _ASM_M32R_CACHE_H
5067 #define _ASM_M32R_CACHE_H
5068
5069+#include <linux/const.h>
5070+
5071 /* L1 cache line size */
5072 #define L1_CACHE_SHIFT 4
5073-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5074+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5075
5076 #endif /* _ASM_M32R_CACHE_H */
5077diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5078index 82abd15..d95ae5d 100644
5079--- a/arch/m32r/lib/usercopy.c
5080+++ b/arch/m32r/lib/usercopy.c
5081@@ -14,6 +14,9 @@
5082 unsigned long
5083 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5084 {
5085+ if ((long)n < 0)
5086+ return n;
5087+
5088 prefetch(from);
5089 if (access_ok(VERIFY_WRITE, to, n))
5090 __copy_user(to,from,n);
5091@@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5092 unsigned long
5093 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5094 {
5095+ if ((long)n < 0)
5096+ return n;
5097+
5098 prefetchw(to);
5099 if (access_ok(VERIFY_READ, from, n))
5100 __copy_user_zeroing(to,from,n);
5101diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5102index 0395c51..5f26031 100644
5103--- a/arch/m68k/include/asm/cache.h
5104+++ b/arch/m68k/include/asm/cache.h
5105@@ -4,9 +4,11 @@
5106 #ifndef __ARCH_M68K_CACHE_H
5107 #define __ARCH_M68K_CACHE_H
5108
5109+#include <linux/const.h>
5110+
5111 /* bytes per L1 cache line */
5112 #define L1_CACHE_SHIFT 4
5113-#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5114+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5115
5116 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5117
5118diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5119index 3c52fa6..11b2ad8 100644
5120--- a/arch/metag/mm/hugetlbpage.c
5121+++ b/arch/metag/mm/hugetlbpage.c
5122@@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5123 info.high_limit = TASK_SIZE;
5124 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5125 info.align_offset = 0;
5126+ info.threadstack_offset = 0;
5127 return vm_unmapped_area(&info);
5128 }
5129
5130diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5131index 4efe96a..60e8699 100644
5132--- a/arch/microblaze/include/asm/cache.h
5133+++ b/arch/microblaze/include/asm/cache.h
5134@@ -13,11 +13,12 @@
5135 #ifndef _ASM_MICROBLAZE_CACHE_H
5136 #define _ASM_MICROBLAZE_CACHE_H
5137
5138+#include <linux/const.h>
5139 #include <asm/registers.h>
5140
5141 #define L1_CACHE_SHIFT 5
5142 /* word-granular cache in microblaze */
5143-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5144+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5145
5146 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5147
5148diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5149index 08b6079..eb272cf 100644
5150--- a/arch/mips/include/asm/atomic.h
5151+++ b/arch/mips/include/asm/atomic.h
5152@@ -21,6 +21,10 @@
5153 #include <asm/cmpxchg.h>
5154 #include <asm/war.h>
5155
5156+#ifdef CONFIG_GENERIC_ATOMIC64
5157+#include <asm-generic/atomic64.h>
5158+#endif
5159+
5160 #define ATOMIC_INIT(i) { (i) }
5161
5162 /*
5163@@ -759,6 +763,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5164 */
5165 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
5166
5167+#define atomic64_read_unchecked(v) atomic64_read(v)
5168+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5169+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5170+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5171+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5172+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5173+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5174+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5175+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5176+
5177 #endif /* CONFIG_64BIT */
5178
5179 /*
5180diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
5181index b4db69f..8f3b093 100644
5182--- a/arch/mips/include/asm/cache.h
5183+++ b/arch/mips/include/asm/cache.h
5184@@ -9,10 +9,11 @@
5185 #ifndef _ASM_CACHE_H
5186 #define _ASM_CACHE_H
5187
5188+#include <linux/const.h>
5189 #include <kmalloc.h>
5190
5191 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
5192-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5193+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5194
5195 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5196 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5197diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
5198index cf3ae24..238d22f 100644
5199--- a/arch/mips/include/asm/elf.h
5200+++ b/arch/mips/include/asm/elf.h
5201@@ -372,13 +372,16 @@ extern const char *__elf_platform;
5202 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
5203 #endif
5204
5205+#ifdef CONFIG_PAX_ASLR
5206+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5207+
5208+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5209+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5210+#endif
5211+
5212 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
5213 struct linux_binprm;
5214 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
5215 int uses_interp);
5216
5217-struct mm_struct;
5218-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
5219-#define arch_randomize_brk arch_randomize_brk
5220-
5221 #endif /* _ASM_ELF_H */
5222diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
5223index c1f6afa..38cc6e9 100644
5224--- a/arch/mips/include/asm/exec.h
5225+++ b/arch/mips/include/asm/exec.h
5226@@ -12,6 +12,6 @@
5227 #ifndef _ASM_EXEC_H
5228 #define _ASM_EXEC_H
5229
5230-extern unsigned long arch_align_stack(unsigned long sp);
5231+#define arch_align_stack(x) ((x) & ~0xfUL)
5232
5233 #endif /* _ASM_EXEC_H */
5234diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
5235index eab99e5..607c98e 100644
5236--- a/arch/mips/include/asm/page.h
5237+++ b/arch/mips/include/asm/page.h
5238@@ -96,7 +96,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
5239 #ifdef CONFIG_CPU_MIPS32
5240 typedef struct { unsigned long pte_low, pte_high; } pte_t;
5241 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
5242- #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
5243+ #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
5244 #else
5245 typedef struct { unsigned long long pte; } pte_t;
5246 #define pte_val(x) ((x).pte)
5247diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
5248index 881d18b..cea38bc 100644
5249--- a/arch/mips/include/asm/pgalloc.h
5250+++ b/arch/mips/include/asm/pgalloc.h
5251@@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5252 {
5253 set_pud(pud, __pud((unsigned long)pmd));
5254 }
5255+
5256+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
5257+{
5258+ pud_populate(mm, pud, pmd);
5259+}
5260 #endif
5261
5262 /*
5263diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
5264index 178f792..8ebc510 100644
5265--- a/arch/mips/include/asm/thread_info.h
5266+++ b/arch/mips/include/asm/thread_info.h
5267@@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
5268 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
5269 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
5270 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
5271+/* li takes a 32bit immediate */
5272+#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
5273 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
5274
5275 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
5276@@ -126,15 +128,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
5277 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
5278 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
5279 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
5280+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5281+
5282+#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5283
5284 /* work to do in syscall_trace_leave() */
5285-#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
5286+#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
5287
5288 /* work to do on interrupt/exception return */
5289 #define _TIF_WORK_MASK \
5290 (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_NOTIFY_RESUME)
5291 /* work to do on any return to u-space */
5292-#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT)
5293+#define _TIF_ALLWORK_MASK (_TIF_WORK_MASK | _TIF_WORK_SYSCALL_EXIT | _TIF_GRSEC_SETXID)
5294
5295 #endif /* __KERNEL__ */
5296
5297diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
5298index e06f777..3244284 100644
5299--- a/arch/mips/kernel/binfmt_elfn32.c
5300+++ b/arch/mips/kernel/binfmt_elfn32.c
5301@@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5302 #undef ELF_ET_DYN_BASE
5303 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5304
5305+#ifdef CONFIG_PAX_ASLR
5306+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5307+
5308+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5309+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5310+#endif
5311+
5312 #include <asm/processor.h>
5313 #include <linux/module.h>
5314 #include <linux/elfcore.h>
5315diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
5316index 556a435..b4fd2e3 100644
5317--- a/arch/mips/kernel/binfmt_elfo32.c
5318+++ b/arch/mips/kernel/binfmt_elfo32.c
5319@@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
5320 #undef ELF_ET_DYN_BASE
5321 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
5322
5323+#ifdef CONFIG_PAX_ASLR
5324+#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
5325+
5326+#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5327+#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
5328+#endif
5329+
5330 #include <asm/processor.h>
5331
5332 /*
5333diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
5334index 3be4405..a799827 100644
5335--- a/arch/mips/kernel/process.c
5336+++ b/arch/mips/kernel/process.c
5337@@ -461,15 +461,3 @@ unsigned long get_wchan(struct task_struct *task)
5338 out:
5339 return pc;
5340 }
5341-
5342-/*
5343- * Don't forget that the stack pointer must be aligned on a 8 bytes
5344- * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
5345- */
5346-unsigned long arch_align_stack(unsigned long sp)
5347-{
5348- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
5349- sp -= get_random_int() & ~PAGE_MASK;
5350-
5351- return sp & ALMASK;
5352-}
5353diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
5354index 9c6299c..2fb4c22 100644
5355--- a/arch/mips/kernel/ptrace.c
5356+++ b/arch/mips/kernel/ptrace.c
5357@@ -528,6 +528,10 @@ static inline int audit_arch(void)
5358 return arch;
5359 }
5360
5361+#ifdef CONFIG_GRKERNSEC_SETXID
5362+extern void gr_delayed_cred_worker(void);
5363+#endif
5364+
5365 /*
5366 * Notification of system call entry/exit
5367 * - triggered by current->work.syscall_trace
5368@@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
5369 /* do the secure computing check first */
5370 secure_computing_strict(regs->regs[2]);
5371
5372+#ifdef CONFIG_GRKERNSEC_SETXID
5373+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5374+ gr_delayed_cred_worker();
5375+#endif
5376+
5377 if (!(current->ptrace & PT_PTRACED))
5378 goto out;
5379
5380diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
5381index 9ea2964..c4329c3 100644
5382--- a/arch/mips/kernel/scall32-o32.S
5383+++ b/arch/mips/kernel/scall32-o32.S
5384@@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5385
5386 stack_done:
5387 lw t0, TI_FLAGS($28) # syscall tracing enabled?
5388- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5389+ li t1, _TIF_SYSCALL_WORK
5390 and t0, t1
5391 bnez t0, syscall_trace_entry # -> yes
5392
5393diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
5394index 36cfd40..b1436e0 100644
5395--- a/arch/mips/kernel/scall64-64.S
5396+++ b/arch/mips/kernel/scall64-64.S
5397@@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
5398
5399 sd a3, PT_R26(sp) # save a3 for syscall restarting
5400
5401- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5402+ li t1, _TIF_SYSCALL_WORK
5403 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5404 and t0, t1, t0
5405 bnez t0, syscall_trace_entry
5406diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
5407index 693d60b..ae0ba75 100644
5408--- a/arch/mips/kernel/scall64-n32.S
5409+++ b/arch/mips/kernel/scall64-n32.S
5410@@ -47,7 +47,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
5411
5412 sd a3, PT_R26(sp) # save a3 for syscall restarting
5413
5414- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5415+ li t1, _TIF_SYSCALL_WORK
5416 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5417 and t0, t1, t0
5418 bnez t0, n32_syscall_trace_entry
5419diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
5420index af8887f..611ccb6 100644
5421--- a/arch/mips/kernel/scall64-o32.S
5422+++ b/arch/mips/kernel/scall64-o32.S
5423@@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
5424 PTR 4b, bad_stack
5425 .previous
5426
5427- li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
5428+ li t1, _TIF_SYSCALL_WORK
5429 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
5430 and t0, t1, t0
5431 bnez t0, trace_a_syscall
5432diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
5433index 0fead53..a2c0fb5 100644
5434--- a/arch/mips/mm/fault.c
5435+++ b/arch/mips/mm/fault.c
5436@@ -27,6 +27,23 @@
5437 #include <asm/highmem.h> /* For VMALLOC_END */
5438 #include <linux/kdebug.h>
5439
5440+#ifdef CONFIG_PAX_PAGEEXEC
5441+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5442+{
5443+ unsigned long i;
5444+
5445+ printk(KERN_ERR "PAX: bytes at PC: ");
5446+ for (i = 0; i < 5; i++) {
5447+ unsigned int c;
5448+ if (get_user(c, (unsigned int *)pc+i))
5449+ printk(KERN_CONT "???????? ");
5450+ else
5451+ printk(KERN_CONT "%08x ", c);
5452+ }
5453+ printk("\n");
5454+}
5455+#endif
5456+
5457 /*
5458 * This routine handles page faults. It determines the address,
5459 * and the problem, and then passes it off to one of the appropriate
5460diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
5461index 7e5fe27..9656513 100644
5462--- a/arch/mips/mm/mmap.c
5463+++ b/arch/mips/mm/mmap.c
5464@@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5465 struct vm_area_struct *vma;
5466 unsigned long addr = addr0;
5467 int do_color_align;
5468+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5469 struct vm_unmapped_area_info info;
5470
5471 if (unlikely(len > TASK_SIZE))
5472@@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5473 do_color_align = 1;
5474
5475 /* requesting a specific address */
5476+
5477+#ifdef CONFIG_PAX_RANDMMAP
5478+ if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
5479+#endif
5480+
5481 if (addr) {
5482 if (do_color_align)
5483 addr = COLOUR_ALIGN(addr, pgoff);
5484@@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
5485 addr = PAGE_ALIGN(addr);
5486
5487 vma = find_vma(mm, addr);
5488- if (TASK_SIZE - len >= addr &&
5489- (!vma || addr + len <= vma->vm_start))
5490+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
5491 return addr;
5492 }
5493
5494 info.length = len;
5495 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
5496 info.align_offset = pgoff << PAGE_SHIFT;
5497+ info.threadstack_offset = offset;
5498
5499 if (dir == DOWN) {
5500 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
5501@@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5502 {
5503 unsigned long random_factor = 0UL;
5504
5505+#ifdef CONFIG_PAX_RANDMMAP
5506+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5507+#endif
5508+
5509 if (current->flags & PF_RANDOMIZE) {
5510 random_factor = get_random_int();
5511 random_factor = random_factor << PAGE_SHIFT;
5512@@ -157,42 +167,27 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5513
5514 if (mmap_is_legacy()) {
5515 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5516+
5517+#ifdef CONFIG_PAX_RANDMMAP
5518+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5519+ mm->mmap_base += mm->delta_mmap;
5520+#endif
5521+
5522 mm->get_unmapped_area = arch_get_unmapped_area;
5523 mm->unmap_area = arch_unmap_area;
5524 } else {
5525 mm->mmap_base = mmap_base(random_factor);
5526+
5527+#ifdef CONFIG_PAX_RANDMMAP
5528+ if (mm->pax_flags & MF_PAX_RANDMMAP)
5529+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
5530+#endif
5531+
5532 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
5533 mm->unmap_area = arch_unmap_area_topdown;
5534 }
5535 }
5536
5537-static inline unsigned long brk_rnd(void)
5538-{
5539- unsigned long rnd = get_random_int();
5540-
5541- rnd = rnd << PAGE_SHIFT;
5542- /* 8MB for 32bit, 256MB for 64bit */
5543- if (TASK_IS_32BIT_ADDR)
5544- rnd = rnd & 0x7ffffful;
5545- else
5546- rnd = rnd & 0xffffffful;
5547-
5548- return rnd;
5549-}
5550-
5551-unsigned long arch_randomize_brk(struct mm_struct *mm)
5552-{
5553- unsigned long base = mm->brk;
5554- unsigned long ret;
5555-
5556- ret = PAGE_ALIGN(base + brk_rnd());
5557-
5558- if (ret < mm->brk)
5559- return mm->brk;
5560-
5561- return ret;
5562-}
5563-
5564 int __virt_addr_valid(const volatile void *kaddr)
5565 {
5566 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
5567diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5568index 967d144..db12197 100644
5569--- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
5570+++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
5571@@ -11,12 +11,14 @@
5572 #ifndef _ASM_PROC_CACHE_H
5573 #define _ASM_PROC_CACHE_H
5574
5575+#include <linux/const.h>
5576+
5577 /* L1 cache */
5578
5579 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5580 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
5581-#define L1_CACHE_BYTES 16 /* bytes per entry */
5582 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
5583+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5584 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
5585
5586 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5587diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5588index bcb5df2..84fabd2 100644
5589--- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5590+++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
5591@@ -16,13 +16,15 @@
5592 #ifndef _ASM_PROC_CACHE_H
5593 #define _ASM_PROC_CACHE_H
5594
5595+#include <linux/const.h>
5596+
5597 /*
5598 * L1 cache
5599 */
5600 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
5601 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
5602-#define L1_CACHE_BYTES 32 /* bytes per entry */
5603 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
5604+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
5605 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
5606
5607 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
5608diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
5609index 4ce7a01..449202a 100644
5610--- a/arch/openrisc/include/asm/cache.h
5611+++ b/arch/openrisc/include/asm/cache.h
5612@@ -19,11 +19,13 @@
5613 #ifndef __ASM_OPENRISC_CACHE_H
5614 #define __ASM_OPENRISC_CACHE_H
5615
5616+#include <linux/const.h>
5617+
5618 /* FIXME: How can we replace these with values from the CPU...
5619 * they shouldn't be hard-coded!
5620 */
5621
5622-#define L1_CACHE_BYTES 16
5623 #define L1_CACHE_SHIFT 4
5624+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5625
5626 #endif /* __ASM_OPENRISC_CACHE_H */
5627diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
5628index f38e198..4179e38 100644
5629--- a/arch/parisc/include/asm/atomic.h
5630+++ b/arch/parisc/include/asm/atomic.h
5631@@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
5632
5633 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5634
5635+#define atomic64_read_unchecked(v) atomic64_read(v)
5636+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5637+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5638+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5639+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5640+#define atomic64_inc_unchecked(v) atomic64_inc(v)
5641+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5642+#define atomic64_dec_unchecked(v) atomic64_dec(v)
5643+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5644+
5645 #endif /* !CONFIG_64BIT */
5646
5647
5648diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
5649index 47f11c7..3420df2 100644
5650--- a/arch/parisc/include/asm/cache.h
5651+++ b/arch/parisc/include/asm/cache.h
5652@@ -5,6 +5,7 @@
5653 #ifndef __ARCH_PARISC_CACHE_H
5654 #define __ARCH_PARISC_CACHE_H
5655
5656+#include <linux/const.h>
5657
5658 /*
5659 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
5660@@ -15,13 +16,13 @@
5661 * just ruin performance.
5662 */
5663 #ifdef CONFIG_PA20
5664-#define L1_CACHE_BYTES 64
5665 #define L1_CACHE_SHIFT 6
5666 #else
5667-#define L1_CACHE_BYTES 32
5668 #define L1_CACHE_SHIFT 5
5669 #endif
5670
5671+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5672+
5673 #ifndef __ASSEMBLY__
5674
5675 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5676diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
5677index ad2b503..bdf1651 100644
5678--- a/arch/parisc/include/asm/elf.h
5679+++ b/arch/parisc/include/asm/elf.h
5680@@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
5681
5682 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
5683
5684+#ifdef CONFIG_PAX_ASLR
5685+#define PAX_ELF_ET_DYN_BASE 0x10000UL
5686+
5687+#define PAX_DELTA_MMAP_LEN 16
5688+#define PAX_DELTA_STACK_LEN 16
5689+#endif
5690+
5691 /* This yields a mask that user programs can use to figure out what
5692 instruction set this CPU supports. This could be done in user space,
5693 but it's not easy, and we've already done it here. */
5694diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
5695index fc987a1..6e068ef 100644
5696--- a/arch/parisc/include/asm/pgalloc.h
5697+++ b/arch/parisc/include/asm/pgalloc.h
5698@@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5699 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
5700 }
5701
5702+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
5703+{
5704+ pgd_populate(mm, pgd, pmd);
5705+}
5706+
5707 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
5708 {
5709 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
5710@@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
5711 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
5712 #define pmd_free(mm, x) do { } while (0)
5713 #define pgd_populate(mm, pmd, pte) BUG()
5714+#define pgd_populate_kernel(mm, pmd, pte) BUG()
5715
5716 #endif
5717
5718diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
5719index 1e40d7f..a3eb445 100644
5720--- a/arch/parisc/include/asm/pgtable.h
5721+++ b/arch/parisc/include/asm/pgtable.h
5722@@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
5723 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
5724 #define PAGE_COPY PAGE_EXECREAD
5725 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
5726+
5727+#ifdef CONFIG_PAX_PAGEEXEC
5728+# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
5729+# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5730+# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
5731+#else
5732+# define PAGE_SHARED_NOEXEC PAGE_SHARED
5733+# define PAGE_COPY_NOEXEC PAGE_COPY
5734+# define PAGE_READONLY_NOEXEC PAGE_READONLY
5735+#endif
5736+
5737 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
5738 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
5739 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
5740diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
5741index e0a8235..ce2f1e1 100644
5742--- a/arch/parisc/include/asm/uaccess.h
5743+++ b/arch/parisc/include/asm/uaccess.h
5744@@ -245,10 +245,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
5745 const void __user *from,
5746 unsigned long n)
5747 {
5748- int sz = __compiletime_object_size(to);
5749+ size_t sz = __compiletime_object_size(to);
5750 int ret = -EFAULT;
5751
5752- if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
5753+ if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
5754 ret = __copy_from_user(to, from, n);
5755 else
5756 copy_from_user_overflow();
5757diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
5758index 2a625fb..9908930 100644
5759--- a/arch/parisc/kernel/module.c
5760+++ b/arch/parisc/kernel/module.c
5761@@ -98,16 +98,38 @@
5762
5763 /* three functions to determine where in the module core
5764 * or init pieces the location is */
5765+static inline int in_init_rx(struct module *me, void *loc)
5766+{
5767+ return (loc >= me->module_init_rx &&
5768+ loc < (me->module_init_rx + me->init_size_rx));
5769+}
5770+
5771+static inline int in_init_rw(struct module *me, void *loc)
5772+{
5773+ return (loc >= me->module_init_rw &&
5774+ loc < (me->module_init_rw + me->init_size_rw));
5775+}
5776+
5777 static inline int in_init(struct module *me, void *loc)
5778 {
5779- return (loc >= me->module_init &&
5780- loc <= (me->module_init + me->init_size));
5781+ return in_init_rx(me, loc) || in_init_rw(me, loc);
5782+}
5783+
5784+static inline int in_core_rx(struct module *me, void *loc)
5785+{
5786+ return (loc >= me->module_core_rx &&
5787+ loc < (me->module_core_rx + me->core_size_rx));
5788+}
5789+
5790+static inline int in_core_rw(struct module *me, void *loc)
5791+{
5792+ return (loc >= me->module_core_rw &&
5793+ loc < (me->module_core_rw + me->core_size_rw));
5794 }
5795
5796 static inline int in_core(struct module *me, void *loc)
5797 {
5798- return (loc >= me->module_core &&
5799- loc <= (me->module_core + me->core_size));
5800+ return in_core_rx(me, loc) || in_core_rw(me, loc);
5801 }
5802
5803 static inline int in_local(struct module *me, void *loc)
5804@@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
5805 }
5806
5807 /* align things a bit */
5808- me->core_size = ALIGN(me->core_size, 16);
5809- me->arch.got_offset = me->core_size;
5810- me->core_size += gots * sizeof(struct got_entry);
5811+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5812+ me->arch.got_offset = me->core_size_rw;
5813+ me->core_size_rw += gots * sizeof(struct got_entry);
5814
5815- me->core_size = ALIGN(me->core_size, 16);
5816- me->arch.fdesc_offset = me->core_size;
5817- me->core_size += fdescs * sizeof(Elf_Fdesc);
5818+ me->core_size_rw = ALIGN(me->core_size_rw, 16);
5819+ me->arch.fdesc_offset = me->core_size_rw;
5820+ me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
5821
5822 me->arch.got_max = gots;
5823 me->arch.fdesc_max = fdescs;
5824@@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5825
5826 BUG_ON(value == 0);
5827
5828- got = me->module_core + me->arch.got_offset;
5829+ got = me->module_core_rw + me->arch.got_offset;
5830 for (i = 0; got[i].addr; i++)
5831 if (got[i].addr == value)
5832 goto out;
5833@@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
5834 #ifdef CONFIG_64BIT
5835 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5836 {
5837- Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
5838+ Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
5839
5840 if (!value) {
5841 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
5842@@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
5843
5844 /* Create new one */
5845 fdesc->addr = value;
5846- fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5847+ fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5848 return (Elf_Addr)fdesc;
5849 }
5850 #endif /* CONFIG_64BIT */
5851@@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
5852
5853 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
5854 end = table + sechdrs[me->arch.unwind_section].sh_size;
5855- gp = (Elf_Addr)me->module_core + me->arch.got_offset;
5856+ gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
5857
5858 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
5859 me->arch.unwind_section, table, end, gp);
5860diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
5861index 5dfd248..64914ac 100644
5862--- a/arch/parisc/kernel/sys_parisc.c
5863+++ b/arch/parisc/kernel/sys_parisc.c
5864@@ -33,9 +33,11 @@
5865 #include <linux/utsname.h>
5866 #include <linux/personality.h>
5867
5868-static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5869+static unsigned long get_unshared_area(struct file *filp, unsigned long addr, unsigned long len,
5870+ unsigned long flags)
5871 {
5872 struct vm_unmapped_area_info info;
5873+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5874
5875 info.flags = 0;
5876 info.length = len;
5877@@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
5878 info.high_limit = TASK_SIZE;
5879 info.align_mask = 0;
5880 info.align_offset = 0;
5881+ info.threadstack_offset = offset;
5882 return vm_unmapped_area(&info);
5883 }
5884
5885@@ -61,10 +64,11 @@ static int get_offset(struct address_space *mapping)
5886 return (unsigned long) mapping >> 8;
5887 }
5888
5889-static unsigned long get_shared_area(struct address_space *mapping,
5890- unsigned long addr, unsigned long len, unsigned long pgoff)
5891+static unsigned long get_shared_area(struct file *filp, struct address_space *mapping,
5892+ unsigned long addr, unsigned long len, unsigned long pgoff, unsigned long flags)
5893 {
5894 struct vm_unmapped_area_info info;
5895+ unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5896
5897 info.flags = 0;
5898 info.length = len;
5899@@ -72,6 +76,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
5900 info.high_limit = TASK_SIZE;
5901 info.align_mask = PAGE_MASK & (SHMLBA - 1);
5902 info.align_offset = (get_offset(mapping) + pgoff) << PAGE_SHIFT;
5903+ info.threadstack_offset = offset;
5904 return vm_unmapped_area(&info);
5905 }
5906
5907@@ -86,15 +91,22 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5908 return -EINVAL;
5909 return addr;
5910 }
5911- if (!addr)
5912+ if (!addr) {
5913 addr = TASK_UNMAPPED_BASE;
5914
5915+#ifdef CONFIG_PAX_RANDMMAP
5916+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
5917+ addr += current->mm->delta_mmap;
5918+#endif
5919+
5920+ }
5921+
5922 if (filp) {
5923- addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
5924+ addr = get_shared_area(filp, filp->f_mapping, addr, len, pgoff, flags);
5925 } else if(flags & MAP_SHARED) {
5926- addr = get_shared_area(NULL, addr, len, pgoff);
5927+ addr = get_shared_area(filp, NULL, addr, len, pgoff, flags);
5928 } else {
5929- addr = get_unshared_area(addr, len);
5930+ addr = get_unshared_area(filp, addr, len, flags);
5931 }
5932 return addr;
5933 }
5934diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
5935index c6ae9f5..e9c3cf4 100644
5936--- a/arch/parisc/kernel/traps.c
5937+++ b/arch/parisc/kernel/traps.c
5938@@ -733,9 +733,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
5939
5940 down_read(&current->mm->mmap_sem);
5941 vma = find_vma(current->mm,regs->iaoq[0]);
5942- if (vma && (regs->iaoq[0] >= vma->vm_start)
5943- && (vma->vm_flags & VM_EXEC)) {
5944-
5945+ if (vma && (regs->iaoq[0] >= vma->vm_start)) {
5946 fault_address = regs->iaoq[0];
5947 fault_space = regs->iasq[0];
5948
5949diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
5950index f247a34..dc0f219 100644
5951--- a/arch/parisc/mm/fault.c
5952+++ b/arch/parisc/mm/fault.c
5953@@ -15,6 +15,7 @@
5954 #include <linux/sched.h>
5955 #include <linux/interrupt.h>
5956 #include <linux/module.h>
5957+#include <linux/unistd.h>
5958
5959 #include <asm/uaccess.h>
5960 #include <asm/traps.h>
5961@@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
5962 static unsigned long
5963 parisc_acctyp(unsigned long code, unsigned int inst)
5964 {
5965- if (code == 6 || code == 16)
5966+ if (code == 6 || code == 7 || code == 16)
5967 return VM_EXEC;
5968
5969 switch (inst & 0xf0000000) {
5970@@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
5971 }
5972 #endif
5973
5974+#ifdef CONFIG_PAX_PAGEEXEC
5975+/*
5976+ * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
5977+ *
5978+ * returns 1 when task should be killed
5979+ * 2 when rt_sigreturn trampoline was detected
5980+ * 3 when unpatched PLT trampoline was detected
5981+ */
5982+static int pax_handle_fetch_fault(struct pt_regs *regs)
5983+{
5984+
5985+#ifdef CONFIG_PAX_EMUPLT
5986+ int err;
5987+
5988+ do { /* PaX: unpatched PLT emulation */
5989+ unsigned int bl, depwi;
5990+
5991+ err = get_user(bl, (unsigned int *)instruction_pointer(regs));
5992+ err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
5993+
5994+ if (err)
5995+ break;
5996+
5997+ if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
5998+ unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
5999+
6000+ err = get_user(ldw, (unsigned int *)addr);
6001+ err |= get_user(bv, (unsigned int *)(addr+4));
6002+ err |= get_user(ldw2, (unsigned int *)(addr+8));
6003+
6004+ if (err)
6005+ break;
6006+
6007+ if (ldw == 0x0E801096U &&
6008+ bv == 0xEAC0C000U &&
6009+ ldw2 == 0x0E881095U)
6010+ {
6011+ unsigned int resolver, map;
6012+
6013+ err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
6014+ err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
6015+ if (err)
6016+ break;
6017+
6018+ regs->gr[20] = instruction_pointer(regs)+8;
6019+ regs->gr[21] = map;
6020+ regs->gr[22] = resolver;
6021+ regs->iaoq[0] = resolver | 3UL;
6022+ regs->iaoq[1] = regs->iaoq[0] + 4;
6023+ return 3;
6024+ }
6025+ }
6026+ } while (0);
6027+#endif
6028+
6029+#ifdef CONFIG_PAX_EMUTRAMP
6030+
6031+#ifndef CONFIG_PAX_EMUSIGRT
6032+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
6033+ return 1;
6034+#endif
6035+
6036+ do { /* PaX: rt_sigreturn emulation */
6037+ unsigned int ldi1, ldi2, bel, nop;
6038+
6039+ err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
6040+ err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
6041+ err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
6042+ err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
6043+
6044+ if (err)
6045+ break;
6046+
6047+ if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
6048+ ldi2 == 0x3414015AU &&
6049+ bel == 0xE4008200U &&
6050+ nop == 0x08000240U)
6051+ {
6052+ regs->gr[25] = (ldi1 & 2) >> 1;
6053+ regs->gr[20] = __NR_rt_sigreturn;
6054+ regs->gr[31] = regs->iaoq[1] + 16;
6055+ regs->sr[0] = regs->iasq[1];
6056+ regs->iaoq[0] = 0x100UL;
6057+ regs->iaoq[1] = regs->iaoq[0] + 4;
6058+ regs->iasq[0] = regs->sr[2];
6059+ regs->iasq[1] = regs->sr[2];
6060+ return 2;
6061+ }
6062+ } while (0);
6063+#endif
6064+
6065+ return 1;
6066+}
6067+
6068+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6069+{
6070+ unsigned long i;
6071+
6072+ printk(KERN_ERR "PAX: bytes at PC: ");
6073+ for (i = 0; i < 5; i++) {
6074+ unsigned int c;
6075+ if (get_user(c, (unsigned int *)pc+i))
6076+ printk(KERN_CONT "???????? ");
6077+ else
6078+ printk(KERN_CONT "%08x ", c);
6079+ }
6080+ printk("\n");
6081+}
6082+#endif
6083+
6084 int fixup_exception(struct pt_regs *regs)
6085 {
6086 const struct exception_table_entry *fix;
6087@@ -194,8 +305,33 @@ good_area:
6088
6089 acc_type = parisc_acctyp(code,regs->iir);
6090
6091- if ((vma->vm_flags & acc_type) != acc_type)
6092+ if ((vma->vm_flags & acc_type) != acc_type) {
6093+
6094+#ifdef CONFIG_PAX_PAGEEXEC
6095+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
6096+ (address & ~3UL) == instruction_pointer(regs))
6097+ {
6098+ up_read(&mm->mmap_sem);
6099+ switch (pax_handle_fetch_fault(regs)) {
6100+
6101+#ifdef CONFIG_PAX_EMUPLT
6102+ case 3:
6103+ return;
6104+#endif
6105+
6106+#ifdef CONFIG_PAX_EMUTRAMP
6107+ case 2:
6108+ return;
6109+#endif
6110+
6111+ }
6112+ pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
6113+ do_group_exit(SIGKILL);
6114+ }
6115+#endif
6116+
6117 goto bad_area;
6118+ }
6119
6120 /*
6121 * If for any reason at all we couldn't handle the fault, make
6122diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
6123index e3b1d41..8e81edf 100644
6124--- a/arch/powerpc/include/asm/atomic.h
6125+++ b/arch/powerpc/include/asm/atomic.h
6126@@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
6127 return t1;
6128 }
6129
6130+#define atomic64_read_unchecked(v) atomic64_read(v)
6131+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
6132+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
6133+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
6134+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
6135+#define atomic64_inc_unchecked(v) atomic64_inc(v)
6136+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
6137+#define atomic64_dec_unchecked(v) atomic64_dec(v)
6138+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
6139+
6140 #endif /* __powerpc64__ */
6141
6142 #endif /* __KERNEL__ */
6143diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
6144index 9e495c9..b6878e5 100644
6145--- a/arch/powerpc/include/asm/cache.h
6146+++ b/arch/powerpc/include/asm/cache.h
6147@@ -3,6 +3,7 @@
6148
6149 #ifdef __KERNEL__
6150
6151+#include <linux/const.h>
6152
6153 /* bytes per L1 cache line */
6154 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
6155@@ -22,7 +23,7 @@
6156 #define L1_CACHE_SHIFT 7
6157 #endif
6158
6159-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6160+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6161
6162 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6163
6164diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
6165index ac9790f..6d30741 100644
6166--- a/arch/powerpc/include/asm/elf.h
6167+++ b/arch/powerpc/include/asm/elf.h
6168@@ -28,8 +28,19 @@
6169 the loader. We need to make sure that it is out of the way of the program
6170 that it will "exec", and that there is sufficient room for the brk. */
6171
6172-extern unsigned long randomize_et_dyn(unsigned long base);
6173-#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
6174+#define ELF_ET_DYN_BASE (0x20000000)
6175+
6176+#ifdef CONFIG_PAX_ASLR
6177+#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
6178+
6179+#ifdef __powerpc64__
6180+#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
6181+#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
6182+#else
6183+#define PAX_DELTA_MMAP_LEN 15
6184+#define PAX_DELTA_STACK_LEN 15
6185+#endif
6186+#endif
6187
6188 /*
6189 * Our registers are always unsigned longs, whether we're a 32 bit
6190@@ -122,10 +133,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6191 (0x7ff >> (PAGE_SHIFT - 12)) : \
6192 (0x3ffff >> (PAGE_SHIFT - 12)))
6193
6194-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6195-#define arch_randomize_brk arch_randomize_brk
6196-
6197-
6198 #ifdef CONFIG_SPU_BASE
6199 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
6200 #define NT_SPU 1
6201diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
6202index 8196e9c..d83a9f3 100644
6203--- a/arch/powerpc/include/asm/exec.h
6204+++ b/arch/powerpc/include/asm/exec.h
6205@@ -4,6 +4,6 @@
6206 #ifndef _ASM_POWERPC_EXEC_H
6207 #define _ASM_POWERPC_EXEC_H
6208
6209-extern unsigned long arch_align_stack(unsigned long sp);
6210+#define arch_align_stack(x) ((x) & ~0xfUL)
6211
6212 #endif /* _ASM_POWERPC_EXEC_H */
6213diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
6214index 5acabbd..7ea14fa 100644
6215--- a/arch/powerpc/include/asm/kmap_types.h
6216+++ b/arch/powerpc/include/asm/kmap_types.h
6217@@ -10,7 +10,7 @@
6218 * 2 of the License, or (at your option) any later version.
6219 */
6220
6221-#define KM_TYPE_NR 16
6222+#define KM_TYPE_NR 17
6223
6224 #endif /* __KERNEL__ */
6225 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
6226diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
6227index 8565c25..2865190 100644
6228--- a/arch/powerpc/include/asm/mman.h
6229+++ b/arch/powerpc/include/asm/mman.h
6230@@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
6231 }
6232 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
6233
6234-static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
6235+static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
6236 {
6237 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
6238 }
6239diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
6240index f072e97..b436dee 100644
6241--- a/arch/powerpc/include/asm/page.h
6242+++ b/arch/powerpc/include/asm/page.h
6243@@ -220,8 +220,9 @@ extern long long virt_phys_offset;
6244 * and needs to be executable. This means the whole heap ends
6245 * up being executable.
6246 */
6247-#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6248- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6249+#define VM_DATA_DEFAULT_FLAGS32 \
6250+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6251+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6252
6253 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6254 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6255@@ -249,6 +250,9 @@ extern long long virt_phys_offset;
6256 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
6257 #endif
6258
6259+#define ktla_ktva(addr) (addr)
6260+#define ktva_ktla(addr) (addr)
6261+
6262 /*
6263 * Use the top bit of the higher-level page table entries to indicate whether
6264 * the entries we point to contain hugepages. This works because we know that
6265diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
6266index cd915d6..c10cee8 100644
6267--- a/arch/powerpc/include/asm/page_64.h
6268+++ b/arch/powerpc/include/asm/page_64.h
6269@@ -154,15 +154,18 @@ do { \
6270 * stack by default, so in the absence of a PT_GNU_STACK program header
6271 * we turn execute permission off.
6272 */
6273-#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
6274- VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6275+#define VM_STACK_DEFAULT_FLAGS32 \
6276+ (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
6277+ VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6278
6279 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
6280 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
6281
6282+#ifndef CONFIG_PAX_PAGEEXEC
6283 #define VM_STACK_DEFAULT_FLAGS \
6284 (is_32bit_task() ? \
6285 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
6286+#endif
6287
6288 #include <asm-generic/getorder.h>
6289
6290diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
6291index 292725c..f87ae14 100644
6292--- a/arch/powerpc/include/asm/pgalloc-64.h
6293+++ b/arch/powerpc/include/asm/pgalloc-64.h
6294@@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
6295 #ifndef CONFIG_PPC_64K_PAGES
6296
6297 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
6298+#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
6299
6300 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
6301 {
6302@@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6303 pud_set(pud, (unsigned long)pmd);
6304 }
6305
6306+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6307+{
6308+ pud_populate(mm, pud, pmd);
6309+}
6310+
6311 #define pmd_populate(mm, pmd, pte_page) \
6312 pmd_populate_kernel(mm, pmd, page_address(pte_page))
6313 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
6314@@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6315 #else /* CONFIG_PPC_64K_PAGES */
6316
6317 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
6318+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
6319
6320 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
6321 pte_t *pte)
6322diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
6323index a9cbd3b..3b67efa 100644
6324--- a/arch/powerpc/include/asm/pgtable.h
6325+++ b/arch/powerpc/include/asm/pgtable.h
6326@@ -2,6 +2,7 @@
6327 #define _ASM_POWERPC_PGTABLE_H
6328 #ifdef __KERNEL__
6329
6330+#include <linux/const.h>
6331 #ifndef __ASSEMBLY__
6332 #include <asm/processor.h> /* For TASK_SIZE */
6333 #include <asm/mmu.h>
6334diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
6335index 4aad413..85d86bf 100644
6336--- a/arch/powerpc/include/asm/pte-hash32.h
6337+++ b/arch/powerpc/include/asm/pte-hash32.h
6338@@ -21,6 +21,7 @@
6339 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
6340 #define _PAGE_USER 0x004 /* usermode access allowed */
6341 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
6342+#define _PAGE_EXEC _PAGE_GUARDED
6343 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
6344 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
6345 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
6346diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
6347index 3b097a8..8f8c774 100644
6348--- a/arch/powerpc/include/asm/reg.h
6349+++ b/arch/powerpc/include/asm/reg.h
6350@@ -234,6 +234,7 @@
6351 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
6352 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
6353 #define DSISR_NOHPTE 0x40000000 /* no translation found */
6354+#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
6355 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
6356 #define DSISR_ISSTORE 0x02000000 /* access was a store */
6357 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
6358diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
6359index 195ce2a..ab5c614 100644
6360--- a/arch/powerpc/include/asm/smp.h
6361+++ b/arch/powerpc/include/asm/smp.h
6362@@ -50,7 +50,7 @@ struct smp_ops_t {
6363 int (*cpu_disable)(void);
6364 void (*cpu_die)(unsigned int nr);
6365 int (*cpu_bootable)(unsigned int nr);
6366-};
6367+} __no_const;
6368
6369 extern void smp_send_debugger_break(void);
6370 extern void start_secondary_resume(void);
6371diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
6372index 406b7b9..af63426 100644
6373--- a/arch/powerpc/include/asm/thread_info.h
6374+++ b/arch/powerpc/include/asm/thread_info.h
6375@@ -97,7 +97,6 @@ static inline struct thread_info *current_thread_info(void)
6376 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
6377 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
6378 #define TIF_SINGLESTEP 8 /* singlestepping active */
6379-#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
6380 #define TIF_SECCOMP 10 /* secure computing */
6381 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
6382 #define TIF_NOERROR 12 /* Force successful syscall return */
6383@@ -106,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6384 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
6385 #define TIF_EMULATE_STACK_STORE 16 /* Is an instruction emulation
6386 for stack store? */
6387+#define TIF_MEMDIE 17 /* is terminating due to OOM killer */
6388+/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
6389+#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
6390
6391 /* as above, but as bit values */
6392 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6393@@ -124,8 +126,10 @@ static inline struct thread_info *current_thread_info(void)
6394 #define _TIF_UPROBE (1<<TIF_UPROBE)
6395 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6396 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
6397+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6398 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
6399- _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
6400+ _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
6401+ _TIF_GRSEC_SETXID)
6402
6403 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
6404 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
6405diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
6406index 4db4959..aba5c41 100644
6407--- a/arch/powerpc/include/asm/uaccess.h
6408+++ b/arch/powerpc/include/asm/uaccess.h
6409@@ -318,52 +318,6 @@ do { \
6410 extern unsigned long __copy_tofrom_user(void __user *to,
6411 const void __user *from, unsigned long size);
6412
6413-#ifndef __powerpc64__
6414-
6415-static inline unsigned long copy_from_user(void *to,
6416- const void __user *from, unsigned long n)
6417-{
6418- unsigned long over;
6419-
6420- if (access_ok(VERIFY_READ, from, n))
6421- return __copy_tofrom_user((__force void __user *)to, from, n);
6422- if ((unsigned long)from < TASK_SIZE) {
6423- over = (unsigned long)from + n - TASK_SIZE;
6424- return __copy_tofrom_user((__force void __user *)to, from,
6425- n - over) + over;
6426- }
6427- return n;
6428-}
6429-
6430-static inline unsigned long copy_to_user(void __user *to,
6431- const void *from, unsigned long n)
6432-{
6433- unsigned long over;
6434-
6435- if (access_ok(VERIFY_WRITE, to, n))
6436- return __copy_tofrom_user(to, (__force void __user *)from, n);
6437- if ((unsigned long)to < TASK_SIZE) {
6438- over = (unsigned long)to + n - TASK_SIZE;
6439- return __copy_tofrom_user(to, (__force void __user *)from,
6440- n - over) + over;
6441- }
6442- return n;
6443-}
6444-
6445-#else /* __powerpc64__ */
6446-
6447-#define __copy_in_user(to, from, size) \
6448- __copy_tofrom_user((to), (from), (size))
6449-
6450-extern unsigned long copy_from_user(void *to, const void __user *from,
6451- unsigned long n);
6452-extern unsigned long copy_to_user(void __user *to, const void *from,
6453- unsigned long n);
6454-extern unsigned long copy_in_user(void __user *to, const void __user *from,
6455- unsigned long n);
6456-
6457-#endif /* __powerpc64__ */
6458-
6459 static inline unsigned long __copy_from_user_inatomic(void *to,
6460 const void __user *from, unsigned long n)
6461 {
6462@@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
6463 if (ret == 0)
6464 return 0;
6465 }
6466+
6467+ if (!__builtin_constant_p(n))
6468+ check_object_size(to, n, false);
6469+
6470 return __copy_tofrom_user((__force void __user *)to, from, n);
6471 }
6472
6473@@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
6474 if (ret == 0)
6475 return 0;
6476 }
6477+
6478+ if (!__builtin_constant_p(n))
6479+ check_object_size(from, n, true);
6480+
6481 return __copy_tofrom_user(to, (__force const void __user *)from, n);
6482 }
6483
6484@@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
6485 return __copy_to_user_inatomic(to, from, size);
6486 }
6487
6488+#ifndef __powerpc64__
6489+
6490+static inline unsigned long __must_check copy_from_user(void *to,
6491+ const void __user *from, unsigned long n)
6492+{
6493+ unsigned long over;
6494+
6495+ if ((long)n < 0)
6496+ return n;
6497+
6498+ if (access_ok(VERIFY_READ, from, n)) {
6499+ if (!__builtin_constant_p(n))
6500+ check_object_size(to, n, false);
6501+ return __copy_tofrom_user((__force void __user *)to, from, n);
6502+ }
6503+ if ((unsigned long)from < TASK_SIZE) {
6504+ over = (unsigned long)from + n - TASK_SIZE;
6505+ if (!__builtin_constant_p(n - over))
6506+ check_object_size(to, n - over, false);
6507+ return __copy_tofrom_user((__force void __user *)to, from,
6508+ n - over) + over;
6509+ }
6510+ return n;
6511+}
6512+
6513+static inline unsigned long __must_check copy_to_user(void __user *to,
6514+ const void *from, unsigned long n)
6515+{
6516+ unsigned long over;
6517+
6518+ if ((long)n < 0)
6519+ return n;
6520+
6521+ if (access_ok(VERIFY_WRITE, to, n)) {
6522+ if (!__builtin_constant_p(n))
6523+ check_object_size(from, n, true);
6524+ return __copy_tofrom_user(to, (__force void __user *)from, n);
6525+ }
6526+ if ((unsigned long)to < TASK_SIZE) {
6527+ over = (unsigned long)to + n - TASK_SIZE;
6528+ if (!__builtin_constant_p(n))
6529+ check_object_size(from, n - over, true);
6530+ return __copy_tofrom_user(to, (__force void __user *)from,
6531+ n - over) + over;
6532+ }
6533+ return n;
6534+}
6535+
6536+#else /* __powerpc64__ */
6537+
6538+#define __copy_in_user(to, from, size) \
6539+ __copy_tofrom_user((to), (from), (size))
6540+
6541+static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
6542+{
6543+ if ((long)n < 0 || n > INT_MAX)
6544+ return n;
6545+
6546+ if (!__builtin_constant_p(n))
6547+ check_object_size(to, n, false);
6548+
6549+ if (likely(access_ok(VERIFY_READ, from, n)))
6550+ n = __copy_from_user(to, from, n);
6551+ else
6552+ memset(to, 0, n);
6553+ return n;
6554+}
6555+
6556+static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
6557+{
6558+ if ((long)n < 0 || n > INT_MAX)
6559+ return n;
6560+
6561+ if (likely(access_ok(VERIFY_WRITE, to, n))) {
6562+ if (!__builtin_constant_p(n))
6563+ check_object_size(from, n, true);
6564+ n = __copy_to_user(to, from, n);
6565+ }
6566+ return n;
6567+}
6568+
6569+extern unsigned long copy_in_user(void __user *to, const void __user *from,
6570+ unsigned long n);
6571+
6572+#endif /* __powerpc64__ */
6573+
6574 extern unsigned long __clear_user(void __user *addr, unsigned long size);
6575
6576 static inline unsigned long clear_user(void __user *addr, unsigned long size)
6577diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
6578index ae54553..cf2184d 100644
6579--- a/arch/powerpc/kernel/exceptions-64e.S
6580+++ b/arch/powerpc/kernel/exceptions-64e.S
6581@@ -716,6 +716,7 @@ storage_fault_common:
6582 std r14,_DAR(r1)
6583 std r15,_DSISR(r1)
6584 addi r3,r1,STACK_FRAME_OVERHEAD
6585+ bl .save_nvgprs
6586 mr r4,r14
6587 mr r5,r15
6588 ld r14,PACA_EXGEN+EX_R14(r13)
6589@@ -724,8 +725,7 @@ storage_fault_common:
6590 cmpdi r3,0
6591 bne- 1f
6592 b .ret_from_except_lite
6593-1: bl .save_nvgprs
6594- mr r5,r3
6595+1: mr r5,r3
6596 addi r3,r1,STACK_FRAME_OVERHEAD
6597 ld r4,_DAR(r1)
6598 bl .bad_page_fault
6599diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
6600index 644378e..b6f2c26 100644
6601--- a/arch/powerpc/kernel/exceptions-64s.S
6602+++ b/arch/powerpc/kernel/exceptions-64s.S
6603@@ -1390,10 +1390,10 @@ handle_page_fault:
6604 11: ld r4,_DAR(r1)
6605 ld r5,_DSISR(r1)
6606 addi r3,r1,STACK_FRAME_OVERHEAD
6607+ bl .save_nvgprs
6608 bl .do_page_fault
6609 cmpdi r3,0
6610 beq+ 12f
6611- bl .save_nvgprs
6612 mr r5,r3
6613 addi r3,r1,STACK_FRAME_OVERHEAD
6614 lwz r4,_DAR(r1)
6615diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
6616index 2e3200c..72095ce 100644
6617--- a/arch/powerpc/kernel/module_32.c
6618+++ b/arch/powerpc/kernel/module_32.c
6619@@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
6620 me->arch.core_plt_section = i;
6621 }
6622 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
6623- printk("Module doesn't contain .plt or .init.plt sections.\n");
6624+ printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
6625 return -ENOEXEC;
6626 }
6627
6628@@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
6629
6630 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
6631 /* Init, or core PLT? */
6632- if (location >= mod->module_core
6633- && location < mod->module_core + mod->core_size)
6634+ if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
6635+ (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
6636 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
6637- else
6638+ else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
6639+ (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
6640 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
6641+ else {
6642+ printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
6643+ return ~0UL;
6644+ }
6645
6646 /* Find this entry, or if that fails, the next avail. entry */
6647 while (entry->jump[0]) {
6648diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
6649index 0d86c8a..df4c5f2 100644
6650--- a/arch/powerpc/kernel/process.c
6651+++ b/arch/powerpc/kernel/process.c
6652@@ -871,8 +871,8 @@ void show_regs(struct pt_regs * regs)
6653 * Lookup NIP late so we have the best change of getting the
6654 * above info out without failing
6655 */
6656- printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
6657- printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
6658+ printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
6659+ printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
6660 #endif
6661 #ifdef CONFIG_PPC_TRANSACTIONAL_MEM
6662 printk("PACATMSCRATCH [%llx]\n", get_paca()->tm_scratch);
6663@@ -1331,10 +1331,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6664 newsp = stack[0];
6665 ip = stack[STACK_FRAME_LR_SAVE];
6666 if (!firstframe || ip != lr) {
6667- printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
6668+ printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
6669 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6670 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
6671- printk(" (%pS)",
6672+ printk(" (%pA)",
6673 (void *)current->ret_stack[curr_frame].ret);
6674 curr_frame--;
6675 }
6676@@ -1354,7 +1354,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
6677 struct pt_regs *regs = (struct pt_regs *)
6678 (sp + STACK_FRAME_OVERHEAD);
6679 lr = regs->link;
6680- printk("--- Exception: %lx at %pS\n LR = %pS\n",
6681+ printk("--- Exception: %lx at %pA\n LR = %pA\n",
6682 regs->trap, (void *)regs->nip, (void *)lr);
6683 firstframe = 1;
6684 }
6685@@ -1396,58 +1396,3 @@ void notrace __ppc64_runlatch_off(void)
6686 mtspr(SPRN_CTRLT, ctrl);
6687 }
6688 #endif /* CONFIG_PPC64 */
6689-
6690-unsigned long arch_align_stack(unsigned long sp)
6691-{
6692- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6693- sp -= get_random_int() & ~PAGE_MASK;
6694- return sp & ~0xf;
6695-}
6696-
6697-static inline unsigned long brk_rnd(void)
6698-{
6699- unsigned long rnd = 0;
6700-
6701- /* 8MB for 32bit, 1GB for 64bit */
6702- if (is_32bit_task())
6703- rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
6704- else
6705- rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
6706-
6707- return rnd << PAGE_SHIFT;
6708-}
6709-
6710-unsigned long arch_randomize_brk(struct mm_struct *mm)
6711-{
6712- unsigned long base = mm->brk;
6713- unsigned long ret;
6714-
6715-#ifdef CONFIG_PPC_STD_MMU_64
6716- /*
6717- * If we are using 1TB segments and we are allowed to randomise
6718- * the heap, we can put it above 1TB so it is backed by a 1TB
6719- * segment. Otherwise the heap will be in the bottom 1TB
6720- * which always uses 256MB segments and this may result in a
6721- * performance penalty.
6722- */
6723- if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
6724- base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
6725-#endif
6726-
6727- ret = PAGE_ALIGN(base + brk_rnd());
6728-
6729- if (ret < mm->brk)
6730- return mm->brk;
6731-
6732- return ret;
6733-}
6734-
6735-unsigned long randomize_et_dyn(unsigned long base)
6736-{
6737- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
6738-
6739- if (ret < base)
6740- return base;
6741-
6742- return ret;
6743-}
6744diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
6745index f9b30c6..d72e7a3 100644
6746--- a/arch/powerpc/kernel/ptrace.c
6747+++ b/arch/powerpc/kernel/ptrace.c
6748@@ -1771,6 +1771,10 @@ long arch_ptrace(struct task_struct *child, long request,
6749 return ret;
6750 }
6751
6752+#ifdef CONFIG_GRKERNSEC_SETXID
6753+extern void gr_delayed_cred_worker(void);
6754+#endif
6755+
6756 /*
6757 * We must return the syscall number to actually look up in the table.
6758 * This can be -1L to skip running any syscall at all.
6759@@ -1781,6 +1785,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
6760
6761 secure_computing_strict(regs->gpr[0]);
6762
6763+#ifdef CONFIG_GRKERNSEC_SETXID
6764+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6765+ gr_delayed_cred_worker();
6766+#endif
6767+
6768 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
6769 tracehook_report_syscall_entry(regs))
6770 /*
6771@@ -1815,6 +1824,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
6772 {
6773 int step;
6774
6775+#ifdef CONFIG_GRKERNSEC_SETXID
6776+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6777+ gr_delayed_cred_worker();
6778+#endif
6779+
6780 audit_syscall_exit(regs);
6781
6782 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6783diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
6784index 201385c..0f01828 100644
6785--- a/arch/powerpc/kernel/signal_32.c
6786+++ b/arch/powerpc/kernel/signal_32.c
6787@@ -976,7 +976,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
6788 /* Save user registers on the stack */
6789 frame = &rt_sf->uc.uc_mcontext;
6790 addr = frame;
6791- if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
6792+ if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6793 sigret = 0;
6794 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
6795 } else {
6796diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
6797index 3459473..2d40783 100644
6798--- a/arch/powerpc/kernel/signal_64.c
6799+++ b/arch/powerpc/kernel/signal_64.c
6800@@ -749,7 +749,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
6801 #endif
6802
6803 /* Set up to return from userspace. */
6804- if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
6805+ if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
6806 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
6807 } else {
6808 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
6809diff --git a/arch/powerpc/kernel/sysfs.c b/arch/powerpc/kernel/sysfs.c
6810index 3ce1f86..c30e629 100644
6811--- a/arch/powerpc/kernel/sysfs.c
6812+++ b/arch/powerpc/kernel/sysfs.c
6813@@ -522,7 +522,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
6814 return NOTIFY_OK;
6815 }
6816
6817-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
6818+static struct notifier_block sysfs_cpu_nb = {
6819 .notifier_call = sysfs_cpu_notify,
6820 };
6821
6822diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
6823index bf33ace..e836d8b 100644
6824--- a/arch/powerpc/kernel/traps.c
6825+++ b/arch/powerpc/kernel/traps.c
6826@@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
6827 return flags;
6828 }
6829
6830+extern void gr_handle_kernel_exploit(void);
6831+
6832 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6833 int signr)
6834 {
6835@@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
6836 panic("Fatal exception in interrupt");
6837 if (panic_on_oops)
6838 panic("Fatal exception");
6839+
6840+ gr_handle_kernel_exploit();
6841+
6842 do_exit(signr);
6843 }
6844
6845diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
6846index 1b2076f..835e4be 100644
6847--- a/arch/powerpc/kernel/vdso.c
6848+++ b/arch/powerpc/kernel/vdso.c
6849@@ -34,6 +34,7 @@
6850 #include <asm/firmware.h>
6851 #include <asm/vdso.h>
6852 #include <asm/vdso_datapage.h>
6853+#include <asm/mman.h>
6854
6855 #include "setup.h"
6856
6857@@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6858 vdso_base = VDSO32_MBASE;
6859 #endif
6860
6861- current->mm->context.vdso_base = 0;
6862+ current->mm->context.vdso_base = ~0UL;
6863
6864 /* vDSO has a problem and was disabled, just don't "enable" it for the
6865 * process
6866@@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
6867 vdso_base = get_unmapped_area(NULL, vdso_base,
6868 (vdso_pages << PAGE_SHIFT) +
6869 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
6870- 0, 0);
6871+ 0, MAP_PRIVATE | MAP_EXECUTABLE);
6872 if (IS_ERR_VALUE(vdso_base)) {
6873 rc = vdso_base;
6874 goto fail_mmapsem;
6875diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
6876index 5eea6f3..5d10396 100644
6877--- a/arch/powerpc/lib/usercopy_64.c
6878+++ b/arch/powerpc/lib/usercopy_64.c
6879@@ -9,22 +9,6 @@
6880 #include <linux/module.h>
6881 #include <asm/uaccess.h>
6882
6883-unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
6884-{
6885- if (likely(access_ok(VERIFY_READ, from, n)))
6886- n = __copy_from_user(to, from, n);
6887- else
6888- memset(to, 0, n);
6889- return n;
6890-}
6891-
6892-unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
6893-{
6894- if (likely(access_ok(VERIFY_WRITE, to, n)))
6895- n = __copy_to_user(to, from, n);
6896- return n;
6897-}
6898-
6899 unsigned long copy_in_user(void __user *to, const void __user *from,
6900 unsigned long n)
6901 {
6902@@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
6903 return n;
6904 }
6905
6906-EXPORT_SYMBOL(copy_from_user);
6907-EXPORT_SYMBOL(copy_to_user);
6908 EXPORT_SYMBOL(copy_in_user);
6909
6910diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
6911index 229951f..cdeca42 100644
6912--- a/arch/powerpc/mm/fault.c
6913+++ b/arch/powerpc/mm/fault.c
6914@@ -32,6 +32,10 @@
6915 #include <linux/perf_event.h>
6916 #include <linux/magic.h>
6917 #include <linux/ratelimit.h>
6918+#include <linux/slab.h>
6919+#include <linux/pagemap.h>
6920+#include <linux/compiler.h>
6921+#include <linux/unistd.h>
6922
6923 #include <asm/firmware.h>
6924 #include <asm/page.h>
6925@@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
6926 }
6927 #endif
6928
6929+#ifdef CONFIG_PAX_PAGEEXEC
6930+/*
6931+ * PaX: decide what to do with offenders (regs->nip = fault address)
6932+ *
6933+ * returns 1 when task should be killed
6934+ */
6935+static int pax_handle_fetch_fault(struct pt_regs *regs)
6936+{
6937+ return 1;
6938+}
6939+
6940+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6941+{
6942+ unsigned long i;
6943+
6944+ printk(KERN_ERR "PAX: bytes at PC: ");
6945+ for (i = 0; i < 5; i++) {
6946+ unsigned int c;
6947+ if (get_user(c, (unsigned int __user *)pc+i))
6948+ printk(KERN_CONT "???????? ");
6949+ else
6950+ printk(KERN_CONT "%08x ", c);
6951+ }
6952+ printk("\n");
6953+}
6954+#endif
6955+
6956 /*
6957 * Check whether the instruction at regs->nip is a store using
6958 * an update addressing form which will update r1.
6959@@ -213,7 +244,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
6960 * indicate errors in DSISR but can validly be set in SRR1.
6961 */
6962 if (trap == 0x400)
6963- error_code &= 0x48200000;
6964+ error_code &= 0x58200000;
6965 else
6966 is_write = error_code & DSISR_ISSTORE;
6967 #else
6968@@ -364,7 +395,7 @@ good_area:
6969 * "undefined". Of those that can be set, this is the only
6970 * one which seems bad.
6971 */
6972- if (error_code & 0x10000000)
6973+ if (error_code & DSISR_GUARDED)
6974 /* Guarded storage error. */
6975 goto bad_area;
6976 #endif /* CONFIG_8xx */
6977@@ -379,7 +410,7 @@ good_area:
6978 * processors use the same I/D cache coherency mechanism
6979 * as embedded.
6980 */
6981- if (error_code & DSISR_PROTFAULT)
6982+ if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
6983 goto bad_area;
6984 #endif /* CONFIG_PPC_STD_MMU */
6985
6986@@ -462,6 +493,23 @@ bad_area:
6987 bad_area_nosemaphore:
6988 /* User mode accesses cause a SIGSEGV */
6989 if (user_mode(regs)) {
6990+
6991+#ifdef CONFIG_PAX_PAGEEXEC
6992+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
6993+#ifdef CONFIG_PPC_STD_MMU
6994+ if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
6995+#else
6996+ if (is_exec && regs->nip == address) {
6997+#endif
6998+ switch (pax_handle_fetch_fault(regs)) {
6999+ }
7000+
7001+ pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
7002+ do_group_exit(SIGKILL);
7003+ }
7004+ }
7005+#endif
7006+
7007 _exception(SIGSEGV, regs, code, address);
7008 return 0;
7009 }
7010diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
7011index 67a42ed..cd463e0 100644
7012--- a/arch/powerpc/mm/mmap_64.c
7013+++ b/arch/powerpc/mm/mmap_64.c
7014@@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
7015 {
7016 unsigned long rnd = 0;
7017
7018+#ifdef CONFIG_PAX_RANDMMAP
7019+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7020+#endif
7021+
7022 if (current->flags & PF_RANDOMIZE) {
7023 /* 8MB for 32bit, 1GB for 64bit */
7024 if (is_32bit_task())
7025@@ -91,10 +95,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7026 */
7027 if (mmap_is_legacy()) {
7028 mm->mmap_base = TASK_UNMAPPED_BASE;
7029+
7030+#ifdef CONFIG_PAX_RANDMMAP
7031+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7032+ mm->mmap_base += mm->delta_mmap;
7033+#endif
7034+
7035 mm->get_unmapped_area = arch_get_unmapped_area;
7036 mm->unmap_area = arch_unmap_area;
7037 } else {
7038 mm->mmap_base = mmap_base();
7039+
7040+#ifdef CONFIG_PAX_RANDMMAP
7041+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7042+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7043+#endif
7044+
7045 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7046 mm->unmap_area = arch_unmap_area_topdown;
7047 }
7048diff --git a/arch/powerpc/mm/mmu_context_nohash.c b/arch/powerpc/mm/mmu_context_nohash.c
7049index e779642..e5bb889 100644
7050--- a/arch/powerpc/mm/mmu_context_nohash.c
7051+++ b/arch/powerpc/mm/mmu_context_nohash.c
7052@@ -363,7 +363,7 @@ static int __cpuinit mmu_context_cpu_notify(struct notifier_block *self,
7053 return NOTIFY_OK;
7054 }
7055
7056-static struct notifier_block __cpuinitdata mmu_context_cpu_nb = {
7057+static struct notifier_block mmu_context_cpu_nb = {
7058 .notifier_call = mmu_context_cpu_notify,
7059 };
7060
7061diff --git a/arch/powerpc/mm/numa.c b/arch/powerpc/mm/numa.c
7062index 6a252c4..3024d81 100644
7063--- a/arch/powerpc/mm/numa.c
7064+++ b/arch/powerpc/mm/numa.c
7065@@ -932,7 +932,7 @@ static void __init *careful_zallocation(int nid, unsigned long size,
7066 return ret;
7067 }
7068
7069-static struct notifier_block __cpuinitdata ppc64_numa_nb = {
7070+static struct notifier_block ppc64_numa_nb = {
7071 .notifier_call = cpu_numa_callback,
7072 .priority = 1 /* Must run before sched domains notifier. */
7073 };
7074diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
7075index cf9dada..241529f 100644
7076--- a/arch/powerpc/mm/slice.c
7077+++ b/arch/powerpc/mm/slice.c
7078@@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
7079 if ((mm->task_size - len) < addr)
7080 return 0;
7081 vma = find_vma(mm, addr);
7082- return (!vma || (addr + len) <= vma->vm_start);
7083+ return check_heap_stack_gap(vma, addr, len, 0);
7084 }
7085
7086 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
7087@@ -272,7 +272,7 @@ full_search:
7088 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
7089 continue;
7090 }
7091- if (!vma || addr + len <= vma->vm_start) {
7092+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7093 /*
7094 * Remember the place where we stopped the search:
7095 */
7096@@ -329,10 +329,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7097 }
7098 }
7099
7100- addr = mm->mmap_base;
7101- while (addr > len) {
7102+ if (mm->mmap_base < len)
7103+ addr = -ENOMEM;
7104+ else
7105+ addr = mm->mmap_base - len;
7106+
7107+ while (!IS_ERR_VALUE(addr)) {
7108 /* Go down by chunk size */
7109- addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
7110+ addr = _ALIGN_DOWN(addr, 1ul << pshift);
7111
7112 /* Check for hit with different page size */
7113 mask = slice_range_to_mask(addr, len);
7114@@ -352,7 +356,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7115 * return with success:
7116 */
7117 vma = find_vma(mm, addr);
7118- if (!vma || (addr + len) <= vma->vm_start) {
7119+ if (check_heap_stack_gap(vma, addr, len, 0)) {
7120 /* remember the address as a hint for next time */
7121 if (use_cache)
7122 mm->free_area_cache = addr;
7123@@ -364,7 +368,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
7124 mm->cached_hole_size = vma->vm_start - addr;
7125
7126 /* try just below the current vma->vm_start */
7127- addr = vma->vm_start;
7128+ addr = skip_heap_stack_gap(vma, len, 0);
7129 }
7130
7131 /*
7132@@ -442,6 +446,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
7133 if (fixed && addr > (mm->task_size - len))
7134 return -EINVAL;
7135
7136+#ifdef CONFIG_PAX_RANDMMAP
7137+ if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
7138+ addr = 0;
7139+#endif
7140+
7141 /* If hint, make sure it matches our alignment restrictions */
7142 if (!fixed && addr) {
7143 addr = _ALIGN_UP(addr, 1ul << pshift);
7144diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
7145index 68c57d3..1fdcfb2 100644
7146--- a/arch/powerpc/platforms/cell/spufs/file.c
7147+++ b/arch/powerpc/platforms/cell/spufs/file.c
7148@@ -281,9 +281,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
7149 return VM_FAULT_NOPAGE;
7150 }
7151
7152-static int spufs_mem_mmap_access(struct vm_area_struct *vma,
7153+static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
7154 unsigned long address,
7155- void *buf, int len, int write)
7156+ void *buf, size_t len, int write)
7157 {
7158 struct spu_context *ctx = vma->vm_file->private_data;
7159 unsigned long offset = address - vma->vm_start;
7160diff --git a/arch/powerpc/platforms/powermac/smp.c b/arch/powerpc/platforms/powermac/smp.c
7161index bdb738a..49c9f95 100644
7162--- a/arch/powerpc/platforms/powermac/smp.c
7163+++ b/arch/powerpc/platforms/powermac/smp.c
7164@@ -885,7 +885,7 @@ static int smp_core99_cpu_notify(struct notifier_block *self,
7165 return NOTIFY_OK;
7166 }
7167
7168-static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
7169+static struct notifier_block smp_core99_cpu_nb = {
7170 .notifier_call = smp_core99_cpu_notify,
7171 };
7172 #endif /* CONFIG_HOTPLUG_CPU */
7173diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
7174index c797832..ce575c8 100644
7175--- a/arch/s390/include/asm/atomic.h
7176+++ b/arch/s390/include/asm/atomic.h
7177@@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
7178 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
7179 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7180
7181+#define atomic64_read_unchecked(v) atomic64_read(v)
7182+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7183+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7184+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7185+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7186+#define atomic64_inc_unchecked(v) atomic64_inc(v)
7187+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7188+#define atomic64_dec_unchecked(v) atomic64_dec(v)
7189+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7190+
7191 #define smp_mb__before_atomic_dec() smp_mb()
7192 #define smp_mb__after_atomic_dec() smp_mb()
7193 #define smp_mb__before_atomic_inc() smp_mb()
7194diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
7195index 4d7ccac..d03d0ad 100644
7196--- a/arch/s390/include/asm/cache.h
7197+++ b/arch/s390/include/asm/cache.h
7198@@ -9,8 +9,10 @@
7199 #ifndef __ARCH_S390_CACHE_H
7200 #define __ARCH_S390_CACHE_H
7201
7202-#define L1_CACHE_BYTES 256
7203+#include <linux/const.h>
7204+
7205 #define L1_CACHE_SHIFT 8
7206+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7207 #define NET_SKB_PAD 32
7208
7209 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7210diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
7211index 1bfdf24..9c9ab2e 100644
7212--- a/arch/s390/include/asm/elf.h
7213+++ b/arch/s390/include/asm/elf.h
7214@@ -160,8 +160,14 @@ extern unsigned int vdso_enabled;
7215 the loader. We need to make sure that it is out of the way of the program
7216 that it will "exec", and that there is sufficient room for the brk. */
7217
7218-extern unsigned long randomize_et_dyn(unsigned long base);
7219-#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
7220+#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
7221+
7222+#ifdef CONFIG_PAX_ASLR
7223+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
7224+
7225+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7226+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
7227+#endif
7228
7229 /* This yields a mask that user programs can use to figure out what
7230 instruction set this CPU supports. */
7231@@ -207,9 +213,6 @@ struct linux_binprm;
7232 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
7233 int arch_setup_additional_pages(struct linux_binprm *, int);
7234
7235-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7236-#define arch_randomize_brk arch_randomize_brk
7237-
7238 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
7239
7240 #endif
7241diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
7242index c4a93d6..4d2a9b4 100644
7243--- a/arch/s390/include/asm/exec.h
7244+++ b/arch/s390/include/asm/exec.h
7245@@ -7,6 +7,6 @@
7246 #ifndef __ASM_EXEC_H
7247 #define __ASM_EXEC_H
7248
7249-extern unsigned long arch_align_stack(unsigned long sp);
7250+#define arch_align_stack(x) ((x) & ~0xfUL)
7251
7252 #endif /* __ASM_EXEC_H */
7253diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
7254index 9c33ed4..e40cbef 100644
7255--- a/arch/s390/include/asm/uaccess.h
7256+++ b/arch/s390/include/asm/uaccess.h
7257@@ -252,6 +252,10 @@ static inline unsigned long __must_check
7258 copy_to_user(void __user *to, const void *from, unsigned long n)
7259 {
7260 might_fault();
7261+
7262+ if ((long)n < 0)
7263+ return n;
7264+
7265 return __copy_to_user(to, from, n);
7266 }
7267
7268@@ -275,6 +279,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
7269 static inline unsigned long __must_check
7270 __copy_from_user(void *to, const void __user *from, unsigned long n)
7271 {
7272+ if ((long)n < 0)
7273+ return n;
7274+
7275 if (__builtin_constant_p(n) && (n <= 256))
7276 return uaccess.copy_from_user_small(n, from, to);
7277 else
7278@@ -306,10 +313,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
7279 static inline unsigned long __must_check
7280 copy_from_user(void *to, const void __user *from, unsigned long n)
7281 {
7282- unsigned int sz = __compiletime_object_size(to);
7283+ size_t sz = __compiletime_object_size(to);
7284
7285 might_fault();
7286- if (unlikely(sz != -1 && sz < n)) {
7287+
7288+ if ((long)n < 0)
7289+ return n;
7290+
7291+ if (unlikely(sz != (size_t)-1 && sz < n)) {
7292 copy_from_user_overflow();
7293 return n;
7294 }
7295diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
7296index 7845e15..59c4353 100644
7297--- a/arch/s390/kernel/module.c
7298+++ b/arch/s390/kernel/module.c
7299@@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
7300
7301 /* Increase core size by size of got & plt and set start
7302 offsets for got and plt. */
7303- me->core_size = ALIGN(me->core_size, 4);
7304- me->arch.got_offset = me->core_size;
7305- me->core_size += me->arch.got_size;
7306- me->arch.plt_offset = me->core_size;
7307- me->core_size += me->arch.plt_size;
7308+ me->core_size_rw = ALIGN(me->core_size_rw, 4);
7309+ me->arch.got_offset = me->core_size_rw;
7310+ me->core_size_rw += me->arch.got_size;
7311+ me->arch.plt_offset = me->core_size_rx;
7312+ me->core_size_rx += me->arch.plt_size;
7313 return 0;
7314 }
7315
7316@@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7317 if (info->got_initialized == 0) {
7318 Elf_Addr *gotent;
7319
7320- gotent = me->module_core + me->arch.got_offset +
7321+ gotent = me->module_core_rw + me->arch.got_offset +
7322 info->got_offset;
7323 *gotent = val;
7324 info->got_initialized = 1;
7325@@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7326 rc = apply_rela_bits(loc, val, 0, 64, 0);
7327 else if (r_type == R_390_GOTENT ||
7328 r_type == R_390_GOTPLTENT) {
7329- val += (Elf_Addr) me->module_core - loc;
7330+ val += (Elf_Addr) me->module_core_rw - loc;
7331 rc = apply_rela_bits(loc, val, 1, 32, 1);
7332 }
7333 break;
7334@@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7335 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
7336 if (info->plt_initialized == 0) {
7337 unsigned int *ip;
7338- ip = me->module_core + me->arch.plt_offset +
7339+ ip = me->module_core_rx + me->arch.plt_offset +
7340 info->plt_offset;
7341 #ifndef CONFIG_64BIT
7342 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
7343@@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7344 val - loc + 0xffffUL < 0x1ffffeUL) ||
7345 (r_type == R_390_PLT32DBL &&
7346 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
7347- val = (Elf_Addr) me->module_core +
7348+ val = (Elf_Addr) me->module_core_rx +
7349 me->arch.plt_offset +
7350 info->plt_offset;
7351 val += rela->r_addend - loc;
7352@@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7353 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
7354 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
7355 val = val + rela->r_addend -
7356- ((Elf_Addr) me->module_core + me->arch.got_offset);
7357+ ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
7358 if (r_type == R_390_GOTOFF16)
7359 rc = apply_rela_bits(loc, val, 0, 16, 0);
7360 else if (r_type == R_390_GOTOFF32)
7361@@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
7362 break;
7363 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
7364 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
7365- val = (Elf_Addr) me->module_core + me->arch.got_offset +
7366+ val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
7367 rela->r_addend - loc;
7368 if (r_type == R_390_GOTPC)
7369 rc = apply_rela_bits(loc, val, 1, 32, 0);
7370diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
7371index 536d645..4a5bd9e 100644
7372--- a/arch/s390/kernel/process.c
7373+++ b/arch/s390/kernel/process.c
7374@@ -250,39 +250,3 @@ unsigned long get_wchan(struct task_struct *p)
7375 }
7376 return 0;
7377 }
7378-
7379-unsigned long arch_align_stack(unsigned long sp)
7380-{
7381- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7382- sp -= get_random_int() & ~PAGE_MASK;
7383- return sp & ~0xf;
7384-}
7385-
7386-static inline unsigned long brk_rnd(void)
7387-{
7388- /* 8MB for 32bit, 1GB for 64bit */
7389- if (is_32bit_task())
7390- return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
7391- else
7392- return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
7393-}
7394-
7395-unsigned long arch_randomize_brk(struct mm_struct *mm)
7396-{
7397- unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
7398-
7399- if (ret < mm->brk)
7400- return mm->brk;
7401- return ret;
7402-}
7403-
7404-unsigned long randomize_et_dyn(unsigned long base)
7405-{
7406- unsigned long ret = PAGE_ALIGN(base + brk_rnd());
7407-
7408- if (!(current->flags & PF_RANDOMIZE))
7409- return base;
7410- if (ret < base)
7411- return base;
7412- return ret;
7413-}
7414diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
7415index 06bafec..2bca531 100644
7416--- a/arch/s390/mm/mmap.c
7417+++ b/arch/s390/mm/mmap.c
7418@@ -90,10 +90,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7419 */
7420 if (mmap_is_legacy()) {
7421 mm->mmap_base = TASK_UNMAPPED_BASE;
7422+
7423+#ifdef CONFIG_PAX_RANDMMAP
7424+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7425+ mm->mmap_base += mm->delta_mmap;
7426+#endif
7427+
7428 mm->get_unmapped_area = arch_get_unmapped_area;
7429 mm->unmap_area = arch_unmap_area;
7430 } else {
7431 mm->mmap_base = mmap_base();
7432+
7433+#ifdef CONFIG_PAX_RANDMMAP
7434+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7435+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7436+#endif
7437+
7438 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7439 mm->unmap_area = arch_unmap_area_topdown;
7440 }
7441@@ -175,10 +187,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7442 */
7443 if (mmap_is_legacy()) {
7444 mm->mmap_base = TASK_UNMAPPED_BASE;
7445+
7446+#ifdef CONFIG_PAX_RANDMMAP
7447+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7448+ mm->mmap_base += mm->delta_mmap;
7449+#endif
7450+
7451 mm->get_unmapped_area = s390_get_unmapped_area;
7452 mm->unmap_area = arch_unmap_area;
7453 } else {
7454 mm->mmap_base = mmap_base();
7455+
7456+#ifdef CONFIG_PAX_RANDMMAP
7457+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7458+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7459+#endif
7460+
7461 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
7462 mm->unmap_area = arch_unmap_area_topdown;
7463 }
7464diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
7465index ae3d59f..f65f075 100644
7466--- a/arch/score/include/asm/cache.h
7467+++ b/arch/score/include/asm/cache.h
7468@@ -1,7 +1,9 @@
7469 #ifndef _ASM_SCORE_CACHE_H
7470 #define _ASM_SCORE_CACHE_H
7471
7472+#include <linux/const.h>
7473+
7474 #define L1_CACHE_SHIFT 4
7475-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7476+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7477
7478 #endif /* _ASM_SCORE_CACHE_H */
7479diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
7480index f9f3cd5..58ff438 100644
7481--- a/arch/score/include/asm/exec.h
7482+++ b/arch/score/include/asm/exec.h
7483@@ -1,6 +1,6 @@
7484 #ifndef _ASM_SCORE_EXEC_H
7485 #define _ASM_SCORE_EXEC_H
7486
7487-extern unsigned long arch_align_stack(unsigned long sp);
7488+#define arch_align_stack(x) (x)
7489
7490 #endif /* _ASM_SCORE_EXEC_H */
7491diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
7492index 7956846..5f37677 100644
7493--- a/arch/score/kernel/process.c
7494+++ b/arch/score/kernel/process.c
7495@@ -134,8 +134,3 @@ unsigned long get_wchan(struct task_struct *task)
7496
7497 return task_pt_regs(task)->cp0_epc;
7498 }
7499-
7500-unsigned long arch_align_stack(unsigned long sp)
7501-{
7502- return sp;
7503-}
7504diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
7505index ef9e555..331bd29 100644
7506--- a/arch/sh/include/asm/cache.h
7507+++ b/arch/sh/include/asm/cache.h
7508@@ -9,10 +9,11 @@
7509 #define __ASM_SH_CACHE_H
7510 #ifdef __KERNEL__
7511
7512+#include <linux/const.h>
7513 #include <linux/init.h>
7514 #include <cpu/cache.h>
7515
7516-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7517+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7518
7519 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
7520
7521diff --git a/arch/sh/kernel/cpu/sh4a/smp-shx3.c b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7522index 03f2b55..b0270327 100644
7523--- a/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7524+++ b/arch/sh/kernel/cpu/sh4a/smp-shx3.c
7525@@ -143,7 +143,7 @@ shx3_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
7526 return NOTIFY_OK;
7527 }
7528
7529-static struct notifier_block __cpuinitdata shx3_cpu_notifier = {
7530+static struct notifier_block shx3_cpu_notifier = {
7531 .notifier_call = shx3_cpu_callback,
7532 };
7533
7534diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
7535index 6777177..cb5e44f 100644
7536--- a/arch/sh/mm/mmap.c
7537+++ b/arch/sh/mm/mmap.c
7538@@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7539 struct mm_struct *mm = current->mm;
7540 struct vm_area_struct *vma;
7541 int do_colour_align;
7542+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7543 struct vm_unmapped_area_info info;
7544
7545 if (flags & MAP_FIXED) {
7546@@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7547 if (filp || (flags & MAP_SHARED))
7548 do_colour_align = 1;
7549
7550+#ifdef CONFIG_PAX_RANDMMAP
7551+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7552+#endif
7553+
7554 if (addr) {
7555 if (do_colour_align)
7556 addr = COLOUR_ALIGN(addr, pgoff);
7557@@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7558 addr = PAGE_ALIGN(addr);
7559
7560 vma = find_vma(mm, addr);
7561- if (TASK_SIZE - len >= addr &&
7562- (!vma || addr + len <= vma->vm_start))
7563+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7564 return addr;
7565 }
7566
7567 info.flags = 0;
7568 info.length = len;
7569- info.low_limit = TASK_UNMAPPED_BASE;
7570+ info.low_limit = mm->mmap_base;
7571 info.high_limit = TASK_SIZE;
7572 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
7573 info.align_offset = pgoff << PAGE_SHIFT;
7574@@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7575 struct mm_struct *mm = current->mm;
7576 unsigned long addr = addr0;
7577 int do_colour_align;
7578+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7579 struct vm_unmapped_area_info info;
7580
7581 if (flags & MAP_FIXED) {
7582@@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7583 if (filp || (flags & MAP_SHARED))
7584 do_colour_align = 1;
7585
7586+#ifdef CONFIG_PAX_RANDMMAP
7587+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7588+#endif
7589+
7590 /* requesting a specific address */
7591 if (addr) {
7592 if (do_colour_align)
7593@@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7594 addr = PAGE_ALIGN(addr);
7595
7596 vma = find_vma(mm, addr);
7597- if (TASK_SIZE - len >= addr &&
7598- (!vma || addr + len <= vma->vm_start))
7599+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7600 return addr;
7601 }
7602
7603@@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7604 VM_BUG_ON(addr != -ENOMEM);
7605 info.flags = 0;
7606 info.low_limit = TASK_UNMAPPED_BASE;
7607+
7608+#ifdef CONFIG_PAX_RANDMMAP
7609+ if (mm->pax_flags & MF_PAX_RANDMMAP)
7610+ info.low_limit += mm->delta_mmap;
7611+#endif
7612+
7613 info.high_limit = TASK_SIZE;
7614 addr = vm_unmapped_area(&info);
7615 }
7616diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
7617index be56a24..443328f 100644
7618--- a/arch/sparc/include/asm/atomic_64.h
7619+++ b/arch/sparc/include/asm/atomic_64.h
7620@@ -14,18 +14,40 @@
7621 #define ATOMIC64_INIT(i) { (i) }
7622
7623 #define atomic_read(v) (*(volatile int *)&(v)->counter)
7624+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
7625+{
7626+ return v->counter;
7627+}
7628 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
7629+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
7630+{
7631+ return v->counter;
7632+}
7633
7634 #define atomic_set(v, i) (((v)->counter) = i)
7635+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
7636+{
7637+ v->counter = i;
7638+}
7639 #define atomic64_set(v, i) (((v)->counter) = i)
7640+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
7641+{
7642+ v->counter = i;
7643+}
7644
7645 extern void atomic_add(int, atomic_t *);
7646+extern void atomic_add_unchecked(int, atomic_unchecked_t *);
7647 extern void atomic64_add(long, atomic64_t *);
7648+extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
7649 extern void atomic_sub(int, atomic_t *);
7650+extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
7651 extern void atomic64_sub(long, atomic64_t *);
7652+extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
7653
7654 extern int atomic_add_ret(int, atomic_t *);
7655+extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
7656 extern long atomic64_add_ret(long, atomic64_t *);
7657+extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
7658 extern int atomic_sub_ret(int, atomic_t *);
7659 extern long atomic64_sub_ret(long, atomic64_t *);
7660
7661@@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7662 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
7663
7664 #define atomic_inc_return(v) atomic_add_ret(1, v)
7665+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
7666+{
7667+ return atomic_add_ret_unchecked(1, v);
7668+}
7669 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
7670+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
7671+{
7672+ return atomic64_add_ret_unchecked(1, v);
7673+}
7674
7675 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
7676 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
7677
7678 #define atomic_add_return(i, v) atomic_add_ret(i, v)
7679+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
7680+{
7681+ return atomic_add_ret_unchecked(i, v);
7682+}
7683 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
7684+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
7685+{
7686+ return atomic64_add_ret_unchecked(i, v);
7687+}
7688
7689 /*
7690 * atomic_inc_and_test - increment and test
7691@@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7692 * other cases.
7693 */
7694 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
7695+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
7696+{
7697+ return atomic_inc_return_unchecked(v) == 0;
7698+}
7699 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
7700
7701 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
7702@@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
7703 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
7704
7705 #define atomic_inc(v) atomic_add(1, v)
7706+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
7707+{
7708+ atomic_add_unchecked(1, v);
7709+}
7710 #define atomic64_inc(v) atomic64_add(1, v)
7711+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
7712+{
7713+ atomic64_add_unchecked(1, v);
7714+}
7715
7716 #define atomic_dec(v) atomic_sub(1, v)
7717+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
7718+{
7719+ atomic_sub_unchecked(1, v);
7720+}
7721 #define atomic64_dec(v) atomic64_sub(1, v)
7722+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
7723+{
7724+ atomic64_sub_unchecked(1, v);
7725+}
7726
7727 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
7728 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
7729
7730 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
7731+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
7732+{
7733+ return cmpxchg(&v->counter, old, new);
7734+}
7735 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
7736+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
7737+{
7738+ return xchg(&v->counter, new);
7739+}
7740
7741 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7742 {
7743- int c, old;
7744+ int c, old, new;
7745 c = atomic_read(v);
7746 for (;;) {
7747- if (unlikely(c == (u)))
7748+ if (unlikely(c == u))
7749 break;
7750- old = atomic_cmpxchg((v), c, c + (a));
7751+
7752+ asm volatile("addcc %2, %0, %0\n"
7753+
7754+#ifdef CONFIG_PAX_REFCOUNT
7755+ "tvs %%icc, 6\n"
7756+#endif
7757+
7758+ : "=r" (new)
7759+ : "0" (c), "ir" (a)
7760+ : "cc");
7761+
7762+ old = atomic_cmpxchg(v, c, new);
7763 if (likely(old == c))
7764 break;
7765 c = old;
7766@@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
7767 #define atomic64_cmpxchg(v, o, n) \
7768 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
7769 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
7770+static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
7771+{
7772+ return xchg(&v->counter, new);
7773+}
7774
7775 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7776 {
7777- long c, old;
7778+ long c, old, new;
7779 c = atomic64_read(v);
7780 for (;;) {
7781- if (unlikely(c == (u)))
7782+ if (unlikely(c == u))
7783 break;
7784- old = atomic64_cmpxchg((v), c, c + (a));
7785+
7786+ asm volatile("addcc %2, %0, %0\n"
7787+
7788+#ifdef CONFIG_PAX_REFCOUNT
7789+ "tvs %%xcc, 6\n"
7790+#endif
7791+
7792+ : "=r" (new)
7793+ : "0" (c), "ir" (a)
7794+ : "cc");
7795+
7796+ old = atomic64_cmpxchg(v, c, new);
7797 if (likely(old == c))
7798 break;
7799 c = old;
7800 }
7801- return c != (u);
7802+ return c != u;
7803 }
7804
7805 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7806diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
7807index 5bb6991..5c2132e 100644
7808--- a/arch/sparc/include/asm/cache.h
7809+++ b/arch/sparc/include/asm/cache.h
7810@@ -7,10 +7,12 @@
7811 #ifndef _SPARC_CACHE_H
7812 #define _SPARC_CACHE_H
7813
7814+#include <linux/const.h>
7815+
7816 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
7817
7818 #define L1_CACHE_SHIFT 5
7819-#define L1_CACHE_BYTES 32
7820+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7821
7822 #ifdef CONFIG_SPARC32
7823 #define SMP_CACHE_BYTES_SHIFT 5
7824diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
7825index a24e41f..47677ff 100644
7826--- a/arch/sparc/include/asm/elf_32.h
7827+++ b/arch/sparc/include/asm/elf_32.h
7828@@ -114,6 +114,13 @@ typedef struct {
7829
7830 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
7831
7832+#ifdef CONFIG_PAX_ASLR
7833+#define PAX_ELF_ET_DYN_BASE 0x10000UL
7834+
7835+#define PAX_DELTA_MMAP_LEN 16
7836+#define PAX_DELTA_STACK_LEN 16
7837+#endif
7838+
7839 /* This yields a mask that user programs can use to figure out what
7840 instruction set this cpu supports. This can NOT be done in userspace
7841 on Sparc. */
7842diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
7843index 370ca1e..d4f4a98 100644
7844--- a/arch/sparc/include/asm/elf_64.h
7845+++ b/arch/sparc/include/asm/elf_64.h
7846@@ -189,6 +189,13 @@ typedef struct {
7847 #define ELF_ET_DYN_BASE 0x0000010000000000UL
7848 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
7849
7850+#ifdef CONFIG_PAX_ASLR
7851+#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
7852+
7853+#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
7854+#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
7855+#endif
7856+
7857 extern unsigned long sparc64_elf_hwcap;
7858 #define ELF_HWCAP sparc64_elf_hwcap
7859
7860diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
7861index 9b1c36d..209298b 100644
7862--- a/arch/sparc/include/asm/pgalloc_32.h
7863+++ b/arch/sparc/include/asm/pgalloc_32.h
7864@@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
7865 }
7866
7867 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
7868+#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
7869
7870 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
7871 unsigned long address)
7872diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
7873index bcfe063..b333142 100644
7874--- a/arch/sparc/include/asm/pgalloc_64.h
7875+++ b/arch/sparc/include/asm/pgalloc_64.h
7876@@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7877 }
7878
7879 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
7880+#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
7881
7882 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
7883 {
7884diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
7885index 6fc1348..390c50a 100644
7886--- a/arch/sparc/include/asm/pgtable_32.h
7887+++ b/arch/sparc/include/asm/pgtable_32.h
7888@@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
7889 #define PAGE_SHARED SRMMU_PAGE_SHARED
7890 #define PAGE_COPY SRMMU_PAGE_COPY
7891 #define PAGE_READONLY SRMMU_PAGE_RDONLY
7892+#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
7893+#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
7894+#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
7895 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
7896
7897 /* Top-level page directory - dummy used by init-mm.
7898@@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
7899
7900 /* xwr */
7901 #define __P000 PAGE_NONE
7902-#define __P001 PAGE_READONLY
7903-#define __P010 PAGE_COPY
7904-#define __P011 PAGE_COPY
7905+#define __P001 PAGE_READONLY_NOEXEC
7906+#define __P010 PAGE_COPY_NOEXEC
7907+#define __P011 PAGE_COPY_NOEXEC
7908 #define __P100 PAGE_READONLY
7909 #define __P101 PAGE_READONLY
7910 #define __P110 PAGE_COPY
7911 #define __P111 PAGE_COPY
7912
7913 #define __S000 PAGE_NONE
7914-#define __S001 PAGE_READONLY
7915-#define __S010 PAGE_SHARED
7916-#define __S011 PAGE_SHARED
7917+#define __S001 PAGE_READONLY_NOEXEC
7918+#define __S010 PAGE_SHARED_NOEXEC
7919+#define __S011 PAGE_SHARED_NOEXEC
7920 #define __S100 PAGE_READONLY
7921 #define __S101 PAGE_READONLY
7922 #define __S110 PAGE_SHARED
7923diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
7924index 79da178..c2eede8 100644
7925--- a/arch/sparc/include/asm/pgtsrmmu.h
7926+++ b/arch/sparc/include/asm/pgtsrmmu.h
7927@@ -115,6 +115,11 @@
7928 SRMMU_EXEC | SRMMU_REF)
7929 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
7930 SRMMU_EXEC | SRMMU_REF)
7931+
7932+#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
7933+#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7934+#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
7935+
7936 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
7937 SRMMU_DIRTY | SRMMU_REF)
7938
7939diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
7940index 9689176..63c18ea 100644
7941--- a/arch/sparc/include/asm/spinlock_64.h
7942+++ b/arch/sparc/include/asm/spinlock_64.h
7943@@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
7944
7945 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
7946
7947-static void inline arch_read_lock(arch_rwlock_t *lock)
7948+static inline void arch_read_lock(arch_rwlock_t *lock)
7949 {
7950 unsigned long tmp1, tmp2;
7951
7952 __asm__ __volatile__ (
7953 "1: ldsw [%2], %0\n"
7954 " brlz,pn %0, 2f\n"
7955-"4: add %0, 1, %1\n"
7956+"4: addcc %0, 1, %1\n"
7957+
7958+#ifdef CONFIG_PAX_REFCOUNT
7959+" tvs %%icc, 6\n"
7960+#endif
7961+
7962 " cas [%2], %0, %1\n"
7963 " cmp %0, %1\n"
7964 " bne,pn %%icc, 1b\n"
7965@@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
7966 " .previous"
7967 : "=&r" (tmp1), "=&r" (tmp2)
7968 : "r" (lock)
7969- : "memory");
7970+ : "memory", "cc");
7971 }
7972
7973-static int inline arch_read_trylock(arch_rwlock_t *lock)
7974+static inline int arch_read_trylock(arch_rwlock_t *lock)
7975 {
7976 int tmp1, tmp2;
7977
7978@@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7979 "1: ldsw [%2], %0\n"
7980 " brlz,a,pn %0, 2f\n"
7981 " mov 0, %0\n"
7982-" add %0, 1, %1\n"
7983+" addcc %0, 1, %1\n"
7984+
7985+#ifdef CONFIG_PAX_REFCOUNT
7986+" tvs %%icc, 6\n"
7987+#endif
7988+
7989 " cas [%2], %0, %1\n"
7990 " cmp %0, %1\n"
7991 " bne,pn %%icc, 1b\n"
7992@@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
7993 return tmp1;
7994 }
7995
7996-static void inline arch_read_unlock(arch_rwlock_t *lock)
7997+static inline void arch_read_unlock(arch_rwlock_t *lock)
7998 {
7999 unsigned long tmp1, tmp2;
8000
8001 __asm__ __volatile__(
8002 "1: lduw [%2], %0\n"
8003-" sub %0, 1, %1\n"
8004+" subcc %0, 1, %1\n"
8005+
8006+#ifdef CONFIG_PAX_REFCOUNT
8007+" tvs %%icc, 6\n"
8008+#endif
8009+
8010 " cas [%2], %0, %1\n"
8011 " cmp %0, %1\n"
8012 " bne,pn %%xcc, 1b\n"
8013@@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
8014 : "memory");
8015 }
8016
8017-static void inline arch_write_lock(arch_rwlock_t *lock)
8018+static inline void arch_write_lock(arch_rwlock_t *lock)
8019 {
8020 unsigned long mask, tmp1, tmp2;
8021
8022@@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
8023 : "memory");
8024 }
8025
8026-static void inline arch_write_unlock(arch_rwlock_t *lock)
8027+static inline void arch_write_unlock(arch_rwlock_t *lock)
8028 {
8029 __asm__ __volatile__(
8030 " stw %%g0, [%0]"
8031@@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
8032 : "memory");
8033 }
8034
8035-static int inline arch_write_trylock(arch_rwlock_t *lock)
8036+static inline int arch_write_trylock(arch_rwlock_t *lock)
8037 {
8038 unsigned long mask, tmp1, tmp2, result;
8039
8040diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
8041index 25849ae..924c54b 100644
8042--- a/arch/sparc/include/asm/thread_info_32.h
8043+++ b/arch/sparc/include/asm/thread_info_32.h
8044@@ -49,6 +49,8 @@ struct thread_info {
8045 unsigned long w_saved;
8046
8047 struct restart_block restart_block;
8048+
8049+ unsigned long lowest_stack;
8050 };
8051
8052 /*
8053diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
8054index 269bd92..e46a9b8 100644
8055--- a/arch/sparc/include/asm/thread_info_64.h
8056+++ b/arch/sparc/include/asm/thread_info_64.h
8057@@ -63,6 +63,8 @@ struct thread_info {
8058 struct pt_regs *kern_una_regs;
8059 unsigned int kern_una_insn;
8060
8061+ unsigned long lowest_stack;
8062+
8063 unsigned long fpregs[0] __attribute__ ((aligned(64)));
8064 };
8065
8066@@ -192,10 +194,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
8067 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
8068 /* flag bit 6 is available */
8069 #define TIF_32BIT 7 /* 32-bit binary */
8070-/* flag bit 8 is available */
8071+#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
8072 #define TIF_SECCOMP 9 /* secure computing */
8073 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
8074 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
8075+
8076 /* NOTE: Thread flags >= 12 should be ones we have no interest
8077 * in using in assembly, else we can't use the mask as
8078 * an immediate value in instructions such as andcc.
8079@@ -214,12 +217,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
8080 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
8081 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8082 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
8083+#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8084
8085 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
8086 _TIF_DO_NOTIFY_RESUME_MASK | \
8087 _TIF_NEED_RESCHED)
8088 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
8089
8090+#define _TIF_WORK_SYSCALL \
8091+ (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
8092+ _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
8093+
8094+
8095 /*
8096 * Thread-synchronous status.
8097 *
8098diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
8099index 0167d26..767bb0c 100644
8100--- a/arch/sparc/include/asm/uaccess.h
8101+++ b/arch/sparc/include/asm/uaccess.h
8102@@ -1,5 +1,6 @@
8103 #ifndef ___ASM_SPARC_UACCESS_H
8104 #define ___ASM_SPARC_UACCESS_H
8105+
8106 #if defined(__sparc__) && defined(__arch64__)
8107 #include <asm/uaccess_64.h>
8108 #else
8109diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
8110index 53a28dd..50c38c3 100644
8111--- a/arch/sparc/include/asm/uaccess_32.h
8112+++ b/arch/sparc/include/asm/uaccess_32.h
8113@@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
8114
8115 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8116 {
8117- if (n && __access_ok((unsigned long) to, n))
8118+ if ((long)n < 0)
8119+ return n;
8120+
8121+ if (n && __access_ok((unsigned long) to, n)) {
8122+ if (!__builtin_constant_p(n))
8123+ check_object_size(from, n, true);
8124 return __copy_user(to, (__force void __user *) from, n);
8125- else
8126+ } else
8127 return n;
8128 }
8129
8130 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
8131 {
8132+ if ((long)n < 0)
8133+ return n;
8134+
8135+ if (!__builtin_constant_p(n))
8136+ check_object_size(from, n, true);
8137+
8138 return __copy_user(to, (__force void __user *) from, n);
8139 }
8140
8141 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8142 {
8143- if (n && __access_ok((unsigned long) from, n))
8144+ if ((long)n < 0)
8145+ return n;
8146+
8147+ if (n && __access_ok((unsigned long) from, n)) {
8148+ if (!__builtin_constant_p(n))
8149+ check_object_size(to, n, false);
8150 return __copy_user((__force void __user *) to, from, n);
8151- else
8152+ } else
8153 return n;
8154 }
8155
8156 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
8157 {
8158+ if ((long)n < 0)
8159+ return n;
8160+
8161 return __copy_user((__force void __user *) to, from, n);
8162 }
8163
8164diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
8165index e562d3c..191f176 100644
8166--- a/arch/sparc/include/asm/uaccess_64.h
8167+++ b/arch/sparc/include/asm/uaccess_64.h
8168@@ -10,6 +10,7 @@
8169 #include <linux/compiler.h>
8170 #include <linux/string.h>
8171 #include <linux/thread_info.h>
8172+#include <linux/kernel.h>
8173 #include <asm/asi.h>
8174 #include <asm/spitfire.h>
8175 #include <asm-generic/uaccess-unaligned.h>
8176@@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
8177 static inline unsigned long __must_check
8178 copy_from_user(void *to, const void __user *from, unsigned long size)
8179 {
8180- unsigned long ret = ___copy_from_user(to, from, size);
8181+ unsigned long ret;
8182
8183+ if ((long)size < 0 || size > INT_MAX)
8184+ return size;
8185+
8186+ if (!__builtin_constant_p(size))
8187+ check_object_size(to, size, false);
8188+
8189+ ret = ___copy_from_user(to, from, size);
8190 if (unlikely(ret))
8191 ret = copy_from_user_fixup(to, from, size);
8192
8193@@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
8194 static inline unsigned long __must_check
8195 copy_to_user(void __user *to, const void *from, unsigned long size)
8196 {
8197- unsigned long ret = ___copy_to_user(to, from, size);
8198+ unsigned long ret;
8199
8200+ if ((long)size < 0 || size > INT_MAX)
8201+ return size;
8202+
8203+ if (!__builtin_constant_p(size))
8204+ check_object_size(from, size, true);
8205+
8206+ ret = ___copy_to_user(to, from, size);
8207 if (unlikely(ret))
8208 ret = copy_to_user_fixup(to, from, size);
8209 return ret;
8210diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
8211index 6cf591b..b49e65a 100644
8212--- a/arch/sparc/kernel/Makefile
8213+++ b/arch/sparc/kernel/Makefile
8214@@ -3,7 +3,7 @@
8215 #
8216
8217 asflags-y := -ansi
8218-ccflags-y := -Werror
8219+#ccflags-y := -Werror
8220
8221 extra-y := head_$(BITS).o
8222
8223diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
8224index 62eede1..9c5b904 100644
8225--- a/arch/sparc/kernel/process_32.c
8226+++ b/arch/sparc/kernel/process_32.c
8227@@ -125,14 +125,14 @@ void show_regs(struct pt_regs *r)
8228
8229 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
8230 r->psr, r->pc, r->npc, r->y, print_tainted());
8231- printk("PC: <%pS>\n", (void *) r->pc);
8232+ printk("PC: <%pA>\n", (void *) r->pc);
8233 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8234 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
8235 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
8236 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8237 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
8238 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
8239- printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
8240+ printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
8241
8242 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
8243 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
8244@@ -167,7 +167,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8245 rw = (struct reg_window32 *) fp;
8246 pc = rw->ins[7];
8247 printk("[%08lx : ", pc);
8248- printk("%pS ] ", (void *) pc);
8249+ printk("%pA ] ", (void *) pc);
8250 fp = rw->ins[6];
8251 } while (++count < 16);
8252 printk("\n");
8253diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
8254index cdb80b2..5ca141d 100644
8255--- a/arch/sparc/kernel/process_64.c
8256+++ b/arch/sparc/kernel/process_64.c
8257@@ -181,14 +181,14 @@ static void show_regwindow(struct pt_regs *regs)
8258 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
8259 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
8260 if (regs->tstate & TSTATE_PRIV)
8261- printk("I7: <%pS>\n", (void *) rwk->ins[7]);
8262+ printk("I7: <%pA>\n", (void *) rwk->ins[7]);
8263 }
8264
8265 void show_regs(struct pt_regs *regs)
8266 {
8267 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
8268 regs->tpc, regs->tnpc, regs->y, print_tainted());
8269- printk("TPC: <%pS>\n", (void *) regs->tpc);
8270+ printk("TPC: <%pA>\n", (void *) regs->tpc);
8271 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
8272 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
8273 regs->u_regs[3]);
8274@@ -201,7 +201,7 @@ void show_regs(struct pt_regs *regs)
8275 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
8276 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
8277 regs->u_regs[15]);
8278- printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
8279+ printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
8280 show_regwindow(regs);
8281 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
8282 }
8283@@ -290,7 +290,7 @@ void arch_trigger_all_cpu_backtrace(void)
8284 ((tp && tp->task) ? tp->task->pid : -1));
8285
8286 if (gp->tstate & TSTATE_PRIV) {
8287- printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
8288+ printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
8289 (void *) gp->tpc,
8290 (void *) gp->o7,
8291 (void *) gp->i7,
8292diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
8293index 9f20566..67eb41b 100644
8294--- a/arch/sparc/kernel/prom_common.c
8295+++ b/arch/sparc/kernel/prom_common.c
8296@@ -143,7 +143,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
8297
8298 unsigned int prom_early_allocated __initdata;
8299
8300-static struct of_pdt_ops prom_sparc_ops __initdata = {
8301+static struct of_pdt_ops prom_sparc_ops __initconst = {
8302 .nextprop = prom_common_nextprop,
8303 .getproplen = prom_getproplen,
8304 .getproperty = prom_getproperty,
8305diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
8306index 7ff45e4..a58f271 100644
8307--- a/arch/sparc/kernel/ptrace_64.c
8308+++ b/arch/sparc/kernel/ptrace_64.c
8309@@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
8310 return ret;
8311 }
8312
8313+#ifdef CONFIG_GRKERNSEC_SETXID
8314+extern void gr_delayed_cred_worker(void);
8315+#endif
8316+
8317 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8318 {
8319 int ret = 0;
8320@@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8321 /* do the secure computing check first */
8322 secure_computing_strict(regs->u_regs[UREG_G1]);
8323
8324+#ifdef CONFIG_GRKERNSEC_SETXID
8325+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8326+ gr_delayed_cred_worker();
8327+#endif
8328+
8329 if (test_thread_flag(TIF_SYSCALL_TRACE))
8330 ret = tracehook_report_syscall_entry(regs);
8331
8332@@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
8333
8334 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
8335 {
8336+#ifdef CONFIG_GRKERNSEC_SETXID
8337+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8338+ gr_delayed_cred_worker();
8339+#endif
8340+
8341 audit_syscall_exit(regs);
8342
8343 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8344diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
8345index 3a8d184..49498a8 100644
8346--- a/arch/sparc/kernel/sys_sparc_32.c
8347+++ b/arch/sparc/kernel/sys_sparc_32.c
8348@@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8349 if (len > TASK_SIZE - PAGE_SIZE)
8350 return -ENOMEM;
8351 if (!addr)
8352- addr = TASK_UNMAPPED_BASE;
8353+ addr = current->mm->mmap_base;
8354
8355 info.flags = 0;
8356 info.length = len;
8357diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
8358index 708bc29..6bfdfad 100644
8359--- a/arch/sparc/kernel/sys_sparc_64.c
8360+++ b/arch/sparc/kernel/sys_sparc_64.c
8361@@ -90,13 +90,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8362 struct vm_area_struct * vma;
8363 unsigned long task_size = TASK_SIZE;
8364 int do_color_align;
8365+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8366 struct vm_unmapped_area_info info;
8367
8368 if (flags & MAP_FIXED) {
8369 /* We do not accept a shared mapping if it would violate
8370 * cache aliasing constraints.
8371 */
8372- if ((flags & MAP_SHARED) &&
8373+ if ((filp || (flags & MAP_SHARED)) &&
8374 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8375 return -EINVAL;
8376 return addr;
8377@@ -111,6 +112,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8378 if (filp || (flags & MAP_SHARED))
8379 do_color_align = 1;
8380
8381+#ifdef CONFIG_PAX_RANDMMAP
8382+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8383+#endif
8384+
8385 if (addr) {
8386 if (do_color_align)
8387 addr = COLOR_ALIGN(addr, pgoff);
8388@@ -118,22 +123,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
8389 addr = PAGE_ALIGN(addr);
8390
8391 vma = find_vma(mm, addr);
8392- if (task_size - len >= addr &&
8393- (!vma || addr + len <= vma->vm_start))
8394+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8395 return addr;
8396 }
8397
8398 info.flags = 0;
8399 info.length = len;
8400- info.low_limit = TASK_UNMAPPED_BASE;
8401+ info.low_limit = mm->mmap_base;
8402 info.high_limit = min(task_size, VA_EXCLUDE_START);
8403 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8404 info.align_offset = pgoff << PAGE_SHIFT;
8405+ info.threadstack_offset = offset;
8406 addr = vm_unmapped_area(&info);
8407
8408 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
8409 VM_BUG_ON(addr != -ENOMEM);
8410 info.low_limit = VA_EXCLUDE_END;
8411+
8412+#ifdef CONFIG_PAX_RANDMMAP
8413+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8414+ info.low_limit += mm->delta_mmap;
8415+#endif
8416+
8417 info.high_limit = task_size;
8418 addr = vm_unmapped_area(&info);
8419 }
8420@@ -151,6 +162,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8421 unsigned long task_size = STACK_TOP32;
8422 unsigned long addr = addr0;
8423 int do_color_align;
8424+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8425 struct vm_unmapped_area_info info;
8426
8427 /* This should only ever run for 32-bit processes. */
8428@@ -160,7 +172,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8429 /* We do not accept a shared mapping if it would violate
8430 * cache aliasing constraints.
8431 */
8432- if ((flags & MAP_SHARED) &&
8433+ if ((filp || (flags & MAP_SHARED)) &&
8434 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
8435 return -EINVAL;
8436 return addr;
8437@@ -173,6 +185,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8438 if (filp || (flags & MAP_SHARED))
8439 do_color_align = 1;
8440
8441+#ifdef CONFIG_PAX_RANDMMAP
8442+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8443+#endif
8444+
8445 /* requesting a specific address */
8446 if (addr) {
8447 if (do_color_align)
8448@@ -181,8 +197,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8449 addr = PAGE_ALIGN(addr);
8450
8451 vma = find_vma(mm, addr);
8452- if (task_size - len >= addr &&
8453- (!vma || addr + len <= vma->vm_start))
8454+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8455 return addr;
8456 }
8457
8458@@ -192,6 +207,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8459 info.high_limit = mm->mmap_base;
8460 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
8461 info.align_offset = pgoff << PAGE_SHIFT;
8462+ info.threadstack_offset = offset;
8463 addr = vm_unmapped_area(&info);
8464
8465 /*
8466@@ -204,6 +220,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8467 VM_BUG_ON(addr != -ENOMEM);
8468 info.flags = 0;
8469 info.low_limit = TASK_UNMAPPED_BASE;
8470+
8471+#ifdef CONFIG_PAX_RANDMMAP
8472+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8473+ info.low_limit += mm->delta_mmap;
8474+#endif
8475+
8476 info.high_limit = STACK_TOP32;
8477 addr = vm_unmapped_area(&info);
8478 }
8479@@ -264,6 +286,10 @@ static unsigned long mmap_rnd(void)
8480 {
8481 unsigned long rnd = 0UL;
8482
8483+#ifdef CONFIG_PAX_RANDMMAP
8484+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8485+#endif
8486+
8487 if (current->flags & PF_RANDOMIZE) {
8488 unsigned long val = get_random_int();
8489 if (test_thread_flag(TIF_32BIT))
8490@@ -289,6 +315,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8491 gap == RLIM_INFINITY ||
8492 sysctl_legacy_va_layout) {
8493 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
8494+
8495+#ifdef CONFIG_PAX_RANDMMAP
8496+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8497+ mm->mmap_base += mm->delta_mmap;
8498+#endif
8499+
8500 mm->get_unmapped_area = arch_get_unmapped_area;
8501 mm->unmap_area = arch_unmap_area;
8502 } else {
8503@@ -301,6 +333,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8504 gap = (task_size / 6 * 5);
8505
8506 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
8507+
8508+#ifdef CONFIG_PAX_RANDMMAP
8509+ if (mm->pax_flags & MF_PAX_RANDMMAP)
8510+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8511+#endif
8512+
8513 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8514 mm->unmap_area = arch_unmap_area_topdown;
8515 }
8516diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
8517index 22a1098..6255eb9 100644
8518--- a/arch/sparc/kernel/syscalls.S
8519+++ b/arch/sparc/kernel/syscalls.S
8520@@ -52,7 +52,7 @@ sys32_rt_sigreturn:
8521 #endif
8522 .align 32
8523 1: ldx [%g6 + TI_FLAGS], %l5
8524- andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8525+ andcc %l5, _TIF_WORK_SYSCALL, %g0
8526 be,pt %icc, rtrap
8527 nop
8528 call syscall_trace_leave
8529@@ -184,7 +184,7 @@ linux_sparc_syscall32:
8530
8531 srl %i5, 0, %o5 ! IEU1
8532 srl %i2, 0, %o2 ! IEU0 Group
8533- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8534+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8535 bne,pn %icc, linux_syscall_trace32 ! CTI
8536 mov %i0, %l5 ! IEU1
8537 call %l7 ! CTI Group brk forced
8538@@ -207,7 +207,7 @@ linux_sparc_syscall:
8539
8540 mov %i3, %o3 ! IEU1
8541 mov %i4, %o4 ! IEU0 Group
8542- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8543+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8544 bne,pn %icc, linux_syscall_trace ! CTI Group
8545 mov %i0, %l5 ! IEU0
8546 2: call %l7 ! CTI Group brk forced
8547@@ -223,7 +223,7 @@ ret_sys_call:
8548
8549 cmp %o0, -ERESTART_RESTARTBLOCK
8550 bgeu,pn %xcc, 1f
8551- andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
8552+ andcc %l0, _TIF_WORK_SYSCALL, %g0
8553 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
8554
8555 2:
8556diff --git a/arch/sparc/kernel/sysfs.c b/arch/sparc/kernel/sysfs.c
8557index 654e8aa..45f431b 100644
8558--- a/arch/sparc/kernel/sysfs.c
8559+++ b/arch/sparc/kernel/sysfs.c
8560@@ -266,7 +266,7 @@ static int __cpuinit sysfs_cpu_notify(struct notifier_block *self,
8561 return NOTIFY_OK;
8562 }
8563
8564-static struct notifier_block __cpuinitdata sysfs_cpu_nb = {
8565+static struct notifier_block sysfs_cpu_nb = {
8566 .notifier_call = sysfs_cpu_notify,
8567 };
8568
8569diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
8570index 6629829..036032d 100644
8571--- a/arch/sparc/kernel/traps_32.c
8572+++ b/arch/sparc/kernel/traps_32.c
8573@@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
8574 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
8575 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
8576
8577+extern void gr_handle_kernel_exploit(void);
8578+
8579 void die_if_kernel(char *str, struct pt_regs *regs)
8580 {
8581 static int die_counter;
8582@@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8583 count++ < 30 &&
8584 (((unsigned long) rw) >= PAGE_OFFSET) &&
8585 !(((unsigned long) rw) & 0x7)) {
8586- printk("Caller[%08lx]: %pS\n", rw->ins[7],
8587+ printk("Caller[%08lx]: %pA\n", rw->ins[7],
8588 (void *) rw->ins[7]);
8589 rw = (struct reg_window32 *)rw->ins[6];
8590 }
8591 }
8592 printk("Instruction DUMP:");
8593 instruction_dump ((unsigned long *) regs->pc);
8594- if(regs->psr & PSR_PS)
8595+ if(regs->psr & PSR_PS) {
8596+ gr_handle_kernel_exploit();
8597 do_exit(SIGKILL);
8598+ }
8599 do_exit(SIGSEGV);
8600 }
8601
8602diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
8603index 8d38ca9..845b1d6 100644
8604--- a/arch/sparc/kernel/traps_64.c
8605+++ b/arch/sparc/kernel/traps_64.c
8606@@ -76,7 +76,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
8607 i + 1,
8608 p->trapstack[i].tstate, p->trapstack[i].tpc,
8609 p->trapstack[i].tnpc, p->trapstack[i].tt);
8610- printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
8611+ printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
8612 }
8613 }
8614
8615@@ -96,6 +96,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
8616
8617 lvl -= 0x100;
8618 if (regs->tstate & TSTATE_PRIV) {
8619+
8620+#ifdef CONFIG_PAX_REFCOUNT
8621+ if (lvl == 6)
8622+ pax_report_refcount_overflow(regs);
8623+#endif
8624+
8625 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
8626 die_if_kernel(buffer, regs);
8627 }
8628@@ -114,11 +120,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
8629 void bad_trap_tl1(struct pt_regs *regs, long lvl)
8630 {
8631 char buffer[32];
8632-
8633+
8634 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
8635 0, lvl, SIGTRAP) == NOTIFY_STOP)
8636 return;
8637
8638+#ifdef CONFIG_PAX_REFCOUNT
8639+ if (lvl == 6)
8640+ pax_report_refcount_overflow(regs);
8641+#endif
8642+
8643 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
8644
8645 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
8646@@ -1142,7 +1153,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
8647 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
8648 printk("%s" "ERROR(%d): ",
8649 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
8650- printk("TPC<%pS>\n", (void *) regs->tpc);
8651+ printk("TPC<%pA>\n", (void *) regs->tpc);
8652 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
8653 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
8654 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
8655@@ -1749,7 +1760,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8656 smp_processor_id(),
8657 (type & 0x1) ? 'I' : 'D',
8658 regs->tpc);
8659- printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
8660+ printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
8661 panic("Irrecoverable Cheetah+ parity error.");
8662 }
8663
8664@@ -1757,7 +1768,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
8665 smp_processor_id(),
8666 (type & 0x1) ? 'I' : 'D',
8667 regs->tpc);
8668- printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
8669+ printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
8670 }
8671
8672 struct sun4v_error_entry {
8673@@ -2104,9 +2115,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
8674
8675 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
8676 regs->tpc, tl);
8677- printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
8678+ printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
8679 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8680- printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
8681+ printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
8682 (void *) regs->u_regs[UREG_I7]);
8683 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
8684 "pte[%lx] error[%lx]\n",
8685@@ -2128,9 +2139,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
8686
8687 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
8688 regs->tpc, tl);
8689- printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
8690+ printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
8691 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
8692- printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
8693+ printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
8694 (void *) regs->u_regs[UREG_I7]);
8695 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
8696 "pte[%lx] error[%lx]\n",
8697@@ -2336,13 +2347,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
8698 fp = (unsigned long)sf->fp + STACK_BIAS;
8699 }
8700
8701- printk(" [%016lx] %pS\n", pc, (void *) pc);
8702+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8703 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8704 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
8705 int index = tsk->curr_ret_stack;
8706 if (tsk->ret_stack && index >= graph) {
8707 pc = tsk->ret_stack[index - graph].ret;
8708- printk(" [%016lx] %pS\n", pc, (void *) pc);
8709+ printk(" [%016lx] %pA\n", pc, (void *) pc);
8710 graph++;
8711 }
8712 }
8713@@ -2367,6 +2378,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
8714 return (struct reg_window *) (fp + STACK_BIAS);
8715 }
8716
8717+extern void gr_handle_kernel_exploit(void);
8718+
8719 void die_if_kernel(char *str, struct pt_regs *regs)
8720 {
8721 static int die_counter;
8722@@ -2395,7 +2408,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8723 while (rw &&
8724 count++ < 30 &&
8725 kstack_valid(tp, (unsigned long) rw)) {
8726- printk("Caller[%016lx]: %pS\n", rw->ins[7],
8727+ printk("Caller[%016lx]: %pA\n", rw->ins[7],
8728 (void *) rw->ins[7]);
8729
8730 rw = kernel_stack_up(rw);
8731@@ -2408,8 +2421,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
8732 }
8733 user_instruction_dump ((unsigned int __user *) regs->tpc);
8734 }
8735- if (regs->tstate & TSTATE_PRIV)
8736+ if (regs->tstate & TSTATE_PRIV) {
8737+ gr_handle_kernel_exploit();
8738 do_exit(SIGKILL);
8739+ }
8740 do_exit(SIGSEGV);
8741 }
8742 EXPORT_SYMBOL(die_if_kernel);
8743diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
8744index 8201c25e..072a2a7 100644
8745--- a/arch/sparc/kernel/unaligned_64.c
8746+++ b/arch/sparc/kernel/unaligned_64.c
8747@@ -286,7 +286,7 @@ static void log_unaligned(struct pt_regs *regs)
8748 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
8749
8750 if (__ratelimit(&ratelimit)) {
8751- printk("Kernel unaligned access at TPC[%lx] %pS\n",
8752+ printk("Kernel unaligned access at TPC[%lx] %pA\n",
8753 regs->tpc, (void *) regs->tpc);
8754 }
8755 }
8756diff --git a/arch/sparc/kernel/us3_cpufreq.c b/arch/sparc/kernel/us3_cpufreq.c
8757index eb1624b..55100de 100644
8758--- a/arch/sparc/kernel/us3_cpufreq.c
8759+++ b/arch/sparc/kernel/us3_cpufreq.c
8760@@ -18,14 +18,12 @@
8761 #include <asm/head.h>
8762 #include <asm/timer.h>
8763
8764-static struct cpufreq_driver *cpufreq_us3_driver;
8765-
8766 struct us3_freq_percpu_info {
8767 struct cpufreq_frequency_table table[4];
8768 };
8769
8770 /* Indexed by cpu number. */
8771-static struct us3_freq_percpu_info *us3_freq_table;
8772+static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
8773
8774 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
8775 * in the Safari config register.
8776@@ -191,12 +189,25 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
8777
8778 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
8779 {
8780- if (cpufreq_us3_driver)
8781- us3_set_cpu_divider_index(policy->cpu, 0);
8782+ us3_set_cpu_divider_index(policy->cpu, 0);
8783
8784 return 0;
8785 }
8786
8787+static int __init us3_freq_init(void);
8788+static void __exit us3_freq_exit(void);
8789+
8790+static struct cpufreq_driver cpufreq_us3_driver = {
8791+ .init = us3_freq_cpu_init,
8792+ .verify = us3_freq_verify,
8793+ .target = us3_freq_target,
8794+ .get = us3_freq_get,
8795+ .exit = us3_freq_cpu_exit,
8796+ .owner = THIS_MODULE,
8797+ .name = "UltraSPARC-III",
8798+
8799+};
8800+
8801 static int __init us3_freq_init(void)
8802 {
8803 unsigned long manuf, impl, ver;
8804@@ -213,57 +224,15 @@ static int __init us3_freq_init(void)
8805 (impl == CHEETAH_IMPL ||
8806 impl == CHEETAH_PLUS_IMPL ||
8807 impl == JAGUAR_IMPL ||
8808- impl == PANTHER_IMPL)) {
8809- struct cpufreq_driver *driver;
8810-
8811- ret = -ENOMEM;
8812- driver = kzalloc(sizeof(struct cpufreq_driver), GFP_KERNEL);
8813- if (!driver)
8814- goto err_out;
8815-
8816- us3_freq_table = kzalloc(
8817- (NR_CPUS * sizeof(struct us3_freq_percpu_info)),
8818- GFP_KERNEL);
8819- if (!us3_freq_table)
8820- goto err_out;
8821-
8822- driver->init = us3_freq_cpu_init;
8823- driver->verify = us3_freq_verify;
8824- driver->target = us3_freq_target;
8825- driver->get = us3_freq_get;
8826- driver->exit = us3_freq_cpu_exit;
8827- driver->owner = THIS_MODULE,
8828- strcpy(driver->name, "UltraSPARC-III");
8829-
8830- cpufreq_us3_driver = driver;
8831- ret = cpufreq_register_driver(driver);
8832- if (ret)
8833- goto err_out;
8834-
8835- return 0;
8836-
8837-err_out:
8838- if (driver) {
8839- kfree(driver);
8840- cpufreq_us3_driver = NULL;
8841- }
8842- kfree(us3_freq_table);
8843- us3_freq_table = NULL;
8844- return ret;
8845- }
8846+ impl == PANTHER_IMPL))
8847+ return cpufreq_register_driver(&cpufreq_us3_driver);
8848
8849 return -ENODEV;
8850 }
8851
8852 static void __exit us3_freq_exit(void)
8853 {
8854- if (cpufreq_us3_driver) {
8855- cpufreq_unregister_driver(cpufreq_us3_driver);
8856- kfree(cpufreq_us3_driver);
8857- cpufreq_us3_driver = NULL;
8858- kfree(us3_freq_table);
8859- us3_freq_table = NULL;
8860- }
8861+ cpufreq_unregister_driver(&cpufreq_us3_driver);
8862 }
8863
8864 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
8865diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
8866index 8410065f2..4fd4ca22 100644
8867--- a/arch/sparc/lib/Makefile
8868+++ b/arch/sparc/lib/Makefile
8869@@ -2,7 +2,7 @@
8870 #
8871
8872 asflags-y := -ansi -DST_DIV0=0x02
8873-ccflags-y := -Werror
8874+#ccflags-y := -Werror
8875
8876 lib-$(CONFIG_SPARC32) += ashrdi3.o
8877 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
8878diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
8879index 85c233d..68500e0 100644
8880--- a/arch/sparc/lib/atomic_64.S
8881+++ b/arch/sparc/lib/atomic_64.S
8882@@ -17,7 +17,12 @@
8883 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8884 BACKOFF_SETUP(%o2)
8885 1: lduw [%o1], %g1
8886- add %g1, %o0, %g7
8887+ addcc %g1, %o0, %g7
8888+
8889+#ifdef CONFIG_PAX_REFCOUNT
8890+ tvs %icc, 6
8891+#endif
8892+
8893 cas [%o1], %g1, %g7
8894 cmp %g1, %g7
8895 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8896@@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
8897 2: BACKOFF_SPIN(%o2, %o3, 1b)
8898 ENDPROC(atomic_add)
8899
8900+ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8901+ BACKOFF_SETUP(%o2)
8902+1: lduw [%o1], %g1
8903+ add %g1, %o0, %g7
8904+ cas [%o1], %g1, %g7
8905+ cmp %g1, %g7
8906+ bne,pn %icc, 2f
8907+ nop
8908+ retl
8909+ nop
8910+2: BACKOFF_SPIN(%o2, %o3, 1b)
8911+ENDPROC(atomic_add_unchecked)
8912+
8913 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8914 BACKOFF_SETUP(%o2)
8915 1: lduw [%o1], %g1
8916- sub %g1, %o0, %g7
8917+ subcc %g1, %o0, %g7
8918+
8919+#ifdef CONFIG_PAX_REFCOUNT
8920+ tvs %icc, 6
8921+#endif
8922+
8923 cas [%o1], %g1, %g7
8924 cmp %g1, %g7
8925 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8926@@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
8927 2: BACKOFF_SPIN(%o2, %o3, 1b)
8928 ENDPROC(atomic_sub)
8929
8930+ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
8931+ BACKOFF_SETUP(%o2)
8932+1: lduw [%o1], %g1
8933+ sub %g1, %o0, %g7
8934+ cas [%o1], %g1, %g7
8935+ cmp %g1, %g7
8936+ bne,pn %icc, 2f
8937+ nop
8938+ retl
8939+ nop
8940+2: BACKOFF_SPIN(%o2, %o3, 1b)
8941+ENDPROC(atomic_sub_unchecked)
8942+
8943 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8944 BACKOFF_SETUP(%o2)
8945 1: lduw [%o1], %g1
8946- add %g1, %o0, %g7
8947+ addcc %g1, %o0, %g7
8948+
8949+#ifdef CONFIG_PAX_REFCOUNT
8950+ tvs %icc, 6
8951+#endif
8952+
8953 cas [%o1], %g1, %g7
8954 cmp %g1, %g7
8955 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8956@@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
8957 2: BACKOFF_SPIN(%o2, %o3, 1b)
8958 ENDPROC(atomic_add_ret)
8959
8960+ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
8961+ BACKOFF_SETUP(%o2)
8962+1: lduw [%o1], %g1
8963+ addcc %g1, %o0, %g7
8964+ cas [%o1], %g1, %g7
8965+ cmp %g1, %g7
8966+ bne,pn %icc, 2f
8967+ add %g7, %o0, %g7
8968+ sra %g7, 0, %o0
8969+ retl
8970+ nop
8971+2: BACKOFF_SPIN(%o2, %o3, 1b)
8972+ENDPROC(atomic_add_ret_unchecked)
8973+
8974 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
8975 BACKOFF_SETUP(%o2)
8976 1: lduw [%o1], %g1
8977- sub %g1, %o0, %g7
8978+ subcc %g1, %o0, %g7
8979+
8980+#ifdef CONFIG_PAX_REFCOUNT
8981+ tvs %icc, 6
8982+#endif
8983+
8984 cas [%o1], %g1, %g7
8985 cmp %g1, %g7
8986 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
8987@@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
8988 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
8989 BACKOFF_SETUP(%o2)
8990 1: ldx [%o1], %g1
8991- add %g1, %o0, %g7
8992+ addcc %g1, %o0, %g7
8993+
8994+#ifdef CONFIG_PAX_REFCOUNT
8995+ tvs %xcc, 6
8996+#endif
8997+
8998 casx [%o1], %g1, %g7
8999 cmp %g1, %g7
9000 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9001@@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
9002 2: BACKOFF_SPIN(%o2, %o3, 1b)
9003 ENDPROC(atomic64_add)
9004
9005+ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9006+ BACKOFF_SETUP(%o2)
9007+1: ldx [%o1], %g1
9008+ addcc %g1, %o0, %g7
9009+ casx [%o1], %g1, %g7
9010+ cmp %g1, %g7
9011+ bne,pn %xcc, 2f
9012+ nop
9013+ retl
9014+ nop
9015+2: BACKOFF_SPIN(%o2, %o3, 1b)
9016+ENDPROC(atomic64_add_unchecked)
9017+
9018 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9019 BACKOFF_SETUP(%o2)
9020 1: ldx [%o1], %g1
9021- sub %g1, %o0, %g7
9022+ subcc %g1, %o0, %g7
9023+
9024+#ifdef CONFIG_PAX_REFCOUNT
9025+ tvs %xcc, 6
9026+#endif
9027+
9028 casx [%o1], %g1, %g7
9029 cmp %g1, %g7
9030 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9031@@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
9032 2: BACKOFF_SPIN(%o2, %o3, 1b)
9033 ENDPROC(atomic64_sub)
9034
9035+ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
9036+ BACKOFF_SETUP(%o2)
9037+1: ldx [%o1], %g1
9038+ subcc %g1, %o0, %g7
9039+ casx [%o1], %g1, %g7
9040+ cmp %g1, %g7
9041+ bne,pn %xcc, 2f
9042+ nop
9043+ retl
9044+ nop
9045+2: BACKOFF_SPIN(%o2, %o3, 1b)
9046+ENDPROC(atomic64_sub_unchecked)
9047+
9048 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9049 BACKOFF_SETUP(%o2)
9050 1: ldx [%o1], %g1
9051- add %g1, %o0, %g7
9052+ addcc %g1, %o0, %g7
9053+
9054+#ifdef CONFIG_PAX_REFCOUNT
9055+ tvs %xcc, 6
9056+#endif
9057+
9058 casx [%o1], %g1, %g7
9059 cmp %g1, %g7
9060 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9061@@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
9062 2: BACKOFF_SPIN(%o2, %o3, 1b)
9063 ENDPROC(atomic64_add_ret)
9064
9065+ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
9066+ BACKOFF_SETUP(%o2)
9067+1: ldx [%o1], %g1
9068+ addcc %g1, %o0, %g7
9069+ casx [%o1], %g1, %g7
9070+ cmp %g1, %g7
9071+ bne,pn %xcc, 2f
9072+ add %g7, %o0, %g7
9073+ mov %g7, %o0
9074+ retl
9075+ nop
9076+2: BACKOFF_SPIN(%o2, %o3, 1b)
9077+ENDPROC(atomic64_add_ret_unchecked)
9078+
9079 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
9080 BACKOFF_SETUP(%o2)
9081 1: ldx [%o1], %g1
9082- sub %g1, %o0, %g7
9083+ subcc %g1, %o0, %g7
9084+
9085+#ifdef CONFIG_PAX_REFCOUNT
9086+ tvs %xcc, 6
9087+#endif
9088+
9089 casx [%o1], %g1, %g7
9090 cmp %g1, %g7
9091 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
9092diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
9093index 0c4e35e..745d3e4 100644
9094--- a/arch/sparc/lib/ksyms.c
9095+++ b/arch/sparc/lib/ksyms.c
9096@@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
9097
9098 /* Atomic counter implementation. */
9099 EXPORT_SYMBOL(atomic_add);
9100+EXPORT_SYMBOL(atomic_add_unchecked);
9101 EXPORT_SYMBOL(atomic_add_ret);
9102+EXPORT_SYMBOL(atomic_add_ret_unchecked);
9103 EXPORT_SYMBOL(atomic_sub);
9104+EXPORT_SYMBOL(atomic_sub_unchecked);
9105 EXPORT_SYMBOL(atomic_sub_ret);
9106 EXPORT_SYMBOL(atomic64_add);
9107+EXPORT_SYMBOL(atomic64_add_unchecked);
9108 EXPORT_SYMBOL(atomic64_add_ret);
9109+EXPORT_SYMBOL(atomic64_add_ret_unchecked);
9110 EXPORT_SYMBOL(atomic64_sub);
9111+EXPORT_SYMBOL(atomic64_sub_unchecked);
9112 EXPORT_SYMBOL(atomic64_sub_ret);
9113 EXPORT_SYMBOL(atomic64_dec_if_positive);
9114
9115diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
9116index 30c3ecc..736f015 100644
9117--- a/arch/sparc/mm/Makefile
9118+++ b/arch/sparc/mm/Makefile
9119@@ -2,7 +2,7 @@
9120 #
9121
9122 asflags-y := -ansi
9123-ccflags-y := -Werror
9124+#ccflags-y := -Werror
9125
9126 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
9127 obj-y += fault_$(BITS).o
9128diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
9129index e98bfda..ea8d221 100644
9130--- a/arch/sparc/mm/fault_32.c
9131+++ b/arch/sparc/mm/fault_32.c
9132@@ -21,6 +21,9 @@
9133 #include <linux/perf_event.h>
9134 #include <linux/interrupt.h>
9135 #include <linux/kdebug.h>
9136+#include <linux/slab.h>
9137+#include <linux/pagemap.h>
9138+#include <linux/compiler.h>
9139
9140 #include <asm/page.h>
9141 #include <asm/pgtable.h>
9142@@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
9143 return safe_compute_effective_address(regs, insn);
9144 }
9145
9146+#ifdef CONFIG_PAX_PAGEEXEC
9147+#ifdef CONFIG_PAX_DLRESOLVE
9148+static void pax_emuplt_close(struct vm_area_struct *vma)
9149+{
9150+ vma->vm_mm->call_dl_resolve = 0UL;
9151+}
9152+
9153+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9154+{
9155+ unsigned int *kaddr;
9156+
9157+ vmf->page = alloc_page(GFP_HIGHUSER);
9158+ if (!vmf->page)
9159+ return VM_FAULT_OOM;
9160+
9161+ kaddr = kmap(vmf->page);
9162+ memset(kaddr, 0, PAGE_SIZE);
9163+ kaddr[0] = 0x9DE3BFA8U; /* save */
9164+ flush_dcache_page(vmf->page);
9165+ kunmap(vmf->page);
9166+ return VM_FAULT_MAJOR;
9167+}
9168+
9169+static const struct vm_operations_struct pax_vm_ops = {
9170+ .close = pax_emuplt_close,
9171+ .fault = pax_emuplt_fault
9172+};
9173+
9174+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9175+{
9176+ int ret;
9177+
9178+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9179+ vma->vm_mm = current->mm;
9180+ vma->vm_start = addr;
9181+ vma->vm_end = addr + PAGE_SIZE;
9182+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9183+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9184+ vma->vm_ops = &pax_vm_ops;
9185+
9186+ ret = insert_vm_struct(current->mm, vma);
9187+ if (ret)
9188+ return ret;
9189+
9190+ ++current->mm->total_vm;
9191+ return 0;
9192+}
9193+#endif
9194+
9195+/*
9196+ * PaX: decide what to do with offenders (regs->pc = fault address)
9197+ *
9198+ * returns 1 when task should be killed
9199+ * 2 when patched PLT trampoline was detected
9200+ * 3 when unpatched PLT trampoline was detected
9201+ */
9202+static int pax_handle_fetch_fault(struct pt_regs *regs)
9203+{
9204+
9205+#ifdef CONFIG_PAX_EMUPLT
9206+ int err;
9207+
9208+ do { /* PaX: patched PLT emulation #1 */
9209+ unsigned int sethi1, sethi2, jmpl;
9210+
9211+ err = get_user(sethi1, (unsigned int *)regs->pc);
9212+ err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
9213+ err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
9214+
9215+ if (err)
9216+ break;
9217+
9218+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9219+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9220+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9221+ {
9222+ unsigned int addr;
9223+
9224+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9225+ addr = regs->u_regs[UREG_G1];
9226+ addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9227+ regs->pc = addr;
9228+ regs->npc = addr+4;
9229+ return 2;
9230+ }
9231+ } while (0);
9232+
9233+ do { /* PaX: patched PLT emulation #2 */
9234+ unsigned int ba;
9235+
9236+ err = get_user(ba, (unsigned int *)regs->pc);
9237+
9238+ if (err)
9239+ break;
9240+
9241+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9242+ unsigned int addr;
9243+
9244+ if ((ba & 0xFFC00000U) == 0x30800000U)
9245+ addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9246+ else
9247+ addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9248+ regs->pc = addr;
9249+ regs->npc = addr+4;
9250+ return 2;
9251+ }
9252+ } while (0);
9253+
9254+ do { /* PaX: patched PLT emulation #3 */
9255+ unsigned int sethi, bajmpl, nop;
9256+
9257+ err = get_user(sethi, (unsigned int *)regs->pc);
9258+ err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
9259+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9260+
9261+ if (err)
9262+ break;
9263+
9264+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9265+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9266+ nop == 0x01000000U)
9267+ {
9268+ unsigned int addr;
9269+
9270+ addr = (sethi & 0x003FFFFFU) << 10;
9271+ regs->u_regs[UREG_G1] = addr;
9272+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9273+ addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9274+ else
9275+ addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9276+ regs->pc = addr;
9277+ regs->npc = addr+4;
9278+ return 2;
9279+ }
9280+ } while (0);
9281+
9282+ do { /* PaX: unpatched PLT emulation step 1 */
9283+ unsigned int sethi, ba, nop;
9284+
9285+ err = get_user(sethi, (unsigned int *)regs->pc);
9286+ err |= get_user(ba, (unsigned int *)(regs->pc+4));
9287+ err |= get_user(nop, (unsigned int *)(regs->pc+8));
9288+
9289+ if (err)
9290+ break;
9291+
9292+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9293+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9294+ nop == 0x01000000U)
9295+ {
9296+ unsigned int addr, save, call;
9297+
9298+ if ((ba & 0xFFC00000U) == 0x30800000U)
9299+ addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
9300+ else
9301+ addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
9302+
9303+ err = get_user(save, (unsigned int *)addr);
9304+ err |= get_user(call, (unsigned int *)(addr+4));
9305+ err |= get_user(nop, (unsigned int *)(addr+8));
9306+ if (err)
9307+ break;
9308+
9309+#ifdef CONFIG_PAX_DLRESOLVE
9310+ if (save == 0x9DE3BFA8U &&
9311+ (call & 0xC0000000U) == 0x40000000U &&
9312+ nop == 0x01000000U)
9313+ {
9314+ struct vm_area_struct *vma;
9315+ unsigned long call_dl_resolve;
9316+
9317+ down_read(&current->mm->mmap_sem);
9318+ call_dl_resolve = current->mm->call_dl_resolve;
9319+ up_read(&current->mm->mmap_sem);
9320+ if (likely(call_dl_resolve))
9321+ goto emulate;
9322+
9323+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9324+
9325+ down_write(&current->mm->mmap_sem);
9326+ if (current->mm->call_dl_resolve) {
9327+ call_dl_resolve = current->mm->call_dl_resolve;
9328+ up_write(&current->mm->mmap_sem);
9329+ if (vma)
9330+ kmem_cache_free(vm_area_cachep, vma);
9331+ goto emulate;
9332+ }
9333+
9334+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9335+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9336+ up_write(&current->mm->mmap_sem);
9337+ if (vma)
9338+ kmem_cache_free(vm_area_cachep, vma);
9339+ return 1;
9340+ }
9341+
9342+ if (pax_insert_vma(vma, call_dl_resolve)) {
9343+ up_write(&current->mm->mmap_sem);
9344+ kmem_cache_free(vm_area_cachep, vma);
9345+ return 1;
9346+ }
9347+
9348+ current->mm->call_dl_resolve = call_dl_resolve;
9349+ up_write(&current->mm->mmap_sem);
9350+
9351+emulate:
9352+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9353+ regs->pc = call_dl_resolve;
9354+ regs->npc = addr+4;
9355+ return 3;
9356+ }
9357+#endif
9358+
9359+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9360+ if ((save & 0xFFC00000U) == 0x05000000U &&
9361+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9362+ nop == 0x01000000U)
9363+ {
9364+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9365+ regs->u_regs[UREG_G2] = addr + 4;
9366+ addr = (save & 0x003FFFFFU) << 10;
9367+ addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
9368+ regs->pc = addr;
9369+ regs->npc = addr+4;
9370+ return 3;
9371+ }
9372+ }
9373+ } while (0);
9374+
9375+ do { /* PaX: unpatched PLT emulation step 2 */
9376+ unsigned int save, call, nop;
9377+
9378+ err = get_user(save, (unsigned int *)(regs->pc-4));
9379+ err |= get_user(call, (unsigned int *)regs->pc);
9380+ err |= get_user(nop, (unsigned int *)(regs->pc+4));
9381+ if (err)
9382+ break;
9383+
9384+ if (save == 0x9DE3BFA8U &&
9385+ (call & 0xC0000000U) == 0x40000000U &&
9386+ nop == 0x01000000U)
9387+ {
9388+ unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
9389+
9390+ regs->u_regs[UREG_RETPC] = regs->pc;
9391+ regs->pc = dl_resolve;
9392+ regs->npc = dl_resolve+4;
9393+ return 3;
9394+ }
9395+ } while (0);
9396+#endif
9397+
9398+ return 1;
9399+}
9400+
9401+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9402+{
9403+ unsigned long i;
9404+
9405+ printk(KERN_ERR "PAX: bytes at PC: ");
9406+ for (i = 0; i < 8; i++) {
9407+ unsigned int c;
9408+ if (get_user(c, (unsigned int *)pc+i))
9409+ printk(KERN_CONT "???????? ");
9410+ else
9411+ printk(KERN_CONT "%08x ", c);
9412+ }
9413+ printk("\n");
9414+}
9415+#endif
9416+
9417 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
9418 int text_fault)
9419 {
9420@@ -230,6 +504,24 @@ good_area:
9421 if (!(vma->vm_flags & VM_WRITE))
9422 goto bad_area;
9423 } else {
9424+
9425+#ifdef CONFIG_PAX_PAGEEXEC
9426+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
9427+ up_read(&mm->mmap_sem);
9428+ switch (pax_handle_fetch_fault(regs)) {
9429+
9430+#ifdef CONFIG_PAX_EMUPLT
9431+ case 2:
9432+ case 3:
9433+ return;
9434+#endif
9435+
9436+ }
9437+ pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
9438+ do_group_exit(SIGKILL);
9439+ }
9440+#endif
9441+
9442 /* Allow reads even for write-only mappings */
9443 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
9444 goto bad_area;
9445diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
9446index 5062ff3..e0b75f3 100644
9447--- a/arch/sparc/mm/fault_64.c
9448+++ b/arch/sparc/mm/fault_64.c
9449@@ -21,6 +21,9 @@
9450 #include <linux/kprobes.h>
9451 #include <linux/kdebug.h>
9452 #include <linux/percpu.h>
9453+#include <linux/slab.h>
9454+#include <linux/pagemap.h>
9455+#include <linux/compiler.h>
9456
9457 #include <asm/page.h>
9458 #include <asm/pgtable.h>
9459@@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
9460 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
9461 regs->tpc);
9462 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
9463- printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
9464+ printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
9465 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
9466 dump_stack();
9467 unhandled_fault(regs->tpc, current, regs);
9468@@ -270,6 +273,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
9469 show_regs(regs);
9470 }
9471
9472+#ifdef CONFIG_PAX_PAGEEXEC
9473+#ifdef CONFIG_PAX_DLRESOLVE
9474+static void pax_emuplt_close(struct vm_area_struct *vma)
9475+{
9476+ vma->vm_mm->call_dl_resolve = 0UL;
9477+}
9478+
9479+static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9480+{
9481+ unsigned int *kaddr;
9482+
9483+ vmf->page = alloc_page(GFP_HIGHUSER);
9484+ if (!vmf->page)
9485+ return VM_FAULT_OOM;
9486+
9487+ kaddr = kmap(vmf->page);
9488+ memset(kaddr, 0, PAGE_SIZE);
9489+ kaddr[0] = 0x9DE3BFA8U; /* save */
9490+ flush_dcache_page(vmf->page);
9491+ kunmap(vmf->page);
9492+ return VM_FAULT_MAJOR;
9493+}
9494+
9495+static const struct vm_operations_struct pax_vm_ops = {
9496+ .close = pax_emuplt_close,
9497+ .fault = pax_emuplt_fault
9498+};
9499+
9500+static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
9501+{
9502+ int ret;
9503+
9504+ INIT_LIST_HEAD(&vma->anon_vma_chain);
9505+ vma->vm_mm = current->mm;
9506+ vma->vm_start = addr;
9507+ vma->vm_end = addr + PAGE_SIZE;
9508+ vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
9509+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
9510+ vma->vm_ops = &pax_vm_ops;
9511+
9512+ ret = insert_vm_struct(current->mm, vma);
9513+ if (ret)
9514+ return ret;
9515+
9516+ ++current->mm->total_vm;
9517+ return 0;
9518+}
9519+#endif
9520+
9521+/*
9522+ * PaX: decide what to do with offenders (regs->tpc = fault address)
9523+ *
9524+ * returns 1 when task should be killed
9525+ * 2 when patched PLT trampoline was detected
9526+ * 3 when unpatched PLT trampoline was detected
9527+ */
9528+static int pax_handle_fetch_fault(struct pt_regs *regs)
9529+{
9530+
9531+#ifdef CONFIG_PAX_EMUPLT
9532+ int err;
9533+
9534+ do { /* PaX: patched PLT emulation #1 */
9535+ unsigned int sethi1, sethi2, jmpl;
9536+
9537+ err = get_user(sethi1, (unsigned int *)regs->tpc);
9538+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
9539+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
9540+
9541+ if (err)
9542+ break;
9543+
9544+ if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
9545+ (sethi2 & 0xFFC00000U) == 0x03000000U &&
9546+ (jmpl & 0xFFFFE000U) == 0x81C06000U)
9547+ {
9548+ unsigned long addr;
9549+
9550+ regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
9551+ addr = regs->u_regs[UREG_G1];
9552+ addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9553+
9554+ if (test_thread_flag(TIF_32BIT))
9555+ addr &= 0xFFFFFFFFUL;
9556+
9557+ regs->tpc = addr;
9558+ regs->tnpc = addr+4;
9559+ return 2;
9560+ }
9561+ } while (0);
9562+
9563+ do { /* PaX: patched PLT emulation #2 */
9564+ unsigned int ba;
9565+
9566+ err = get_user(ba, (unsigned int *)regs->tpc);
9567+
9568+ if (err)
9569+ break;
9570+
9571+ if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
9572+ unsigned long addr;
9573+
9574+ if ((ba & 0xFFC00000U) == 0x30800000U)
9575+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9576+ else
9577+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9578+
9579+ if (test_thread_flag(TIF_32BIT))
9580+ addr &= 0xFFFFFFFFUL;
9581+
9582+ regs->tpc = addr;
9583+ regs->tnpc = addr+4;
9584+ return 2;
9585+ }
9586+ } while (0);
9587+
9588+ do { /* PaX: patched PLT emulation #3 */
9589+ unsigned int sethi, bajmpl, nop;
9590+
9591+ err = get_user(sethi, (unsigned int *)regs->tpc);
9592+ err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
9593+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9594+
9595+ if (err)
9596+ break;
9597+
9598+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9599+ ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
9600+ nop == 0x01000000U)
9601+ {
9602+ unsigned long addr;
9603+
9604+ addr = (sethi & 0x003FFFFFU) << 10;
9605+ regs->u_regs[UREG_G1] = addr;
9606+ if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
9607+ addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9608+ else
9609+ addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9610+
9611+ if (test_thread_flag(TIF_32BIT))
9612+ addr &= 0xFFFFFFFFUL;
9613+
9614+ regs->tpc = addr;
9615+ regs->tnpc = addr+4;
9616+ return 2;
9617+ }
9618+ } while (0);
9619+
9620+ do { /* PaX: patched PLT emulation #4 */
9621+ unsigned int sethi, mov1, call, mov2;
9622+
9623+ err = get_user(sethi, (unsigned int *)regs->tpc);
9624+ err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
9625+ err |= get_user(call, (unsigned int *)(regs->tpc+8));
9626+ err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
9627+
9628+ if (err)
9629+ break;
9630+
9631+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9632+ mov1 == 0x8210000FU &&
9633+ (call & 0xC0000000U) == 0x40000000U &&
9634+ mov2 == 0x9E100001U)
9635+ {
9636+ unsigned long addr;
9637+
9638+ regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
9639+ addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9640+
9641+ if (test_thread_flag(TIF_32BIT))
9642+ addr &= 0xFFFFFFFFUL;
9643+
9644+ regs->tpc = addr;
9645+ regs->tnpc = addr+4;
9646+ return 2;
9647+ }
9648+ } while (0);
9649+
9650+ do { /* PaX: patched PLT emulation #5 */
9651+ unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
9652+
9653+ err = get_user(sethi, (unsigned int *)regs->tpc);
9654+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9655+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9656+ err |= get_user(or1, (unsigned int *)(regs->tpc+12));
9657+ err |= get_user(or2, (unsigned int *)(regs->tpc+16));
9658+ err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
9659+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
9660+ err |= get_user(nop, (unsigned int *)(regs->tpc+28));
9661+
9662+ if (err)
9663+ break;
9664+
9665+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9666+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9667+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9668+ (or1 & 0xFFFFE000U) == 0x82106000U &&
9669+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9670+ sllx == 0x83287020U &&
9671+ jmpl == 0x81C04005U &&
9672+ nop == 0x01000000U)
9673+ {
9674+ unsigned long addr;
9675+
9676+ regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9677+ regs->u_regs[UREG_G1] <<= 32;
9678+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9679+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9680+ regs->tpc = addr;
9681+ regs->tnpc = addr+4;
9682+ return 2;
9683+ }
9684+ } while (0);
9685+
9686+ do { /* PaX: patched PLT emulation #6 */
9687+ unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
9688+
9689+ err = get_user(sethi, (unsigned int *)regs->tpc);
9690+ err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
9691+ err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
9692+ err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
9693+ err |= get_user(or, (unsigned int *)(regs->tpc+16));
9694+ err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
9695+ err |= get_user(nop, (unsigned int *)(regs->tpc+24));
9696+
9697+ if (err)
9698+ break;
9699+
9700+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9701+ (sethi1 & 0xFFC00000U) == 0x03000000U &&
9702+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9703+ sllx == 0x83287020U &&
9704+ (or & 0xFFFFE000U) == 0x8A116000U &&
9705+ jmpl == 0x81C04005U &&
9706+ nop == 0x01000000U)
9707+ {
9708+ unsigned long addr;
9709+
9710+ regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
9711+ regs->u_regs[UREG_G1] <<= 32;
9712+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
9713+ addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
9714+ regs->tpc = addr;
9715+ regs->tnpc = addr+4;
9716+ return 2;
9717+ }
9718+ } while (0);
9719+
9720+ do { /* PaX: unpatched PLT emulation step 1 */
9721+ unsigned int sethi, ba, nop;
9722+
9723+ err = get_user(sethi, (unsigned int *)regs->tpc);
9724+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9725+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9726+
9727+ if (err)
9728+ break;
9729+
9730+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9731+ ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
9732+ nop == 0x01000000U)
9733+ {
9734+ unsigned long addr;
9735+ unsigned int save, call;
9736+ unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
9737+
9738+ if ((ba & 0xFFC00000U) == 0x30800000U)
9739+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
9740+ else
9741+ addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9742+
9743+ if (test_thread_flag(TIF_32BIT))
9744+ addr &= 0xFFFFFFFFUL;
9745+
9746+ err = get_user(save, (unsigned int *)addr);
9747+ err |= get_user(call, (unsigned int *)(addr+4));
9748+ err |= get_user(nop, (unsigned int *)(addr+8));
9749+ if (err)
9750+ break;
9751+
9752+#ifdef CONFIG_PAX_DLRESOLVE
9753+ if (save == 0x9DE3BFA8U &&
9754+ (call & 0xC0000000U) == 0x40000000U &&
9755+ nop == 0x01000000U)
9756+ {
9757+ struct vm_area_struct *vma;
9758+ unsigned long call_dl_resolve;
9759+
9760+ down_read(&current->mm->mmap_sem);
9761+ call_dl_resolve = current->mm->call_dl_resolve;
9762+ up_read(&current->mm->mmap_sem);
9763+ if (likely(call_dl_resolve))
9764+ goto emulate;
9765+
9766+ vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
9767+
9768+ down_write(&current->mm->mmap_sem);
9769+ if (current->mm->call_dl_resolve) {
9770+ call_dl_resolve = current->mm->call_dl_resolve;
9771+ up_write(&current->mm->mmap_sem);
9772+ if (vma)
9773+ kmem_cache_free(vm_area_cachep, vma);
9774+ goto emulate;
9775+ }
9776+
9777+ call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
9778+ if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
9779+ up_write(&current->mm->mmap_sem);
9780+ if (vma)
9781+ kmem_cache_free(vm_area_cachep, vma);
9782+ return 1;
9783+ }
9784+
9785+ if (pax_insert_vma(vma, call_dl_resolve)) {
9786+ up_write(&current->mm->mmap_sem);
9787+ kmem_cache_free(vm_area_cachep, vma);
9788+ return 1;
9789+ }
9790+
9791+ current->mm->call_dl_resolve = call_dl_resolve;
9792+ up_write(&current->mm->mmap_sem);
9793+
9794+emulate:
9795+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9796+ regs->tpc = call_dl_resolve;
9797+ regs->tnpc = addr+4;
9798+ return 3;
9799+ }
9800+#endif
9801+
9802+ /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
9803+ if ((save & 0xFFC00000U) == 0x05000000U &&
9804+ (call & 0xFFFFE000U) == 0x85C0A000U &&
9805+ nop == 0x01000000U)
9806+ {
9807+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9808+ regs->u_regs[UREG_G2] = addr + 4;
9809+ addr = (save & 0x003FFFFFU) << 10;
9810+ addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
9811+
9812+ if (test_thread_flag(TIF_32BIT))
9813+ addr &= 0xFFFFFFFFUL;
9814+
9815+ regs->tpc = addr;
9816+ regs->tnpc = addr+4;
9817+ return 3;
9818+ }
9819+
9820+ /* PaX: 64-bit PLT stub */
9821+ err = get_user(sethi1, (unsigned int *)addr);
9822+ err |= get_user(sethi2, (unsigned int *)(addr+4));
9823+ err |= get_user(or1, (unsigned int *)(addr+8));
9824+ err |= get_user(or2, (unsigned int *)(addr+12));
9825+ err |= get_user(sllx, (unsigned int *)(addr+16));
9826+ err |= get_user(add, (unsigned int *)(addr+20));
9827+ err |= get_user(jmpl, (unsigned int *)(addr+24));
9828+ err |= get_user(nop, (unsigned int *)(addr+28));
9829+ if (err)
9830+ break;
9831+
9832+ if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
9833+ (sethi2 & 0xFFC00000U) == 0x0B000000U &&
9834+ (or1 & 0xFFFFE000U) == 0x88112000U &&
9835+ (or2 & 0xFFFFE000U) == 0x8A116000U &&
9836+ sllx == 0x89293020U &&
9837+ add == 0x8A010005U &&
9838+ jmpl == 0x89C14000U &&
9839+ nop == 0x01000000U)
9840+ {
9841+ regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
9842+ regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
9843+ regs->u_regs[UREG_G4] <<= 32;
9844+ regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
9845+ regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
9846+ regs->u_regs[UREG_G4] = addr + 24;
9847+ addr = regs->u_regs[UREG_G5];
9848+ regs->tpc = addr;
9849+ regs->tnpc = addr+4;
9850+ return 3;
9851+ }
9852+ }
9853+ } while (0);
9854+
9855+#ifdef CONFIG_PAX_DLRESOLVE
9856+ do { /* PaX: unpatched PLT emulation step 2 */
9857+ unsigned int save, call, nop;
9858+
9859+ err = get_user(save, (unsigned int *)(regs->tpc-4));
9860+ err |= get_user(call, (unsigned int *)regs->tpc);
9861+ err |= get_user(nop, (unsigned int *)(regs->tpc+4));
9862+ if (err)
9863+ break;
9864+
9865+ if (save == 0x9DE3BFA8U &&
9866+ (call & 0xC0000000U) == 0x40000000U &&
9867+ nop == 0x01000000U)
9868+ {
9869+ unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
9870+
9871+ if (test_thread_flag(TIF_32BIT))
9872+ dl_resolve &= 0xFFFFFFFFUL;
9873+
9874+ regs->u_regs[UREG_RETPC] = regs->tpc;
9875+ regs->tpc = dl_resolve;
9876+ regs->tnpc = dl_resolve+4;
9877+ return 3;
9878+ }
9879+ } while (0);
9880+#endif
9881+
9882+ do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
9883+ unsigned int sethi, ba, nop;
9884+
9885+ err = get_user(sethi, (unsigned int *)regs->tpc);
9886+ err |= get_user(ba, (unsigned int *)(regs->tpc+4));
9887+ err |= get_user(nop, (unsigned int *)(regs->tpc+8));
9888+
9889+ if (err)
9890+ break;
9891+
9892+ if ((sethi & 0xFFC00000U) == 0x03000000U &&
9893+ (ba & 0xFFF00000U) == 0x30600000U &&
9894+ nop == 0x01000000U)
9895+ {
9896+ unsigned long addr;
9897+
9898+ addr = (sethi & 0x003FFFFFU) << 10;
9899+ regs->u_regs[UREG_G1] = addr;
9900+ addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
9901+
9902+ if (test_thread_flag(TIF_32BIT))
9903+ addr &= 0xFFFFFFFFUL;
9904+
9905+ regs->tpc = addr;
9906+ regs->tnpc = addr+4;
9907+ return 2;
9908+ }
9909+ } while (0);
9910+
9911+#endif
9912+
9913+ return 1;
9914+}
9915+
9916+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
9917+{
9918+ unsigned long i;
9919+
9920+ printk(KERN_ERR "PAX: bytes at PC: ");
9921+ for (i = 0; i < 8; i++) {
9922+ unsigned int c;
9923+ if (get_user(c, (unsigned int *)pc+i))
9924+ printk(KERN_CONT "???????? ");
9925+ else
9926+ printk(KERN_CONT "%08x ", c);
9927+ }
9928+ printk("\n");
9929+}
9930+#endif
9931+
9932 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
9933 {
9934 struct mm_struct *mm = current->mm;
9935@@ -341,6 +804,29 @@ retry:
9936 if (!vma)
9937 goto bad_area;
9938
9939+#ifdef CONFIG_PAX_PAGEEXEC
9940+ /* PaX: detect ITLB misses on non-exec pages */
9941+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
9942+ !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
9943+ {
9944+ if (address != regs->tpc)
9945+ goto good_area;
9946+
9947+ up_read(&mm->mmap_sem);
9948+ switch (pax_handle_fetch_fault(regs)) {
9949+
9950+#ifdef CONFIG_PAX_EMUPLT
9951+ case 2:
9952+ case 3:
9953+ return;
9954+#endif
9955+
9956+ }
9957+ pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
9958+ do_group_exit(SIGKILL);
9959+ }
9960+#endif
9961+
9962 /* Pure DTLB misses do not tell us whether the fault causing
9963 * load/store/atomic was a write or not, it only says that there
9964 * was no match. So in such a case we (carefully) read the
9965diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
9966index d2b5944..bd813f2 100644
9967--- a/arch/sparc/mm/hugetlbpage.c
9968+++ b/arch/sparc/mm/hugetlbpage.c
9969@@ -38,7 +38,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9970
9971 info.flags = 0;
9972 info.length = len;
9973- info.low_limit = TASK_UNMAPPED_BASE;
9974+ info.low_limit = mm->mmap_base;
9975 info.high_limit = min(task_size, VA_EXCLUDE_START);
9976 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
9977 info.align_offset = 0;
9978@@ -47,6 +47,12 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
9979 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9980 VM_BUG_ON(addr != -ENOMEM);
9981 info.low_limit = VA_EXCLUDE_END;
9982+
9983+#ifdef CONFIG_PAX_RANDMMAP
9984+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9985+ info.low_limit += mm->delta_mmap;
9986+#endif
9987+
9988 info.high_limit = task_size;
9989 addr = vm_unmapped_area(&info);
9990 }
9991@@ -85,6 +91,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9992 VM_BUG_ON(addr != -ENOMEM);
9993 info.flags = 0;
9994 info.low_limit = TASK_UNMAPPED_BASE;
9995+
9996+#ifdef CONFIG_PAX_RANDMMAP
9997+ if (mm->pax_flags & MF_PAX_RANDMMAP)
9998+ info.low_limit += mm->delta_mmap;
9999+#endif
10000+
10001 info.high_limit = STACK_TOP32;
10002 addr = vm_unmapped_area(&info);
10003 }
10004@@ -99,6 +111,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10005 struct mm_struct *mm = current->mm;
10006 struct vm_area_struct *vma;
10007 unsigned long task_size = TASK_SIZE;
10008+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
10009
10010 if (test_thread_flag(TIF_32BIT))
10011 task_size = STACK_TOP32;
10012@@ -114,11 +127,14 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
10013 return addr;
10014 }
10015
10016+#ifdef CONFIG_PAX_RANDMMAP
10017+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10018+#endif
10019+
10020 if (addr) {
10021 addr = ALIGN(addr, HPAGE_SIZE);
10022 vma = find_vma(mm, addr);
10023- if (task_size - len >= addr &&
10024- (!vma || addr + len <= vma->vm_start))
10025+ if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10026 return addr;
10027 }
10028 if (mm->get_unmapped_area == arch_get_unmapped_area)
10029diff --git a/arch/sparc/mm/tlb.c b/arch/sparc/mm/tlb.c
10030index 83d89bc..37e7bc4 100644
10031--- a/arch/sparc/mm/tlb.c
10032+++ b/arch/sparc/mm/tlb.c
10033@@ -85,8 +85,8 @@ static void tlb_batch_add_one(struct mm_struct *mm, unsigned long vaddr,
10034 }
10035
10036 if (!tb->active) {
10037- global_flush_tlb_page(mm, vaddr);
10038 flush_tsb_user_page(mm, vaddr);
10039+ global_flush_tlb_page(mm, vaddr);
10040 goto out;
10041 }
10042
10043diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
10044index f4500c6..889656c 100644
10045--- a/arch/tile/include/asm/atomic_64.h
10046+++ b/arch/tile/include/asm/atomic_64.h
10047@@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
10048
10049 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10050
10051+#define atomic64_read_unchecked(v) atomic64_read(v)
10052+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
10053+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
10054+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
10055+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
10056+#define atomic64_inc_unchecked(v) atomic64_inc(v)
10057+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
10058+#define atomic64_dec_unchecked(v) atomic64_dec(v)
10059+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
10060+
10061 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
10062 #define smp_mb__before_atomic_dec() smp_mb()
10063 #define smp_mb__after_atomic_dec() smp_mb()
10064diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
10065index a9a5299..0fce79e 100644
10066--- a/arch/tile/include/asm/cache.h
10067+++ b/arch/tile/include/asm/cache.h
10068@@ -15,11 +15,12 @@
10069 #ifndef _ASM_TILE_CACHE_H
10070 #define _ASM_TILE_CACHE_H
10071
10072+#include <linux/const.h>
10073 #include <arch/chip.h>
10074
10075 /* bytes per L1 data cache line */
10076 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
10077-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10078+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10079
10080 /* bytes per L2 cache line */
10081 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
10082diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
10083index 9ab078a..d6635c2 100644
10084--- a/arch/tile/include/asm/uaccess.h
10085+++ b/arch/tile/include/asm/uaccess.h
10086@@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
10087 const void __user *from,
10088 unsigned long n)
10089 {
10090- int sz = __compiletime_object_size(to);
10091+ size_t sz = __compiletime_object_size(to);
10092
10093- if (likely(sz == -1 || sz >= n))
10094+ if (likely(sz == (size_t)-1 || sz >= n))
10095 n = _copy_from_user(to, from, n);
10096 else
10097 copy_from_user_overflow();
10098diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
10099index 650ccff..45fe2d6 100644
10100--- a/arch/tile/mm/hugetlbpage.c
10101+++ b/arch/tile/mm/hugetlbpage.c
10102@@ -239,6 +239,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
10103 info.high_limit = TASK_SIZE;
10104 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10105 info.align_offset = 0;
10106+ info.threadstack_offset = 0;
10107 return vm_unmapped_area(&info);
10108 }
10109
10110@@ -256,6 +257,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
10111 info.high_limit = current->mm->mmap_base;
10112 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
10113 info.align_offset = 0;
10114+ info.threadstack_offset = 0;
10115 addr = vm_unmapped_area(&info);
10116
10117 /*
10118diff --git a/arch/um/Makefile b/arch/um/Makefile
10119index 133f7de..1d6f2f1 100644
10120--- a/arch/um/Makefile
10121+++ b/arch/um/Makefile
10122@@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
10123 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
10124 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
10125
10126+ifdef CONSTIFY_PLUGIN
10127+USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10128+endif
10129+
10130 #This will adjust *FLAGS accordingly to the platform.
10131 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
10132
10133diff --git a/arch/um/defconfig b/arch/um/defconfig
10134index 08107a7..ab22afe 100644
10135--- a/arch/um/defconfig
10136+++ b/arch/um/defconfig
10137@@ -51,7 +51,6 @@ CONFIG_X86_CMPXCHG=y
10138 CONFIG_X86_L1_CACHE_SHIFT=5
10139 CONFIG_X86_XADD=y
10140 CONFIG_X86_PPRO_FENCE=y
10141-CONFIG_X86_WP_WORKS_OK=y
10142 CONFIG_X86_INVLPG=y
10143 CONFIG_X86_BSWAP=y
10144 CONFIG_X86_POPAD_OK=y
10145diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
10146index 19e1bdd..3665b77 100644
10147--- a/arch/um/include/asm/cache.h
10148+++ b/arch/um/include/asm/cache.h
10149@@ -1,6 +1,7 @@
10150 #ifndef __UM_CACHE_H
10151 #define __UM_CACHE_H
10152
10153+#include <linux/const.h>
10154
10155 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
10156 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10157@@ -12,6 +13,6 @@
10158 # define L1_CACHE_SHIFT 5
10159 #endif
10160
10161-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10162+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10163
10164 #endif
10165diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
10166index 2e0a6b1..a64d0f5 100644
10167--- a/arch/um/include/asm/kmap_types.h
10168+++ b/arch/um/include/asm/kmap_types.h
10169@@ -8,6 +8,6 @@
10170
10171 /* No more #include "asm/arch/kmap_types.h" ! */
10172
10173-#define KM_TYPE_NR 14
10174+#define KM_TYPE_NR 15
10175
10176 #endif
10177diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
10178index 5ff53d9..5850cdf 100644
10179--- a/arch/um/include/asm/page.h
10180+++ b/arch/um/include/asm/page.h
10181@@ -14,6 +14,9 @@
10182 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
10183 #define PAGE_MASK (~(PAGE_SIZE-1))
10184
10185+#define ktla_ktva(addr) (addr)
10186+#define ktva_ktla(addr) (addr)
10187+
10188 #ifndef __ASSEMBLY__
10189
10190 struct page;
10191diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
10192index 0032f92..cd151e0 100644
10193--- a/arch/um/include/asm/pgtable-3level.h
10194+++ b/arch/um/include/asm/pgtable-3level.h
10195@@ -58,6 +58,7 @@
10196 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
10197 #define pud_populate(mm, pud, pmd) \
10198 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
10199+#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
10200
10201 #ifdef CONFIG_64BIT
10202 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
10203diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
10204index b462b13..e7a19aa 100644
10205--- a/arch/um/kernel/process.c
10206+++ b/arch/um/kernel/process.c
10207@@ -386,22 +386,6 @@ int singlestepping(void * t)
10208 return 2;
10209 }
10210
10211-/*
10212- * Only x86 and x86_64 have an arch_align_stack().
10213- * All other arches have "#define arch_align_stack(x) (x)"
10214- * in their asm/system.h
10215- * As this is included in UML from asm-um/system-generic.h,
10216- * we can use it to behave as the subarch does.
10217- */
10218-#ifndef arch_align_stack
10219-unsigned long arch_align_stack(unsigned long sp)
10220-{
10221- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
10222- sp -= get_random_int() % 8192;
10223- return sp & ~0xf;
10224-}
10225-#endif
10226-
10227 unsigned long get_wchan(struct task_struct *p)
10228 {
10229 unsigned long stack_page, sp, ip;
10230diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
10231index ad8f795..2c7eec6 100644
10232--- a/arch/unicore32/include/asm/cache.h
10233+++ b/arch/unicore32/include/asm/cache.h
10234@@ -12,8 +12,10 @@
10235 #ifndef __UNICORE_CACHE_H__
10236 #define __UNICORE_CACHE_H__
10237
10238-#define L1_CACHE_SHIFT (5)
10239-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10240+#include <linux/const.h>
10241+
10242+#define L1_CACHE_SHIFT 5
10243+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10244
10245 /*
10246 * Memory returned by kmalloc() may be used for DMA, so we must make
10247diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
10248index de80b33..c0f0899 100644
10249--- a/arch/x86/Kconfig
10250+++ b/arch/x86/Kconfig
10251@@ -243,7 +243,7 @@ config X86_HT
10252
10253 config X86_32_LAZY_GS
10254 def_bool y
10255- depends on X86_32 && !CC_STACKPROTECTOR
10256+ depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
10257
10258 config ARCH_HWEIGHT_CFLAGS
10259 string
10260@@ -1076,6 +1076,7 @@ config MICROCODE_EARLY
10261
10262 config X86_MSR
10263 tristate "/dev/cpu/*/msr - Model-specific register support"
10264+ depends on !GRKERNSEC_KMEM
10265 ---help---
10266 This device gives privileged processes access to the x86
10267 Model-Specific Registers (MSRs). It is a character device with
10268@@ -1099,7 +1100,7 @@ choice
10269
10270 config NOHIGHMEM
10271 bool "off"
10272- depends on !X86_NUMAQ
10273+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10274 ---help---
10275 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
10276 However, the address space of 32-bit x86 processors is only 4
10277@@ -1136,7 +1137,7 @@ config NOHIGHMEM
10278
10279 config HIGHMEM4G
10280 bool "4GB"
10281- depends on !X86_NUMAQ
10282+ depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
10283 ---help---
10284 Select this if you have a 32-bit processor and between 1 and 4
10285 gigabytes of physical RAM.
10286@@ -1189,7 +1190,7 @@ config PAGE_OFFSET
10287 hex
10288 default 0xB0000000 if VMSPLIT_3G_OPT
10289 default 0x80000000 if VMSPLIT_2G
10290- default 0x78000000 if VMSPLIT_2G_OPT
10291+ default 0x70000000 if VMSPLIT_2G_OPT
10292 default 0x40000000 if VMSPLIT_1G
10293 default 0xC0000000
10294 depends on X86_32
10295@@ -1587,6 +1588,7 @@ config SECCOMP
10296
10297 config CC_STACKPROTECTOR
10298 bool "Enable -fstack-protector buffer overflow detection"
10299+ depends on X86_64 || !PAX_MEMORY_UDEREF
10300 ---help---
10301 This option turns on the -fstack-protector GCC feature. This
10302 feature puts, at the beginning of functions, a canary value on
10303@@ -1706,6 +1708,8 @@ config X86_NEED_RELOCS
10304 config PHYSICAL_ALIGN
10305 hex "Alignment value to which kernel should be aligned" if X86_32
10306 default "0x1000000"
10307+ range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
10308+ range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
10309 range 0x2000 0x1000000
10310 ---help---
10311 This value puts the alignment restrictions on physical address
10312@@ -1781,9 +1785,10 @@ config DEBUG_HOTPLUG_CPU0
10313 If unsure, say N.
10314
10315 config COMPAT_VDSO
10316- def_bool y
10317+ def_bool n
10318 prompt "Compat VDSO support"
10319 depends on X86_32 || IA32_EMULATION
10320+ depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
10321 ---help---
10322 Map the 32-bit VDSO to the predictable old-style address too.
10323
10324diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
10325index c026cca..14657ae 100644
10326--- a/arch/x86/Kconfig.cpu
10327+++ b/arch/x86/Kconfig.cpu
10328@@ -319,7 +319,7 @@ config X86_PPRO_FENCE
10329
10330 config X86_F00F_BUG
10331 def_bool y
10332- depends on M586MMX || M586TSC || M586 || M486
10333+ depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
10334
10335 config X86_INVD_BUG
10336 def_bool y
10337@@ -327,7 +327,7 @@ config X86_INVD_BUG
10338
10339 config X86_ALIGNMENT_16
10340 def_bool y
10341- depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10342+ depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
10343
10344 config X86_INTEL_USERCOPY
10345 def_bool y
10346@@ -373,7 +373,7 @@ config X86_CMPXCHG64
10347 # generates cmov.
10348 config X86_CMOV
10349 def_bool y
10350- depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10351+ depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
10352
10353 config X86_MINIMUM_CPU_FAMILY
10354 int
10355diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
10356index b322f12..652d0d9 100644
10357--- a/arch/x86/Kconfig.debug
10358+++ b/arch/x86/Kconfig.debug
10359@@ -84,7 +84,7 @@ config X86_PTDUMP
10360 config DEBUG_RODATA
10361 bool "Write protect kernel read-only data structures"
10362 default y
10363- depends on DEBUG_KERNEL
10364+ depends on DEBUG_KERNEL && BROKEN
10365 ---help---
10366 Mark the kernel read-only data as write-protected in the pagetables,
10367 in order to catch accidental (and incorrect) writes to such const
10368@@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
10369
10370 config DEBUG_SET_MODULE_RONX
10371 bool "Set loadable kernel module data as NX and text as RO"
10372- depends on MODULES
10373+ depends on MODULES && BROKEN
10374 ---help---
10375 This option helps catch unintended modifications to loadable
10376 kernel module's text and read-only data. It also prevents execution
10377@@ -294,7 +294,7 @@ config OPTIMIZE_INLINING
10378
10379 config DEBUG_STRICT_USER_COPY_CHECKS
10380 bool "Strict copy size checks"
10381- depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
10382+ depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
10383 ---help---
10384 Enabling this option turns a certain set of sanity checks for user
10385 copy operations into compile time failures.
10386diff --git a/arch/x86/Makefile b/arch/x86/Makefile
10387index 5c47726..8c4fa67 100644
10388--- a/arch/x86/Makefile
10389+++ b/arch/x86/Makefile
10390@@ -54,6 +54,7 @@ else
10391 UTS_MACHINE := x86_64
10392 CHECKFLAGS += -D__x86_64__ -m64
10393
10394+ biarch := $(call cc-option,-m64)
10395 KBUILD_AFLAGS += -m64
10396 KBUILD_CFLAGS += -m64
10397
10398@@ -234,3 +235,12 @@ define archhelp
10399 echo ' FDARGS="..." arguments for the booted kernel'
10400 echo ' FDINITRD=file initrd for the booted kernel'
10401 endef
10402+
10403+define OLD_LD
10404+
10405+*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
10406+*** Please upgrade your binutils to 2.18 or newer
10407+endef
10408+
10409+archprepare:
10410+ $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
10411diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
10412index 379814b..add62ce 100644
10413--- a/arch/x86/boot/Makefile
10414+++ b/arch/x86/boot/Makefile
10415@@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
10416 $(call cc-option, -fno-stack-protector) \
10417 $(call cc-option, -mpreferred-stack-boundary=2)
10418 KBUILD_CFLAGS += $(call cc-option, -m32)
10419+ifdef CONSTIFY_PLUGIN
10420+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10421+endif
10422 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10423 GCOV_PROFILE := n
10424
10425diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
10426index 878e4b9..20537ab 100644
10427--- a/arch/x86/boot/bitops.h
10428+++ b/arch/x86/boot/bitops.h
10429@@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10430 u8 v;
10431 const u32 *p = (const u32 *)addr;
10432
10433- asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10434+ asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
10435 return v;
10436 }
10437
10438@@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
10439
10440 static inline void set_bit(int nr, void *addr)
10441 {
10442- asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10443+ asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
10444 }
10445
10446 #endif /* BOOT_BITOPS_H */
10447diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
10448index 5b75319..331a4ca 100644
10449--- a/arch/x86/boot/boot.h
10450+++ b/arch/x86/boot/boot.h
10451@@ -85,7 +85,7 @@ static inline void io_delay(void)
10452 static inline u16 ds(void)
10453 {
10454 u16 seg;
10455- asm("movw %%ds,%0" : "=rm" (seg));
10456+ asm volatile("movw %%ds,%0" : "=rm" (seg));
10457 return seg;
10458 }
10459
10460@@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
10461 static inline int memcmp(const void *s1, const void *s2, size_t len)
10462 {
10463 u8 diff;
10464- asm("repe; cmpsb; setnz %0"
10465+ asm volatile("repe; cmpsb; setnz %0"
10466 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
10467 return diff;
10468 }
10469diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
10470index 5ef205c..342191d 100644
10471--- a/arch/x86/boot/compressed/Makefile
10472+++ b/arch/x86/boot/compressed/Makefile
10473@@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
10474 KBUILD_CFLAGS += $(cflags-y)
10475 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
10476 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
10477+ifdef CONSTIFY_PLUGIN
10478+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
10479+endif
10480
10481 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
10482 GCOV_PROFILE := n
10483diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
10484index c205035..5853587 100644
10485--- a/arch/x86/boot/compressed/eboot.c
10486+++ b/arch/x86/boot/compressed/eboot.c
10487@@ -150,7 +150,6 @@ again:
10488 *addr = max_addr;
10489 }
10490
10491-free_pool:
10492 efi_call_phys1(sys_table->boottime->free_pool, map);
10493
10494 fail:
10495@@ -214,7 +213,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
10496 if (i == map_size / desc_size)
10497 status = EFI_NOT_FOUND;
10498
10499-free_pool:
10500 efi_call_phys1(sys_table->boottime->free_pool, map);
10501 fail:
10502 return status;
10503diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
10504index a53440e..c3dbf1e 100644
10505--- a/arch/x86/boot/compressed/efi_stub_32.S
10506+++ b/arch/x86/boot/compressed/efi_stub_32.S
10507@@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
10508 * parameter 2, ..., param n. To make things easy, we save the return
10509 * address of efi_call_phys in a global variable.
10510 */
10511- popl %ecx
10512- movl %ecx, saved_return_addr(%edx)
10513- /* get the function pointer into ECX*/
10514- popl %ecx
10515- movl %ecx, efi_rt_function_ptr(%edx)
10516+ popl saved_return_addr(%edx)
10517+ popl efi_rt_function_ptr(%edx)
10518
10519 /*
10520 * 3. Call the physical function.
10521 */
10522- call *%ecx
10523+ call *efi_rt_function_ptr(%edx)
10524
10525 /*
10526 * 4. Balance the stack. And because EAX contain the return value,
10527@@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
10528 1: popl %edx
10529 subl $1b, %edx
10530
10531- movl efi_rt_function_ptr(%edx), %ecx
10532- pushl %ecx
10533+ pushl efi_rt_function_ptr(%edx)
10534
10535 /*
10536 * 10. Push the saved return address onto the stack and return.
10537 */
10538- movl saved_return_addr(%edx), %ecx
10539- pushl %ecx
10540- ret
10541+ jmpl *saved_return_addr(%edx)
10542 ENDPROC(efi_call_phys)
10543 .previous
10544
10545diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
10546index 1e3184f..0d11e2e 100644
10547--- a/arch/x86/boot/compressed/head_32.S
10548+++ b/arch/x86/boot/compressed/head_32.S
10549@@ -118,7 +118,7 @@ preferred_addr:
10550 notl %eax
10551 andl %eax, %ebx
10552 #else
10553- movl $LOAD_PHYSICAL_ADDR, %ebx
10554+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10555 #endif
10556
10557 /* Target address to relocate to for decompression */
10558@@ -204,7 +204,7 @@ relocated:
10559 * and where it was actually loaded.
10560 */
10561 movl %ebp, %ebx
10562- subl $LOAD_PHYSICAL_ADDR, %ebx
10563+ subl $____LOAD_PHYSICAL_ADDR, %ebx
10564 jz 2f /* Nothing to be done if loaded at compiled addr. */
10565 /*
10566 * Process relocations.
10567@@ -212,8 +212,7 @@ relocated:
10568
10569 1: subl $4, %edi
10570 movl (%edi), %ecx
10571- testl %ecx, %ecx
10572- jz 2f
10573+ jecxz 2f
10574 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
10575 jmp 1b
10576 2:
10577diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
10578index c1d383d..57ab51c 100644
10579--- a/arch/x86/boot/compressed/head_64.S
10580+++ b/arch/x86/boot/compressed/head_64.S
10581@@ -97,7 +97,7 @@ ENTRY(startup_32)
10582 notl %eax
10583 andl %eax, %ebx
10584 #else
10585- movl $LOAD_PHYSICAL_ADDR, %ebx
10586+ movl $____LOAD_PHYSICAL_ADDR, %ebx
10587 #endif
10588
10589 /* Target address to relocate to for decompression */
10590@@ -272,7 +272,7 @@ preferred_addr:
10591 notq %rax
10592 andq %rax, %rbp
10593 #else
10594- movq $LOAD_PHYSICAL_ADDR, %rbp
10595+ movq $____LOAD_PHYSICAL_ADDR, %rbp
10596 #endif
10597
10598 /* Target address to relocate to for decompression */
10599@@ -363,8 +363,8 @@ gdt:
10600 .long gdt
10601 .word 0
10602 .quad 0x0000000000000000 /* NULL descriptor */
10603- .quad 0x00af9a000000ffff /* __KERNEL_CS */
10604- .quad 0x00cf92000000ffff /* __KERNEL_DS */
10605+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
10606+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
10607 .quad 0x0080890000000000 /* TS descriptor */
10608 .quad 0x0000000000000000 /* TS continued */
10609 gdt_end:
10610diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
10611index 7cb56c6..d382d84 100644
10612--- a/arch/x86/boot/compressed/misc.c
10613+++ b/arch/x86/boot/compressed/misc.c
10614@@ -303,7 +303,7 @@ static void parse_elf(void *output)
10615 case PT_LOAD:
10616 #ifdef CONFIG_RELOCATABLE
10617 dest = output;
10618- dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
10619+ dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
10620 #else
10621 dest = (void *)(phdr->p_paddr);
10622 #endif
10623@@ -354,7 +354,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
10624 error("Destination address too large");
10625 #endif
10626 #ifndef CONFIG_RELOCATABLE
10627- if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
10628+ if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
10629 error("Wrong destination address");
10630 #endif
10631
10632diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
10633index 4d3ff03..e4972ff 100644
10634--- a/arch/x86/boot/cpucheck.c
10635+++ b/arch/x86/boot/cpucheck.c
10636@@ -74,7 +74,7 @@ static int has_fpu(void)
10637 u16 fcw = -1, fsw = -1;
10638 u32 cr0;
10639
10640- asm("movl %%cr0,%0" : "=r" (cr0));
10641+ asm volatile("movl %%cr0,%0" : "=r" (cr0));
10642 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
10643 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
10644 asm volatile("movl %0,%%cr0" : : "r" (cr0));
10645@@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
10646 {
10647 u32 f0, f1;
10648
10649- asm("pushfl ; "
10650+ asm volatile("pushfl ; "
10651 "pushfl ; "
10652 "popl %0 ; "
10653 "movl %0,%1 ; "
10654@@ -115,7 +115,7 @@ static void get_flags(void)
10655 set_bit(X86_FEATURE_FPU, cpu.flags);
10656
10657 if (has_eflag(X86_EFLAGS_ID)) {
10658- asm("cpuid"
10659+ asm volatile("cpuid"
10660 : "=a" (max_intel_level),
10661 "=b" (cpu_vendor[0]),
10662 "=d" (cpu_vendor[1]),
10663@@ -124,7 +124,7 @@ static void get_flags(void)
10664
10665 if (max_intel_level >= 0x00000001 &&
10666 max_intel_level <= 0x0000ffff) {
10667- asm("cpuid"
10668+ asm volatile("cpuid"
10669 : "=a" (tfms),
10670 "=c" (cpu.flags[4]),
10671 "=d" (cpu.flags[0])
10672@@ -136,7 +136,7 @@ static void get_flags(void)
10673 cpu.model += ((tfms >> 16) & 0xf) << 4;
10674 }
10675
10676- asm("cpuid"
10677+ asm volatile("cpuid"
10678 : "=a" (max_amd_level)
10679 : "a" (0x80000000)
10680 : "ebx", "ecx", "edx");
10681@@ -144,7 +144,7 @@ static void get_flags(void)
10682 if (max_amd_level >= 0x80000001 &&
10683 max_amd_level <= 0x8000ffff) {
10684 u32 eax = 0x80000001;
10685- asm("cpuid"
10686+ asm volatile("cpuid"
10687 : "+a" (eax),
10688 "=c" (cpu.flags[6]),
10689 "=d" (cpu.flags[1])
10690@@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10691 u32 ecx = MSR_K7_HWCR;
10692 u32 eax, edx;
10693
10694- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10695+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10696 eax &= ~(1 << 15);
10697- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10698+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10699
10700 get_flags(); /* Make sure it really did something */
10701 err = check_flags();
10702@@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10703 u32 ecx = MSR_VIA_FCR;
10704 u32 eax, edx;
10705
10706- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10707+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10708 eax |= (1<<1)|(1<<7);
10709- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10710+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10711
10712 set_bit(X86_FEATURE_CX8, cpu.flags);
10713 err = check_flags();
10714@@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
10715 u32 eax, edx;
10716 u32 level = 1;
10717
10718- asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10719- asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10720- asm("cpuid"
10721+ asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
10722+ asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
10723+ asm volatile("cpuid"
10724 : "+a" (level), "=d" (cpu.flags[0])
10725 : : "ecx", "ebx");
10726- asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10727+ asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
10728
10729 err = check_flags();
10730 }
10731diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
10732index 9ec06a1..2c25e79 100644
10733--- a/arch/x86/boot/header.S
10734+++ b/arch/x86/boot/header.S
10735@@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
10736 # single linked list of
10737 # struct setup_data
10738
10739-pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
10740+pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
10741
10742 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
10743+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
10744+#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
10745+#else
10746 #define VO_INIT_SIZE (VO__end - VO__text)
10747+#endif
10748 #if ZO_INIT_SIZE > VO_INIT_SIZE
10749 #define INIT_SIZE ZO_INIT_SIZE
10750 #else
10751diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
10752index db75d07..8e6d0af 100644
10753--- a/arch/x86/boot/memory.c
10754+++ b/arch/x86/boot/memory.c
10755@@ -19,7 +19,7 @@
10756
10757 static int detect_memory_e820(void)
10758 {
10759- int count = 0;
10760+ unsigned int count = 0;
10761 struct biosregs ireg, oreg;
10762 struct e820entry *desc = boot_params.e820_map;
10763 static struct e820entry buf; /* static so it is zeroed */
10764diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
10765index 11e8c6e..fdbb1ed 100644
10766--- a/arch/x86/boot/video-vesa.c
10767+++ b/arch/x86/boot/video-vesa.c
10768@@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
10769
10770 boot_params.screen_info.vesapm_seg = oreg.es;
10771 boot_params.screen_info.vesapm_off = oreg.di;
10772+ boot_params.screen_info.vesapm_size = oreg.cx;
10773 }
10774
10775 /*
10776diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
10777index 43eda28..5ab5fdb 100644
10778--- a/arch/x86/boot/video.c
10779+++ b/arch/x86/boot/video.c
10780@@ -96,7 +96,7 @@ static void store_mode_params(void)
10781 static unsigned int get_entry(void)
10782 {
10783 char entry_buf[4];
10784- int i, len = 0;
10785+ unsigned int i, len = 0;
10786 int key;
10787 unsigned int v;
10788
10789diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
10790index 9105655..5e37f27 100644
10791--- a/arch/x86/crypto/aes-x86_64-asm_64.S
10792+++ b/arch/x86/crypto/aes-x86_64-asm_64.S
10793@@ -8,6 +8,8 @@
10794 * including this sentence is retained in full.
10795 */
10796
10797+#include <asm/alternative-asm.h>
10798+
10799 .extern crypto_ft_tab
10800 .extern crypto_it_tab
10801 .extern crypto_fl_tab
10802@@ -70,6 +72,8 @@
10803 je B192; \
10804 leaq 32(r9),r9;
10805
10806+#define ret pax_force_retaddr 0, 1; ret
10807+
10808 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
10809 movq r1,r2; \
10810 movq r3,r4; \
10811diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
10812index 04b7977..402f223 100644
10813--- a/arch/x86/crypto/aesni-intel_asm.S
10814+++ b/arch/x86/crypto/aesni-intel_asm.S
10815@@ -31,6 +31,7 @@
10816
10817 #include <linux/linkage.h>
10818 #include <asm/inst.h>
10819+#include <asm/alternative-asm.h>
10820
10821 #ifdef __x86_64__
10822 .data
10823@@ -1435,6 +1436,7 @@ _return_T_done_decrypt:
10824 pop %r14
10825 pop %r13
10826 pop %r12
10827+ pax_force_retaddr 0, 1
10828 ret
10829 ENDPROC(aesni_gcm_dec)
10830
10831@@ -1699,6 +1701,7 @@ _return_T_done_encrypt:
10832 pop %r14
10833 pop %r13
10834 pop %r12
10835+ pax_force_retaddr 0, 1
10836 ret
10837 ENDPROC(aesni_gcm_enc)
10838
10839@@ -1716,6 +1719,7 @@ _key_expansion_256a:
10840 pxor %xmm1, %xmm0
10841 movaps %xmm0, (TKEYP)
10842 add $0x10, TKEYP
10843+ pax_force_retaddr_bts
10844 ret
10845 ENDPROC(_key_expansion_128)
10846 ENDPROC(_key_expansion_256a)
10847@@ -1742,6 +1746,7 @@ _key_expansion_192a:
10848 shufps $0b01001110, %xmm2, %xmm1
10849 movaps %xmm1, 0x10(TKEYP)
10850 add $0x20, TKEYP
10851+ pax_force_retaddr_bts
10852 ret
10853 ENDPROC(_key_expansion_192a)
10854
10855@@ -1762,6 +1767,7 @@ _key_expansion_192b:
10856
10857 movaps %xmm0, (TKEYP)
10858 add $0x10, TKEYP
10859+ pax_force_retaddr_bts
10860 ret
10861 ENDPROC(_key_expansion_192b)
10862
10863@@ -1775,6 +1781,7 @@ _key_expansion_256b:
10864 pxor %xmm1, %xmm2
10865 movaps %xmm2, (TKEYP)
10866 add $0x10, TKEYP
10867+ pax_force_retaddr_bts
10868 ret
10869 ENDPROC(_key_expansion_256b)
10870
10871@@ -1888,6 +1895,7 @@ ENTRY(aesni_set_key)
10872 #ifndef __x86_64__
10873 popl KEYP
10874 #endif
10875+ pax_force_retaddr 0, 1
10876 ret
10877 ENDPROC(aesni_set_key)
10878
10879@@ -1910,6 +1918,7 @@ ENTRY(aesni_enc)
10880 popl KLEN
10881 popl KEYP
10882 #endif
10883+ pax_force_retaddr 0, 1
10884 ret
10885 ENDPROC(aesni_enc)
10886
10887@@ -1968,6 +1977,7 @@ _aesni_enc1:
10888 AESENC KEY STATE
10889 movaps 0x70(TKEYP), KEY
10890 AESENCLAST KEY STATE
10891+ pax_force_retaddr_bts
10892 ret
10893 ENDPROC(_aesni_enc1)
10894
10895@@ -2077,6 +2087,7 @@ _aesni_enc4:
10896 AESENCLAST KEY STATE2
10897 AESENCLAST KEY STATE3
10898 AESENCLAST KEY STATE4
10899+ pax_force_retaddr_bts
10900 ret
10901 ENDPROC(_aesni_enc4)
10902
10903@@ -2100,6 +2111,7 @@ ENTRY(aesni_dec)
10904 popl KLEN
10905 popl KEYP
10906 #endif
10907+ pax_force_retaddr 0, 1
10908 ret
10909 ENDPROC(aesni_dec)
10910
10911@@ -2158,6 +2170,7 @@ _aesni_dec1:
10912 AESDEC KEY STATE
10913 movaps 0x70(TKEYP), KEY
10914 AESDECLAST KEY STATE
10915+ pax_force_retaddr_bts
10916 ret
10917 ENDPROC(_aesni_dec1)
10918
10919@@ -2267,6 +2280,7 @@ _aesni_dec4:
10920 AESDECLAST KEY STATE2
10921 AESDECLAST KEY STATE3
10922 AESDECLAST KEY STATE4
10923+ pax_force_retaddr_bts
10924 ret
10925 ENDPROC(_aesni_dec4)
10926
10927@@ -2325,6 +2339,7 @@ ENTRY(aesni_ecb_enc)
10928 popl KEYP
10929 popl LEN
10930 #endif
10931+ pax_force_retaddr 0, 1
10932 ret
10933 ENDPROC(aesni_ecb_enc)
10934
10935@@ -2384,6 +2399,7 @@ ENTRY(aesni_ecb_dec)
10936 popl KEYP
10937 popl LEN
10938 #endif
10939+ pax_force_retaddr 0, 1
10940 ret
10941 ENDPROC(aesni_ecb_dec)
10942
10943@@ -2426,6 +2442,7 @@ ENTRY(aesni_cbc_enc)
10944 popl LEN
10945 popl IVP
10946 #endif
10947+ pax_force_retaddr 0, 1
10948 ret
10949 ENDPROC(aesni_cbc_enc)
10950
10951@@ -2517,6 +2534,7 @@ ENTRY(aesni_cbc_dec)
10952 popl LEN
10953 popl IVP
10954 #endif
10955+ pax_force_retaddr 0, 1
10956 ret
10957 ENDPROC(aesni_cbc_dec)
10958
10959@@ -2544,6 +2562,7 @@ _aesni_inc_init:
10960 mov $1, TCTR_LOW
10961 MOVQ_R64_XMM TCTR_LOW INC
10962 MOVQ_R64_XMM CTR TCTR_LOW
10963+ pax_force_retaddr_bts
10964 ret
10965 ENDPROC(_aesni_inc_init)
10966
10967@@ -2573,6 +2592,7 @@ _aesni_inc:
10968 .Linc_low:
10969 movaps CTR, IV
10970 PSHUFB_XMM BSWAP_MASK IV
10971+ pax_force_retaddr_bts
10972 ret
10973 ENDPROC(_aesni_inc)
10974
10975@@ -2634,6 +2654,7 @@ ENTRY(aesni_ctr_enc)
10976 .Lctr_enc_ret:
10977 movups IV, (IVP)
10978 .Lctr_enc_just_ret:
10979+ pax_force_retaddr 0, 1
10980 ret
10981 ENDPROC(aesni_ctr_enc)
10982 #endif
10983diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10984index 246c670..4d1ed00 100644
10985--- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
10986+++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
10987@@ -21,6 +21,7 @@
10988 */
10989
10990 #include <linux/linkage.h>
10991+#include <asm/alternative-asm.h>
10992
10993 .file "blowfish-x86_64-asm.S"
10994 .text
10995@@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
10996 jnz .L__enc_xor;
10997
10998 write_block();
10999+ pax_force_retaddr 0, 1
11000 ret;
11001 .L__enc_xor:
11002 xor_block();
11003+ pax_force_retaddr 0, 1
11004 ret;
11005 ENDPROC(__blowfish_enc_blk)
11006
11007@@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
11008
11009 movq %r11, %rbp;
11010
11011+ pax_force_retaddr 0, 1
11012 ret;
11013 ENDPROC(blowfish_dec_blk)
11014
11015@@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
11016
11017 popq %rbx;
11018 popq %rbp;
11019+ pax_force_retaddr 0, 1
11020 ret;
11021
11022 .L__enc_xor4:
11023@@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
11024
11025 popq %rbx;
11026 popq %rbp;
11027+ pax_force_retaddr 0, 1
11028 ret;
11029 ENDPROC(__blowfish_enc_blk_4way)
11030
11031@@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
11032 popq %rbx;
11033 popq %rbp;
11034
11035+ pax_force_retaddr 0, 1
11036 ret;
11037 ENDPROC(blowfish_dec_blk_4way)
11038diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
11039index 310319c..ce174a4 100644
11040--- a/arch/x86/crypto/camellia-x86_64-asm_64.S
11041+++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
11042@@ -21,6 +21,7 @@
11043 */
11044
11045 #include <linux/linkage.h>
11046+#include <asm/alternative-asm.h>
11047
11048 .file "camellia-x86_64-asm_64.S"
11049 .text
11050@@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
11051 enc_outunpack(mov, RT1);
11052
11053 movq RRBP, %rbp;
11054+ pax_force_retaddr 0, 1
11055 ret;
11056
11057 .L__enc_xor:
11058 enc_outunpack(xor, RT1);
11059
11060 movq RRBP, %rbp;
11061+ pax_force_retaddr 0, 1
11062 ret;
11063 ENDPROC(__camellia_enc_blk)
11064
11065@@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
11066 dec_outunpack();
11067
11068 movq RRBP, %rbp;
11069+ pax_force_retaddr 0, 1
11070 ret;
11071 ENDPROC(camellia_dec_blk)
11072
11073@@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
11074
11075 movq RRBP, %rbp;
11076 popq %rbx;
11077+ pax_force_retaddr 0, 1
11078 ret;
11079
11080 .L__enc2_xor:
11081@@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
11082
11083 movq RRBP, %rbp;
11084 popq %rbx;
11085+ pax_force_retaddr 0, 1
11086 ret;
11087 ENDPROC(__camellia_enc_blk_2way)
11088
11089@@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
11090
11091 movq RRBP, %rbp;
11092 movq RXOR, %rbx;
11093+ pax_force_retaddr 0, 1
11094 ret;
11095 ENDPROC(camellia_dec_blk_2way)
11096diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11097index c35fd5d..c1ee236 100644
11098--- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11099+++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
11100@@ -24,6 +24,7 @@
11101 */
11102
11103 #include <linux/linkage.h>
11104+#include <asm/alternative-asm.h>
11105
11106 .file "cast5-avx-x86_64-asm_64.S"
11107
11108@@ -281,6 +282,7 @@ __cast5_enc_blk16:
11109 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11110 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11111
11112+ pax_force_retaddr 0, 1
11113 ret;
11114 ENDPROC(__cast5_enc_blk16)
11115
11116@@ -352,6 +354,7 @@ __cast5_dec_blk16:
11117 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
11118 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
11119
11120+ pax_force_retaddr 0, 1
11121 ret;
11122
11123 .L__skip_dec:
11124@@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
11125 vmovdqu RR4, (6*4*4)(%r11);
11126 vmovdqu RL4, (7*4*4)(%r11);
11127
11128+ pax_force_retaddr
11129 ret;
11130 ENDPROC(cast5_ecb_enc_16way)
11131
11132@@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
11133 vmovdqu RR4, (6*4*4)(%r11);
11134 vmovdqu RL4, (7*4*4)(%r11);
11135
11136+ pax_force_retaddr
11137 ret;
11138 ENDPROC(cast5_ecb_dec_16way)
11139
11140@@ -469,6 +474,7 @@ ENTRY(cast5_cbc_dec_16way)
11141
11142 popq %r12;
11143
11144+ pax_force_retaddr
11145 ret;
11146 ENDPROC(cast5_cbc_dec_16way)
11147
11148@@ -542,5 +548,6 @@ ENTRY(cast5_ctr_16way)
11149
11150 popq %r12;
11151
11152+ pax_force_retaddr
11153 ret;
11154 ENDPROC(cast5_ctr_16way)
11155diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11156index f93b610..c09bf40 100644
11157--- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11158+++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
11159@@ -24,6 +24,7 @@
11160 */
11161
11162 #include <linux/linkage.h>
11163+#include <asm/alternative-asm.h>
11164 #include "glue_helper-asm-avx.S"
11165
11166 .file "cast6-avx-x86_64-asm_64.S"
11167@@ -293,6 +294,7 @@ __cast6_enc_blk8:
11168 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11169 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11170
11171+ pax_force_retaddr 0, 1
11172 ret;
11173 ENDPROC(__cast6_enc_blk8)
11174
11175@@ -338,6 +340,7 @@ __cast6_dec_blk8:
11176 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
11177 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
11178
11179+ pax_force_retaddr 0, 1
11180 ret;
11181 ENDPROC(__cast6_dec_blk8)
11182
11183@@ -356,6 +359,7 @@ ENTRY(cast6_ecb_enc_8way)
11184
11185 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11186
11187+ pax_force_retaddr
11188 ret;
11189 ENDPROC(cast6_ecb_enc_8way)
11190
11191@@ -374,6 +378,7 @@ ENTRY(cast6_ecb_dec_8way)
11192
11193 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11194
11195+ pax_force_retaddr
11196 ret;
11197 ENDPROC(cast6_ecb_dec_8way)
11198
11199@@ -397,6 +402,7 @@ ENTRY(cast6_cbc_dec_8way)
11200
11201 popq %r12;
11202
11203+ pax_force_retaddr
11204 ret;
11205 ENDPROC(cast6_cbc_dec_8way)
11206
11207@@ -422,5 +428,6 @@ ENTRY(cast6_ctr_8way)
11208
11209 popq %r12;
11210
11211+ pax_force_retaddr
11212 ret;
11213 ENDPROC(cast6_ctr_8way)
11214diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11215index 9279e0b..9270820 100644
11216--- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
11217+++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
11218@@ -1,4 +1,5 @@
11219 #include <linux/linkage.h>
11220+#include <asm/alternative-asm.h>
11221
11222 # enter salsa20_encrypt_bytes
11223 ENTRY(salsa20_encrypt_bytes)
11224@@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
11225 add %r11,%rsp
11226 mov %rdi,%rax
11227 mov %rsi,%rdx
11228+ pax_force_retaddr 0, 1
11229 ret
11230 # bytesatleast65:
11231 ._bytesatleast65:
11232@@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
11233 add %r11,%rsp
11234 mov %rdi,%rax
11235 mov %rsi,%rdx
11236+ pax_force_retaddr
11237 ret
11238 ENDPROC(salsa20_keysetup)
11239
11240@@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
11241 add %r11,%rsp
11242 mov %rdi,%rax
11243 mov %rsi,%rdx
11244+ pax_force_retaddr
11245 ret
11246 ENDPROC(salsa20_ivsetup)
11247diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11248index 43c9386..a0e2d60 100644
11249--- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11250+++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
11251@@ -25,6 +25,7 @@
11252 */
11253
11254 #include <linux/linkage.h>
11255+#include <asm/alternative-asm.h>
11256 #include "glue_helper-asm-avx.S"
11257
11258 .file "serpent-avx-x86_64-asm_64.S"
11259@@ -617,6 +618,7 @@ __serpent_enc_blk8_avx:
11260 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11261 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11262
11263+ pax_force_retaddr
11264 ret;
11265 ENDPROC(__serpent_enc_blk8_avx)
11266
11267@@ -671,6 +673,7 @@ __serpent_dec_blk8_avx:
11268 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11269 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11270
11271+ pax_force_retaddr
11272 ret;
11273 ENDPROC(__serpent_dec_blk8_avx)
11274
11275@@ -687,6 +690,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
11276
11277 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11278
11279+ pax_force_retaddr
11280 ret;
11281 ENDPROC(serpent_ecb_enc_8way_avx)
11282
11283@@ -703,6 +707,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
11284
11285 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11286
11287+ pax_force_retaddr
11288 ret;
11289 ENDPROC(serpent_ecb_dec_8way_avx)
11290
11291@@ -719,6 +724,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
11292
11293 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
11294
11295+ pax_force_retaddr
11296 ret;
11297 ENDPROC(serpent_cbc_dec_8way_avx)
11298
11299@@ -737,5 +743,6 @@ ENTRY(serpent_ctr_8way_avx)
11300
11301 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11302
11303+ pax_force_retaddr
11304 ret;
11305 ENDPROC(serpent_ctr_8way_avx)
11306diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11307index acc066c..1559cc4 100644
11308--- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11309+++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
11310@@ -25,6 +25,7 @@
11311 */
11312
11313 #include <linux/linkage.h>
11314+#include <asm/alternative-asm.h>
11315
11316 .file "serpent-sse2-x86_64-asm_64.S"
11317 .text
11318@@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
11319 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11320 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11321
11322+ pax_force_retaddr
11323 ret;
11324
11325 .L__enc_xor8:
11326 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
11327 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
11328
11329+ pax_force_retaddr
11330 ret;
11331 ENDPROC(__serpent_enc_blk_8way)
11332
11333@@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
11334 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
11335 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
11336
11337+ pax_force_retaddr
11338 ret;
11339 ENDPROC(serpent_dec_blk_8way)
11340diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
11341index a410950..3356d42 100644
11342--- a/arch/x86/crypto/sha1_ssse3_asm.S
11343+++ b/arch/x86/crypto/sha1_ssse3_asm.S
11344@@ -29,6 +29,7 @@
11345 */
11346
11347 #include <linux/linkage.h>
11348+#include <asm/alternative-asm.h>
11349
11350 #define CTX %rdi // arg1
11351 #define BUF %rsi // arg2
11352@@ -104,6 +105,7 @@
11353 pop %r12
11354 pop %rbp
11355 pop %rbx
11356+ pax_force_retaddr 0, 1
11357 ret
11358
11359 ENDPROC(\name)
11360diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11361index 8d3e113..898b161 100644
11362--- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11363+++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
11364@@ -24,6 +24,7 @@
11365 */
11366
11367 #include <linux/linkage.h>
11368+#include <asm/alternative-asm.h>
11369 #include "glue_helper-asm-avx.S"
11370
11371 .file "twofish-avx-x86_64-asm_64.S"
11372@@ -282,6 +283,7 @@ __twofish_enc_blk8:
11373 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
11374 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
11375
11376+ pax_force_retaddr 0, 1
11377 ret;
11378 ENDPROC(__twofish_enc_blk8)
11379
11380@@ -322,6 +324,7 @@ __twofish_dec_blk8:
11381 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
11382 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
11383
11384+ pax_force_retaddr 0, 1
11385 ret;
11386 ENDPROC(__twofish_dec_blk8)
11387
11388@@ -340,6 +343,7 @@ ENTRY(twofish_ecb_enc_8way)
11389
11390 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
11391
11392+ pax_force_retaddr 0, 1
11393 ret;
11394 ENDPROC(twofish_ecb_enc_8way)
11395
11396@@ -358,6 +362,7 @@ ENTRY(twofish_ecb_dec_8way)
11397
11398 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
11399
11400+ pax_force_retaddr 0, 1
11401 ret;
11402 ENDPROC(twofish_ecb_dec_8way)
11403
11404@@ -381,6 +386,7 @@ ENTRY(twofish_cbc_dec_8way)
11405
11406 popq %r12;
11407
11408+ pax_force_retaddr 0, 1
11409 ret;
11410 ENDPROC(twofish_cbc_dec_8way)
11411
11412@@ -406,5 +412,6 @@ ENTRY(twofish_ctr_8way)
11413
11414 popq %r12;
11415
11416+ pax_force_retaddr 0, 1
11417 ret;
11418 ENDPROC(twofish_ctr_8way)
11419diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11420index 1c3b7ce..b365c5e 100644
11421--- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11422+++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
11423@@ -21,6 +21,7 @@
11424 */
11425
11426 #include <linux/linkage.h>
11427+#include <asm/alternative-asm.h>
11428
11429 .file "twofish-x86_64-asm-3way.S"
11430 .text
11431@@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
11432 popq %r13;
11433 popq %r14;
11434 popq %r15;
11435+ pax_force_retaddr 0, 1
11436 ret;
11437
11438 .L__enc_xor3:
11439@@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
11440 popq %r13;
11441 popq %r14;
11442 popq %r15;
11443+ pax_force_retaddr 0, 1
11444 ret;
11445 ENDPROC(__twofish_enc_blk_3way)
11446
11447@@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
11448 popq %r13;
11449 popq %r14;
11450 popq %r15;
11451+ pax_force_retaddr 0, 1
11452 ret;
11453 ENDPROC(twofish_dec_blk_3way)
11454diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
11455index a039d21..29e7615 100644
11456--- a/arch/x86/crypto/twofish-x86_64-asm_64.S
11457+++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
11458@@ -22,6 +22,7 @@
11459
11460 #include <linux/linkage.h>
11461 #include <asm/asm-offsets.h>
11462+#include <asm/alternative-asm.h>
11463
11464 #define a_offset 0
11465 #define b_offset 4
11466@@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
11467
11468 popq R1
11469 movq $1,%rax
11470+ pax_force_retaddr 0, 1
11471 ret
11472 ENDPROC(twofish_enc_blk)
11473
11474@@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
11475
11476 popq R1
11477 movq $1,%rax
11478+ pax_force_retaddr 0, 1
11479 ret
11480 ENDPROC(twofish_dec_blk)
11481diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
11482index 03abf9b..a42ba29 100644
11483--- a/arch/x86/ia32/ia32_aout.c
11484+++ b/arch/x86/ia32/ia32_aout.c
11485@@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
11486 unsigned long dump_start, dump_size;
11487 struct user32 dump;
11488
11489+ memset(&dump, 0, sizeof(dump));
11490+
11491 fs = get_fs();
11492 set_fs(KERNEL_DS);
11493 has_dumped = 1;
11494diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
11495index cf1a471..3bc4cf8 100644
11496--- a/arch/x86/ia32/ia32_signal.c
11497+++ b/arch/x86/ia32/ia32_signal.c
11498@@ -340,7 +340,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
11499 sp -= frame_size;
11500 /* Align the stack pointer according to the i386 ABI,
11501 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
11502- sp = ((sp + 4) & -16ul) - 4;
11503+ sp = ((sp - 12) & -16ul) - 4;
11504 return (void __user *) sp;
11505 }
11506
11507@@ -398,7 +398,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
11508 * These are actually not used anymore, but left because some
11509 * gdb versions depend on them as a marker.
11510 */
11511- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11512+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11513 } put_user_catch(err);
11514
11515 if (err)
11516@@ -440,7 +440,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11517 0xb8,
11518 __NR_ia32_rt_sigreturn,
11519 0x80cd,
11520- 0,
11521+ 0
11522 };
11523
11524 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
11525@@ -463,16 +463,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
11526
11527 if (ksig->ka.sa.sa_flags & SA_RESTORER)
11528 restorer = ksig->ka.sa.sa_restorer;
11529+ else if (current->mm->context.vdso)
11530+ /* Return stub is in 32bit vsyscall page */
11531+ restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
11532 else
11533- restorer = VDSO32_SYMBOL(current->mm->context.vdso,
11534- rt_sigreturn);
11535+ restorer = &frame->retcode;
11536 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
11537
11538 /*
11539 * Not actually used anymore, but left because some gdb
11540 * versions need it.
11541 */
11542- put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
11543+ put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
11544 } put_user_catch(err);
11545
11546 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
11547diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
11548index 474dc1b..be7bff5 100644
11549--- a/arch/x86/ia32/ia32entry.S
11550+++ b/arch/x86/ia32/ia32entry.S
11551@@ -15,8 +15,10 @@
11552 #include <asm/irqflags.h>
11553 #include <asm/asm.h>
11554 #include <asm/smap.h>
11555+#include <asm/pgtable.h>
11556 #include <linux/linkage.h>
11557 #include <linux/err.h>
11558+#include <asm/alternative-asm.h>
11559
11560 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
11561 #include <linux/elf-em.h>
11562@@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
11563 ENDPROC(native_irq_enable_sysexit)
11564 #endif
11565
11566+ .macro pax_enter_kernel_user
11567+ pax_set_fptr_mask
11568+#ifdef CONFIG_PAX_MEMORY_UDEREF
11569+ call pax_enter_kernel_user
11570+#endif
11571+ .endm
11572+
11573+ .macro pax_exit_kernel_user
11574+#ifdef CONFIG_PAX_MEMORY_UDEREF
11575+ call pax_exit_kernel_user
11576+#endif
11577+#ifdef CONFIG_PAX_RANDKSTACK
11578+ pushq %rax
11579+ pushq %r11
11580+ call pax_randomize_kstack
11581+ popq %r11
11582+ popq %rax
11583+#endif
11584+ .endm
11585+
11586+.macro pax_erase_kstack
11587+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
11588+ call pax_erase_kstack
11589+#endif
11590+.endm
11591+
11592 /*
11593 * 32bit SYSENTER instruction entry.
11594 *
11595@@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
11596 CFI_REGISTER rsp,rbp
11597 SWAPGS_UNSAFE_STACK
11598 movq PER_CPU_VAR(kernel_stack), %rsp
11599- addq $(KERNEL_STACK_OFFSET),%rsp
11600- /*
11601- * No need to follow this irqs on/off section: the syscall
11602- * disabled irqs, here we enable it straight after entry:
11603- */
11604- ENABLE_INTERRUPTS(CLBR_NONE)
11605 movl %ebp,%ebp /* zero extension */
11606 pushq_cfi $__USER32_DS
11607 /*CFI_REL_OFFSET ss,0*/
11608@@ -135,24 +157,44 @@ ENTRY(ia32_sysenter_target)
11609 CFI_REL_OFFSET rsp,0
11610 pushfq_cfi
11611 /*CFI_REL_OFFSET rflags,0*/
11612- movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
11613- CFI_REGISTER rip,r10
11614+ orl $X86_EFLAGS_IF,(%rsp)
11615+ GET_THREAD_INFO(%r11)
11616+ movl TI_sysenter_return(%r11), %r11d
11617+ CFI_REGISTER rip,r11
11618 pushq_cfi $__USER32_CS
11619 /*CFI_REL_OFFSET cs,0*/
11620 movl %eax, %eax
11621- pushq_cfi %r10
11622+ pushq_cfi %r11
11623 CFI_REL_OFFSET rip,0
11624 pushq_cfi %rax
11625 cld
11626 SAVE_ARGS 0,1,0
11627+ pax_enter_kernel_user
11628+
11629+#ifdef CONFIG_PAX_RANDKSTACK
11630+ pax_erase_kstack
11631+#endif
11632+
11633+ /*
11634+ * No need to follow this irqs on/off section: the syscall
11635+ * disabled irqs, here we enable it straight after entry:
11636+ */
11637+ ENABLE_INTERRUPTS(CLBR_NONE)
11638 /* no need to do an access_ok check here because rbp has been
11639 32bit zero extended */
11640+
11641+#ifdef CONFIG_PAX_MEMORY_UDEREF
11642+ mov pax_user_shadow_base,%r11
11643+ add %r11,%rbp
11644+#endif
11645+
11646 ASM_STAC
11647 1: movl (%rbp),%ebp
11648 _ASM_EXTABLE(1b,ia32_badarg)
11649 ASM_CLAC
11650- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11651- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11652+ GET_THREAD_INFO(%r11)
11653+ orl $TS_COMPAT,TI_status(%r11)
11654+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11655 CFI_REMEMBER_STATE
11656 jnz sysenter_tracesys
11657 cmpq $(IA32_NR_syscalls-1),%rax
11658@@ -162,12 +204,15 @@ sysenter_do_call:
11659 sysenter_dispatch:
11660 call *ia32_sys_call_table(,%rax,8)
11661 movq %rax,RAX-ARGOFFSET(%rsp)
11662+ GET_THREAD_INFO(%r11)
11663 DISABLE_INTERRUPTS(CLBR_NONE)
11664 TRACE_IRQS_OFF
11665- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11666+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11667 jnz sysexit_audit
11668 sysexit_from_sys_call:
11669- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11670+ pax_exit_kernel_user
11671+ pax_erase_kstack
11672+ andl $~TS_COMPAT,TI_status(%r11)
11673 /* clear IF, that popfq doesn't enable interrupts early */
11674 andl $~0x200,EFLAGS-R11(%rsp)
11675 movl RIP-R11(%rsp),%edx /* User %eip */
11676@@ -193,6 +238,9 @@ sysexit_from_sys_call:
11677 movl %eax,%esi /* 2nd arg: syscall number */
11678 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
11679 call __audit_syscall_entry
11680+
11681+ pax_erase_kstack
11682+
11683 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
11684 cmpq $(IA32_NR_syscalls-1),%rax
11685 ja ia32_badsys
11686@@ -204,7 +252,7 @@ sysexit_from_sys_call:
11687 .endm
11688
11689 .macro auditsys_exit exit
11690- testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11691+ testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11692 jnz ia32_ret_from_sys_call
11693 TRACE_IRQS_ON
11694 ENABLE_INTERRUPTS(CLBR_NONE)
11695@@ -215,11 +263,12 @@ sysexit_from_sys_call:
11696 1: setbe %al /* 1 if error, 0 if not */
11697 movzbl %al,%edi /* zero-extend that into %edi */
11698 call __audit_syscall_exit
11699+ GET_THREAD_INFO(%r11)
11700 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
11701 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
11702 DISABLE_INTERRUPTS(CLBR_NONE)
11703 TRACE_IRQS_OFF
11704- testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11705+ testl %edi,TI_flags(%r11)
11706 jz \exit
11707 CLEAR_RREGS -ARGOFFSET
11708 jmp int_with_check
11709@@ -237,7 +286,7 @@ sysexit_audit:
11710
11711 sysenter_tracesys:
11712 #ifdef CONFIG_AUDITSYSCALL
11713- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11714+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11715 jz sysenter_auditsys
11716 #endif
11717 SAVE_REST
11718@@ -249,6 +298,9 @@ sysenter_tracesys:
11719 RESTORE_REST
11720 cmpq $(IA32_NR_syscalls-1),%rax
11721 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
11722+
11723+ pax_erase_kstack
11724+
11725 jmp sysenter_do_call
11726 CFI_ENDPROC
11727 ENDPROC(ia32_sysenter_target)
11728@@ -276,19 +328,25 @@ ENDPROC(ia32_sysenter_target)
11729 ENTRY(ia32_cstar_target)
11730 CFI_STARTPROC32 simple
11731 CFI_SIGNAL_FRAME
11732- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
11733+ CFI_DEF_CFA rsp,0
11734 CFI_REGISTER rip,rcx
11735 /*CFI_REGISTER rflags,r11*/
11736 SWAPGS_UNSAFE_STACK
11737 movl %esp,%r8d
11738 CFI_REGISTER rsp,r8
11739 movq PER_CPU_VAR(kernel_stack),%rsp
11740+ SAVE_ARGS 8*6,0,0
11741+ pax_enter_kernel_user
11742+
11743+#ifdef CONFIG_PAX_RANDKSTACK
11744+ pax_erase_kstack
11745+#endif
11746+
11747 /*
11748 * No need to follow this irqs on/off section: the syscall
11749 * disabled irqs and here we enable it straight after entry:
11750 */
11751 ENABLE_INTERRUPTS(CLBR_NONE)
11752- SAVE_ARGS 8,0,0
11753 movl %eax,%eax /* zero extension */
11754 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
11755 movq %rcx,RIP-ARGOFFSET(%rsp)
11756@@ -304,12 +362,19 @@ ENTRY(ia32_cstar_target)
11757 /* no need to do an access_ok check here because r8 has been
11758 32bit zero extended */
11759 /* hardware stack frame is complete now */
11760+
11761+#ifdef CONFIG_PAX_MEMORY_UDEREF
11762+ mov pax_user_shadow_base,%r11
11763+ add %r11,%r8
11764+#endif
11765+
11766 ASM_STAC
11767 1: movl (%r8),%r9d
11768 _ASM_EXTABLE(1b,ia32_badarg)
11769 ASM_CLAC
11770- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11771- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11772+ GET_THREAD_INFO(%r11)
11773+ orl $TS_COMPAT,TI_status(%r11)
11774+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11775 CFI_REMEMBER_STATE
11776 jnz cstar_tracesys
11777 cmpq $IA32_NR_syscalls-1,%rax
11778@@ -319,12 +384,15 @@ cstar_do_call:
11779 cstar_dispatch:
11780 call *ia32_sys_call_table(,%rax,8)
11781 movq %rax,RAX-ARGOFFSET(%rsp)
11782+ GET_THREAD_INFO(%r11)
11783 DISABLE_INTERRUPTS(CLBR_NONE)
11784 TRACE_IRQS_OFF
11785- testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11786+ testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
11787 jnz sysretl_audit
11788 sysretl_from_sys_call:
11789- andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11790+ pax_exit_kernel_user
11791+ pax_erase_kstack
11792+ andl $~TS_COMPAT,TI_status(%r11)
11793 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
11794 movl RIP-ARGOFFSET(%rsp),%ecx
11795 CFI_REGISTER rip,rcx
11796@@ -352,7 +420,7 @@ sysretl_audit:
11797
11798 cstar_tracesys:
11799 #ifdef CONFIG_AUDITSYSCALL
11800- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11801+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
11802 jz cstar_auditsys
11803 #endif
11804 xchgl %r9d,%ebp
11805@@ -366,6 +434,9 @@ cstar_tracesys:
11806 xchgl %ebp,%r9d
11807 cmpq $(IA32_NR_syscalls-1),%rax
11808 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
11809+
11810+ pax_erase_kstack
11811+
11812 jmp cstar_do_call
11813 END(ia32_cstar_target)
11814
11815@@ -407,19 +478,26 @@ ENTRY(ia32_syscall)
11816 CFI_REL_OFFSET rip,RIP-RIP
11817 PARAVIRT_ADJUST_EXCEPTION_FRAME
11818 SWAPGS
11819- /*
11820- * No need to follow this irqs on/off section: the syscall
11821- * disabled irqs and here we enable it straight after entry:
11822- */
11823- ENABLE_INTERRUPTS(CLBR_NONE)
11824 movl %eax,%eax
11825 pushq_cfi %rax
11826 cld
11827 /* note the registers are not zero extended to the sf.
11828 this could be a problem. */
11829 SAVE_ARGS 0,1,0
11830- orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11831- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
11832+ pax_enter_kernel_user
11833+
11834+#ifdef CONFIG_PAX_RANDKSTACK
11835+ pax_erase_kstack
11836+#endif
11837+
11838+ /*
11839+ * No need to follow this irqs on/off section: the syscall
11840+ * disabled irqs and here we enable it straight after entry:
11841+ */
11842+ ENABLE_INTERRUPTS(CLBR_NONE)
11843+ GET_THREAD_INFO(%r11)
11844+ orl $TS_COMPAT,TI_status(%r11)
11845+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
11846 jnz ia32_tracesys
11847 cmpq $(IA32_NR_syscalls-1),%rax
11848 ja ia32_badsys
11849@@ -442,6 +520,9 @@ ia32_tracesys:
11850 RESTORE_REST
11851 cmpq $(IA32_NR_syscalls-1),%rax
11852 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
11853+
11854+ pax_erase_kstack
11855+
11856 jmp ia32_do_call
11857 END(ia32_syscall)
11858
11859diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
11860index ad7a20c..1ffa3c1 100644
11861--- a/arch/x86/ia32/sys_ia32.c
11862+++ b/arch/x86/ia32/sys_ia32.c
11863@@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
11864 */
11865 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
11866 {
11867- typeof(ubuf->st_uid) uid = 0;
11868- typeof(ubuf->st_gid) gid = 0;
11869+ typeof(((struct stat64 *)0)->st_uid) uid = 0;
11870+ typeof(((struct stat64 *)0)->st_gid) gid = 0;
11871 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
11872 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
11873 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
11874@@ -205,7 +205,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
11875 return -EFAULT;
11876
11877 set_fs(KERNEL_DS);
11878- ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
11879+ ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
11880 count);
11881 set_fs(old_fs);
11882
11883diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
11884index 372231c..a5aa1a1 100644
11885--- a/arch/x86/include/asm/alternative-asm.h
11886+++ b/arch/x86/include/asm/alternative-asm.h
11887@@ -18,6 +18,45 @@
11888 .endm
11889 #endif
11890
11891+#ifdef KERNEXEC_PLUGIN
11892+ .macro pax_force_retaddr_bts rip=0
11893+ btsq $63,\rip(%rsp)
11894+ .endm
11895+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11896+ .macro pax_force_retaddr rip=0, reload=0
11897+ btsq $63,\rip(%rsp)
11898+ .endm
11899+ .macro pax_force_fptr ptr
11900+ btsq $63,\ptr
11901+ .endm
11902+ .macro pax_set_fptr_mask
11903+ .endm
11904+#endif
11905+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
11906+ .macro pax_force_retaddr rip=0, reload=0
11907+ .if \reload
11908+ pax_set_fptr_mask
11909+ .endif
11910+ orq %r10,\rip(%rsp)
11911+ .endm
11912+ .macro pax_force_fptr ptr
11913+ orq %r10,\ptr
11914+ .endm
11915+ .macro pax_set_fptr_mask
11916+ movabs $0x8000000000000000,%r10
11917+ .endm
11918+#endif
11919+#else
11920+ .macro pax_force_retaddr rip=0, reload=0
11921+ .endm
11922+ .macro pax_force_fptr ptr
11923+ .endm
11924+ .macro pax_force_retaddr_bts rip=0
11925+ .endm
11926+ .macro pax_set_fptr_mask
11927+ .endm
11928+#endif
11929+
11930 .macro altinstruction_entry orig alt feature orig_len alt_len
11931 .long \orig - .
11932 .long \alt - .
11933diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
11934index 58ed6d9..f1cbe58 100644
11935--- a/arch/x86/include/asm/alternative.h
11936+++ b/arch/x86/include/asm/alternative.h
11937@@ -105,7 +105,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11938 ".pushsection .discard,\"aw\",@progbits\n" \
11939 DISCARD_ENTRY(1) \
11940 ".popsection\n" \
11941- ".pushsection .altinstr_replacement, \"ax\"\n" \
11942+ ".pushsection .altinstr_replacement, \"a\"\n" \
11943 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
11944 ".popsection"
11945
11946@@ -119,7 +119,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
11947 DISCARD_ENTRY(1) \
11948 DISCARD_ENTRY(2) \
11949 ".popsection\n" \
11950- ".pushsection .altinstr_replacement, \"ax\"\n" \
11951+ ".pushsection .altinstr_replacement, \"a\"\n" \
11952 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
11953 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
11954 ".popsection"
11955diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
11956index 3388034..050f0b9 100644
11957--- a/arch/x86/include/asm/apic.h
11958+++ b/arch/x86/include/asm/apic.h
11959@@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
11960
11961 #ifdef CONFIG_X86_LOCAL_APIC
11962
11963-extern unsigned int apic_verbosity;
11964+extern int apic_verbosity;
11965 extern int local_apic_timer_c2_ok;
11966
11967 extern int disable_apic;
11968diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
11969index 20370c6..a2eb9b0 100644
11970--- a/arch/x86/include/asm/apm.h
11971+++ b/arch/x86/include/asm/apm.h
11972@@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
11973 __asm__ __volatile__(APM_DO_ZERO_SEGS
11974 "pushl %%edi\n\t"
11975 "pushl %%ebp\n\t"
11976- "lcall *%%cs:apm_bios_entry\n\t"
11977+ "lcall *%%ss:apm_bios_entry\n\t"
11978 "setc %%al\n\t"
11979 "popl %%ebp\n\t"
11980 "popl %%edi\n\t"
11981@@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
11982 __asm__ __volatile__(APM_DO_ZERO_SEGS
11983 "pushl %%edi\n\t"
11984 "pushl %%ebp\n\t"
11985- "lcall *%%cs:apm_bios_entry\n\t"
11986+ "lcall *%%ss:apm_bios_entry\n\t"
11987 "setc %%bl\n\t"
11988 "popl %%ebp\n\t"
11989 "popl %%edi\n\t"
11990diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
11991index 722aa3b..3a0bb27 100644
11992--- a/arch/x86/include/asm/atomic.h
11993+++ b/arch/x86/include/asm/atomic.h
11994@@ -22,7 +22,18 @@
11995 */
11996 static inline int atomic_read(const atomic_t *v)
11997 {
11998- return (*(volatile int *)&(v)->counter);
11999+ return (*(volatile const int *)&(v)->counter);
12000+}
12001+
12002+/**
12003+ * atomic_read_unchecked - read atomic variable
12004+ * @v: pointer of type atomic_unchecked_t
12005+ *
12006+ * Atomically reads the value of @v.
12007+ */
12008+static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
12009+{
12010+ return (*(volatile const int *)&(v)->counter);
12011 }
12012
12013 /**
12014@@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
12015 }
12016
12017 /**
12018+ * atomic_set_unchecked - set atomic variable
12019+ * @v: pointer of type atomic_unchecked_t
12020+ * @i: required value
12021+ *
12022+ * Atomically sets the value of @v to @i.
12023+ */
12024+static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
12025+{
12026+ v->counter = i;
12027+}
12028+
12029+/**
12030 * atomic_add - add integer to atomic variable
12031 * @i: integer value to add
12032 * @v: pointer of type atomic_t
12033@@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
12034 */
12035 static inline void atomic_add(int i, atomic_t *v)
12036 {
12037- asm volatile(LOCK_PREFIX "addl %1,%0"
12038+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12039+
12040+#ifdef CONFIG_PAX_REFCOUNT
12041+ "jno 0f\n"
12042+ LOCK_PREFIX "subl %1,%0\n"
12043+ "int $4\n0:\n"
12044+ _ASM_EXTABLE(0b, 0b)
12045+#endif
12046+
12047+ : "+m" (v->counter)
12048+ : "ir" (i));
12049+}
12050+
12051+/**
12052+ * atomic_add_unchecked - add integer to atomic variable
12053+ * @i: integer value to add
12054+ * @v: pointer of type atomic_unchecked_t
12055+ *
12056+ * Atomically adds @i to @v.
12057+ */
12058+static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
12059+{
12060+ asm volatile(LOCK_PREFIX "addl %1,%0\n"
12061 : "+m" (v->counter)
12062 : "ir" (i));
12063 }
12064@@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
12065 */
12066 static inline void atomic_sub(int i, atomic_t *v)
12067 {
12068- asm volatile(LOCK_PREFIX "subl %1,%0"
12069+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12070+
12071+#ifdef CONFIG_PAX_REFCOUNT
12072+ "jno 0f\n"
12073+ LOCK_PREFIX "addl %1,%0\n"
12074+ "int $4\n0:\n"
12075+ _ASM_EXTABLE(0b, 0b)
12076+#endif
12077+
12078+ : "+m" (v->counter)
12079+ : "ir" (i));
12080+}
12081+
12082+/**
12083+ * atomic_sub_unchecked - subtract integer from atomic variable
12084+ * @i: integer value to subtract
12085+ * @v: pointer of type atomic_unchecked_t
12086+ *
12087+ * Atomically subtracts @i from @v.
12088+ */
12089+static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
12090+{
12091+ asm volatile(LOCK_PREFIX "subl %1,%0\n"
12092 : "+m" (v->counter)
12093 : "ir" (i));
12094 }
12095@@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12096 {
12097 unsigned char c;
12098
12099- asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
12100+ asm volatile(LOCK_PREFIX "subl %2,%0\n"
12101+
12102+#ifdef CONFIG_PAX_REFCOUNT
12103+ "jno 0f\n"
12104+ LOCK_PREFIX "addl %2,%0\n"
12105+ "int $4\n0:\n"
12106+ _ASM_EXTABLE(0b, 0b)
12107+#endif
12108+
12109+ "sete %1\n"
12110 : "+m" (v->counter), "=qm" (c)
12111 : "ir" (i) : "memory");
12112 return c;
12113@@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
12114 */
12115 static inline void atomic_inc(atomic_t *v)
12116 {
12117- asm volatile(LOCK_PREFIX "incl %0"
12118+ asm volatile(LOCK_PREFIX "incl %0\n"
12119+
12120+#ifdef CONFIG_PAX_REFCOUNT
12121+ "jno 0f\n"
12122+ LOCK_PREFIX "decl %0\n"
12123+ "int $4\n0:\n"
12124+ _ASM_EXTABLE(0b, 0b)
12125+#endif
12126+
12127+ : "+m" (v->counter));
12128+}
12129+
12130+/**
12131+ * atomic_inc_unchecked - increment atomic variable
12132+ * @v: pointer of type atomic_unchecked_t
12133+ *
12134+ * Atomically increments @v by 1.
12135+ */
12136+static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
12137+{
12138+ asm volatile(LOCK_PREFIX "incl %0\n"
12139 : "+m" (v->counter));
12140 }
12141
12142@@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
12143 */
12144 static inline void atomic_dec(atomic_t *v)
12145 {
12146- asm volatile(LOCK_PREFIX "decl %0"
12147+ asm volatile(LOCK_PREFIX "decl %0\n"
12148+
12149+#ifdef CONFIG_PAX_REFCOUNT
12150+ "jno 0f\n"
12151+ LOCK_PREFIX "incl %0\n"
12152+ "int $4\n0:\n"
12153+ _ASM_EXTABLE(0b, 0b)
12154+#endif
12155+
12156+ : "+m" (v->counter));
12157+}
12158+
12159+/**
12160+ * atomic_dec_unchecked - decrement atomic variable
12161+ * @v: pointer of type atomic_unchecked_t
12162+ *
12163+ * Atomically decrements @v by 1.
12164+ */
12165+static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
12166+{
12167+ asm volatile(LOCK_PREFIX "decl %0\n"
12168 : "+m" (v->counter));
12169 }
12170
12171@@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
12172 {
12173 unsigned char c;
12174
12175- asm volatile(LOCK_PREFIX "decl %0; sete %1"
12176+ asm volatile(LOCK_PREFIX "decl %0\n"
12177+
12178+#ifdef CONFIG_PAX_REFCOUNT
12179+ "jno 0f\n"
12180+ LOCK_PREFIX "incl %0\n"
12181+ "int $4\n0:\n"
12182+ _ASM_EXTABLE(0b, 0b)
12183+#endif
12184+
12185+ "sete %1\n"
12186 : "+m" (v->counter), "=qm" (c)
12187 : : "memory");
12188 return c != 0;
12189@@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
12190 {
12191 unsigned char c;
12192
12193- asm volatile(LOCK_PREFIX "incl %0; sete %1"
12194+ asm volatile(LOCK_PREFIX "incl %0\n"
12195+
12196+#ifdef CONFIG_PAX_REFCOUNT
12197+ "jno 0f\n"
12198+ LOCK_PREFIX "decl %0\n"
12199+ "int $4\n0:\n"
12200+ _ASM_EXTABLE(0b, 0b)
12201+#endif
12202+
12203+ "sete %1\n"
12204+ : "+m" (v->counter), "=qm" (c)
12205+ : : "memory");
12206+ return c != 0;
12207+}
12208+
12209+/**
12210+ * atomic_inc_and_test_unchecked - increment and test
12211+ * @v: pointer of type atomic_unchecked_t
12212+ *
12213+ * Atomically increments @v by 1
12214+ * and returns true if the result is zero, or false for all
12215+ * other cases.
12216+ */
12217+static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
12218+{
12219+ unsigned char c;
12220+
12221+ asm volatile(LOCK_PREFIX "incl %0\n"
12222+ "sete %1\n"
12223 : "+m" (v->counter), "=qm" (c)
12224 : : "memory");
12225 return c != 0;
12226@@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12227 {
12228 unsigned char c;
12229
12230- asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
12231+ asm volatile(LOCK_PREFIX "addl %2,%0\n"
12232+
12233+#ifdef CONFIG_PAX_REFCOUNT
12234+ "jno 0f\n"
12235+ LOCK_PREFIX "subl %2,%0\n"
12236+ "int $4\n0:\n"
12237+ _ASM_EXTABLE(0b, 0b)
12238+#endif
12239+
12240+ "sets %1\n"
12241 : "+m" (v->counter), "=qm" (c)
12242 : "ir" (i) : "memory");
12243 return c;
12244@@ -172,6 +334,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
12245 */
12246 static inline int atomic_add_return(int i, atomic_t *v)
12247 {
12248+ return i + xadd_check_overflow(&v->counter, i);
12249+}
12250+
12251+/**
12252+ * atomic_add_return_unchecked - add integer and return
12253+ * @i: integer value to add
12254+ * @v: pointer of type atomic_unchecked_t
12255+ *
12256+ * Atomically adds @i to @v and returns @i + @v
12257+ */
12258+static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
12259+{
12260 return i + xadd(&v->counter, i);
12261 }
12262
12263@@ -188,6 +362,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
12264 }
12265
12266 #define atomic_inc_return(v) (atomic_add_return(1, v))
12267+static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
12268+{
12269+ return atomic_add_return_unchecked(1, v);
12270+}
12271 #define atomic_dec_return(v) (atomic_sub_return(1, v))
12272
12273 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12274@@ -195,11 +373,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
12275 return cmpxchg(&v->counter, old, new);
12276 }
12277
12278+static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
12279+{
12280+ return cmpxchg(&v->counter, old, new);
12281+}
12282+
12283 static inline int atomic_xchg(atomic_t *v, int new)
12284 {
12285 return xchg(&v->counter, new);
12286 }
12287
12288+static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
12289+{
12290+ return xchg(&v->counter, new);
12291+}
12292+
12293 /**
12294 * __atomic_add_unless - add unless the number is already a given value
12295 * @v: pointer of type atomic_t
12296@@ -211,12 +399,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
12297 */
12298 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12299 {
12300- int c, old;
12301+ int c, old, new;
12302 c = atomic_read(v);
12303 for (;;) {
12304- if (unlikely(c == (u)))
12305+ if (unlikely(c == u))
12306 break;
12307- old = atomic_cmpxchg((v), c, c + (a));
12308+
12309+ asm volatile("addl %2,%0\n"
12310+
12311+#ifdef CONFIG_PAX_REFCOUNT
12312+ "jno 0f\n"
12313+ "subl %2,%0\n"
12314+ "int $4\n0:\n"
12315+ _ASM_EXTABLE(0b, 0b)
12316+#endif
12317+
12318+ : "=r" (new)
12319+ : "0" (c), "ir" (a));
12320+
12321+ old = atomic_cmpxchg(v, c, new);
12322 if (likely(old == c))
12323 break;
12324 c = old;
12325@@ -225,6 +426,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
12326 }
12327
12328 /**
12329+ * atomic_inc_not_zero_hint - increment if not null
12330+ * @v: pointer of type atomic_t
12331+ * @hint: probable value of the atomic before the increment
12332+ *
12333+ * This version of atomic_inc_not_zero() gives a hint of probable
12334+ * value of the atomic. This helps processor to not read the memory
12335+ * before doing the atomic read/modify/write cycle, lowering
12336+ * number of bus transactions on some arches.
12337+ *
12338+ * Returns: 0 if increment was not done, 1 otherwise.
12339+ */
12340+#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
12341+static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
12342+{
12343+ int val, c = hint, new;
12344+
12345+ /* sanity test, should be removed by compiler if hint is a constant */
12346+ if (!hint)
12347+ return __atomic_add_unless(v, 1, 0);
12348+
12349+ do {
12350+ asm volatile("incl %0\n"
12351+
12352+#ifdef CONFIG_PAX_REFCOUNT
12353+ "jno 0f\n"
12354+ "decl %0\n"
12355+ "int $4\n0:\n"
12356+ _ASM_EXTABLE(0b, 0b)
12357+#endif
12358+
12359+ : "=r" (new)
12360+ : "0" (c));
12361+
12362+ val = atomic_cmpxchg(v, c, new);
12363+ if (val == c)
12364+ return 1;
12365+ c = val;
12366+ } while (c);
12367+
12368+ return 0;
12369+}
12370+
12371+/**
12372 * atomic_inc_short - increment of a short integer
12373 * @v: pointer to type int
12374 *
12375@@ -253,14 +497,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
12376 #endif
12377
12378 /* These are x86-specific, used by some header files */
12379-#define atomic_clear_mask(mask, addr) \
12380- asm volatile(LOCK_PREFIX "andl %0,%1" \
12381- : : "r" (~(mask)), "m" (*(addr)) : "memory")
12382+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
12383+{
12384+ asm volatile(LOCK_PREFIX "andl %1,%0"
12385+ : "+m" (v->counter)
12386+ : "r" (~(mask))
12387+ : "memory");
12388+}
12389
12390-#define atomic_set_mask(mask, addr) \
12391- asm volatile(LOCK_PREFIX "orl %0,%1" \
12392- : : "r" ((unsigned)(mask)), "m" (*(addr)) \
12393- : "memory")
12394+static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12395+{
12396+ asm volatile(LOCK_PREFIX "andl %1,%0"
12397+ : "+m" (v->counter)
12398+ : "r" (~(mask))
12399+ : "memory");
12400+}
12401+
12402+static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
12403+{
12404+ asm volatile(LOCK_PREFIX "orl %1,%0"
12405+ : "+m" (v->counter)
12406+ : "r" (mask)
12407+ : "memory");
12408+}
12409+
12410+static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
12411+{
12412+ asm volatile(LOCK_PREFIX "orl %1,%0"
12413+ : "+m" (v->counter)
12414+ : "r" (mask)
12415+ : "memory");
12416+}
12417
12418 /* Atomic operations are already serializing on x86 */
12419 #define smp_mb__before_atomic_dec() barrier()
12420diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
12421index b154de7..aadebd8 100644
12422--- a/arch/x86/include/asm/atomic64_32.h
12423+++ b/arch/x86/include/asm/atomic64_32.h
12424@@ -12,6 +12,14 @@ typedef struct {
12425 u64 __aligned(8) counter;
12426 } atomic64_t;
12427
12428+#ifdef CONFIG_PAX_REFCOUNT
12429+typedef struct {
12430+ u64 __aligned(8) counter;
12431+} atomic64_unchecked_t;
12432+#else
12433+typedef atomic64_t atomic64_unchecked_t;
12434+#endif
12435+
12436 #define ATOMIC64_INIT(val) { (val) }
12437
12438 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
12439@@ -37,21 +45,31 @@ typedef struct {
12440 ATOMIC64_DECL_ONE(sym##_386)
12441
12442 ATOMIC64_DECL_ONE(add_386);
12443+ATOMIC64_DECL_ONE(add_unchecked_386);
12444 ATOMIC64_DECL_ONE(sub_386);
12445+ATOMIC64_DECL_ONE(sub_unchecked_386);
12446 ATOMIC64_DECL_ONE(inc_386);
12447+ATOMIC64_DECL_ONE(inc_unchecked_386);
12448 ATOMIC64_DECL_ONE(dec_386);
12449+ATOMIC64_DECL_ONE(dec_unchecked_386);
12450 #endif
12451
12452 #define alternative_atomic64(f, out, in...) \
12453 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
12454
12455 ATOMIC64_DECL(read);
12456+ATOMIC64_DECL(read_unchecked);
12457 ATOMIC64_DECL(set);
12458+ATOMIC64_DECL(set_unchecked);
12459 ATOMIC64_DECL(xchg);
12460 ATOMIC64_DECL(add_return);
12461+ATOMIC64_DECL(add_return_unchecked);
12462 ATOMIC64_DECL(sub_return);
12463+ATOMIC64_DECL(sub_return_unchecked);
12464 ATOMIC64_DECL(inc_return);
12465+ATOMIC64_DECL(inc_return_unchecked);
12466 ATOMIC64_DECL(dec_return);
12467+ATOMIC64_DECL(dec_return_unchecked);
12468 ATOMIC64_DECL(dec_if_positive);
12469 ATOMIC64_DECL(inc_not_zero);
12470 ATOMIC64_DECL(add_unless);
12471@@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
12472 }
12473
12474 /**
12475+ * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
12476+ * @p: pointer to type atomic64_unchecked_t
12477+ * @o: expected value
12478+ * @n: new value
12479+ *
12480+ * Atomically sets @v to @n if it was equal to @o and returns
12481+ * the old value.
12482+ */
12483+
12484+static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
12485+{
12486+ return cmpxchg64(&v->counter, o, n);
12487+}
12488+
12489+/**
12490 * atomic64_xchg - xchg atomic64 variable
12491 * @v: pointer to type atomic64_t
12492 * @n: value to assign
12493@@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
12494 }
12495
12496 /**
12497+ * atomic64_set_unchecked - set atomic64 variable
12498+ * @v: pointer to type atomic64_unchecked_t
12499+ * @n: value to assign
12500+ *
12501+ * Atomically sets the value of @v to @n.
12502+ */
12503+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
12504+{
12505+ unsigned high = (unsigned)(i >> 32);
12506+ unsigned low = (unsigned)i;
12507+ alternative_atomic64(set, /* no output */,
12508+ "S" (v), "b" (low), "c" (high)
12509+ : "eax", "edx", "memory");
12510+}
12511+
12512+/**
12513 * atomic64_read - read atomic64 variable
12514 * @v: pointer to type atomic64_t
12515 *
12516@@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
12517 }
12518
12519 /**
12520+ * atomic64_read_unchecked - read atomic64 variable
12521+ * @v: pointer to type atomic64_unchecked_t
12522+ *
12523+ * Atomically reads the value of @v and returns it.
12524+ */
12525+static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
12526+{
12527+ long long r;
12528+ alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
12529+ return r;
12530+ }
12531+
12532+/**
12533 * atomic64_add_return - add and return
12534 * @i: integer value to add
12535 * @v: pointer to type atomic64_t
12536@@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
12537 return i;
12538 }
12539
12540+/**
12541+ * atomic64_add_return_unchecked - add and return
12542+ * @i: integer value to add
12543+ * @v: pointer to type atomic64_unchecked_t
12544+ *
12545+ * Atomically adds @i to @v and returns @i + *@v
12546+ */
12547+static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
12548+{
12549+ alternative_atomic64(add_return_unchecked,
12550+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12551+ ASM_NO_INPUT_CLOBBER("memory"));
12552+ return i;
12553+}
12554+
12555 /*
12556 * Other variants with different arithmetic operators:
12557 */
12558@@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
12559 return a;
12560 }
12561
12562+static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12563+{
12564+ long long a;
12565+ alternative_atomic64(inc_return_unchecked, "=&A" (a),
12566+ "S" (v) : "memory", "ecx");
12567+ return a;
12568+}
12569+
12570 static inline long long atomic64_dec_return(atomic64_t *v)
12571 {
12572 long long a;
12573@@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
12574 }
12575
12576 /**
12577+ * atomic64_add_unchecked - add integer to atomic64 variable
12578+ * @i: integer value to add
12579+ * @v: pointer to type atomic64_unchecked_t
12580+ *
12581+ * Atomically adds @i to @v.
12582+ */
12583+static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
12584+{
12585+ __alternative_atomic64(add_unchecked, add_return_unchecked,
12586+ ASM_OUTPUT2("+A" (i), "+c" (v)),
12587+ ASM_NO_INPUT_CLOBBER("memory"));
12588+ return i;
12589+}
12590+
12591+/**
12592 * atomic64_sub - subtract the atomic64 variable
12593 * @i: integer value to subtract
12594 * @v: pointer to type atomic64_t
12595diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
12596index 0e1cbfc..5623683 100644
12597--- a/arch/x86/include/asm/atomic64_64.h
12598+++ b/arch/x86/include/asm/atomic64_64.h
12599@@ -18,7 +18,19 @@
12600 */
12601 static inline long atomic64_read(const atomic64_t *v)
12602 {
12603- return (*(volatile long *)&(v)->counter);
12604+ return (*(volatile const long *)&(v)->counter);
12605+}
12606+
12607+/**
12608+ * atomic64_read_unchecked - read atomic64 variable
12609+ * @v: pointer of type atomic64_unchecked_t
12610+ *
12611+ * Atomically reads the value of @v.
12612+ * Doesn't imply a read memory barrier.
12613+ */
12614+static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
12615+{
12616+ return (*(volatile const long *)&(v)->counter);
12617 }
12618
12619 /**
12620@@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
12621 }
12622
12623 /**
12624+ * atomic64_set_unchecked - set atomic64 variable
12625+ * @v: pointer to type atomic64_unchecked_t
12626+ * @i: required value
12627+ *
12628+ * Atomically sets the value of @v to @i.
12629+ */
12630+static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
12631+{
12632+ v->counter = i;
12633+}
12634+
12635+/**
12636 * atomic64_add - add integer to atomic64 variable
12637 * @i: integer value to add
12638 * @v: pointer to type atomic64_t
12639@@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
12640 */
12641 static inline void atomic64_add(long i, atomic64_t *v)
12642 {
12643+ asm volatile(LOCK_PREFIX "addq %1,%0\n"
12644+
12645+#ifdef CONFIG_PAX_REFCOUNT
12646+ "jno 0f\n"
12647+ LOCK_PREFIX "subq %1,%0\n"
12648+ "int $4\n0:\n"
12649+ _ASM_EXTABLE(0b, 0b)
12650+#endif
12651+
12652+ : "=m" (v->counter)
12653+ : "er" (i), "m" (v->counter));
12654+}
12655+
12656+/**
12657+ * atomic64_add_unchecked - add integer to atomic64 variable
12658+ * @i: integer value to add
12659+ * @v: pointer to type atomic64_unchecked_t
12660+ *
12661+ * Atomically adds @i to @v.
12662+ */
12663+static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
12664+{
12665 asm volatile(LOCK_PREFIX "addq %1,%0"
12666 : "=m" (v->counter)
12667 : "er" (i), "m" (v->counter));
12668@@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
12669 */
12670 static inline void atomic64_sub(long i, atomic64_t *v)
12671 {
12672- asm volatile(LOCK_PREFIX "subq %1,%0"
12673+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12674+
12675+#ifdef CONFIG_PAX_REFCOUNT
12676+ "jno 0f\n"
12677+ LOCK_PREFIX "addq %1,%0\n"
12678+ "int $4\n0:\n"
12679+ _ASM_EXTABLE(0b, 0b)
12680+#endif
12681+
12682+ : "=m" (v->counter)
12683+ : "er" (i), "m" (v->counter));
12684+}
12685+
12686+/**
12687+ * atomic64_sub_unchecked - subtract the atomic64 variable
12688+ * @i: integer value to subtract
12689+ * @v: pointer to type atomic64_unchecked_t
12690+ *
12691+ * Atomically subtracts @i from @v.
12692+ */
12693+static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
12694+{
12695+ asm volatile(LOCK_PREFIX "subq %1,%0\n"
12696 : "=m" (v->counter)
12697 : "er" (i), "m" (v->counter));
12698 }
12699@@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12700 {
12701 unsigned char c;
12702
12703- asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
12704+ asm volatile(LOCK_PREFIX "subq %2,%0\n"
12705+
12706+#ifdef CONFIG_PAX_REFCOUNT
12707+ "jno 0f\n"
12708+ LOCK_PREFIX "addq %2,%0\n"
12709+ "int $4\n0:\n"
12710+ _ASM_EXTABLE(0b, 0b)
12711+#endif
12712+
12713+ "sete %1\n"
12714 : "=m" (v->counter), "=qm" (c)
12715 : "er" (i), "m" (v->counter) : "memory");
12716 return c;
12717@@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
12718 */
12719 static inline void atomic64_inc(atomic64_t *v)
12720 {
12721+ asm volatile(LOCK_PREFIX "incq %0\n"
12722+
12723+#ifdef CONFIG_PAX_REFCOUNT
12724+ "jno 0f\n"
12725+ LOCK_PREFIX "decq %0\n"
12726+ "int $4\n0:\n"
12727+ _ASM_EXTABLE(0b, 0b)
12728+#endif
12729+
12730+ : "=m" (v->counter)
12731+ : "m" (v->counter));
12732+}
12733+
12734+/**
12735+ * atomic64_inc_unchecked - increment atomic64 variable
12736+ * @v: pointer to type atomic64_unchecked_t
12737+ *
12738+ * Atomically increments @v by 1.
12739+ */
12740+static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
12741+{
12742 asm volatile(LOCK_PREFIX "incq %0"
12743 : "=m" (v->counter)
12744 : "m" (v->counter));
12745@@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
12746 */
12747 static inline void atomic64_dec(atomic64_t *v)
12748 {
12749- asm volatile(LOCK_PREFIX "decq %0"
12750+ asm volatile(LOCK_PREFIX "decq %0\n"
12751+
12752+#ifdef CONFIG_PAX_REFCOUNT
12753+ "jno 0f\n"
12754+ LOCK_PREFIX "incq %0\n"
12755+ "int $4\n0:\n"
12756+ _ASM_EXTABLE(0b, 0b)
12757+#endif
12758+
12759+ : "=m" (v->counter)
12760+ : "m" (v->counter));
12761+}
12762+
12763+/**
12764+ * atomic64_dec_unchecked - decrement atomic64 variable
12765+ * @v: pointer to type atomic64_t
12766+ *
12767+ * Atomically decrements @v by 1.
12768+ */
12769+static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
12770+{
12771+ asm volatile(LOCK_PREFIX "decq %0\n"
12772 : "=m" (v->counter)
12773 : "m" (v->counter));
12774 }
12775@@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
12776 {
12777 unsigned char c;
12778
12779- asm volatile(LOCK_PREFIX "decq %0; sete %1"
12780+ asm volatile(LOCK_PREFIX "decq %0\n"
12781+
12782+#ifdef CONFIG_PAX_REFCOUNT
12783+ "jno 0f\n"
12784+ LOCK_PREFIX "incq %0\n"
12785+ "int $4\n0:\n"
12786+ _ASM_EXTABLE(0b, 0b)
12787+#endif
12788+
12789+ "sete %1\n"
12790 : "=m" (v->counter), "=qm" (c)
12791 : "m" (v->counter) : "memory");
12792 return c != 0;
12793@@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
12794 {
12795 unsigned char c;
12796
12797- asm volatile(LOCK_PREFIX "incq %0; sete %1"
12798+ asm volatile(LOCK_PREFIX "incq %0\n"
12799+
12800+#ifdef CONFIG_PAX_REFCOUNT
12801+ "jno 0f\n"
12802+ LOCK_PREFIX "decq %0\n"
12803+ "int $4\n0:\n"
12804+ _ASM_EXTABLE(0b, 0b)
12805+#endif
12806+
12807+ "sete %1\n"
12808 : "=m" (v->counter), "=qm" (c)
12809 : "m" (v->counter) : "memory");
12810 return c != 0;
12811@@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12812 {
12813 unsigned char c;
12814
12815- asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
12816+ asm volatile(LOCK_PREFIX "addq %2,%0\n"
12817+
12818+#ifdef CONFIG_PAX_REFCOUNT
12819+ "jno 0f\n"
12820+ LOCK_PREFIX "subq %2,%0\n"
12821+ "int $4\n0:\n"
12822+ _ASM_EXTABLE(0b, 0b)
12823+#endif
12824+
12825+ "sets %1\n"
12826 : "=m" (v->counter), "=qm" (c)
12827 : "er" (i), "m" (v->counter) : "memory");
12828 return c;
12829@@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
12830 */
12831 static inline long atomic64_add_return(long i, atomic64_t *v)
12832 {
12833+ return i + xadd_check_overflow(&v->counter, i);
12834+}
12835+
12836+/**
12837+ * atomic64_add_return_unchecked - add and return
12838+ * @i: integer value to add
12839+ * @v: pointer to type atomic64_unchecked_t
12840+ *
12841+ * Atomically adds @i to @v and returns @i + @v
12842+ */
12843+static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
12844+{
12845 return i + xadd(&v->counter, i);
12846 }
12847
12848@@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
12849 }
12850
12851 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
12852+static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
12853+{
12854+ return atomic64_add_return_unchecked(1, v);
12855+}
12856 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
12857
12858 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12859@@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
12860 return cmpxchg(&v->counter, old, new);
12861 }
12862
12863+static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
12864+{
12865+ return cmpxchg(&v->counter, old, new);
12866+}
12867+
12868 static inline long atomic64_xchg(atomic64_t *v, long new)
12869 {
12870 return xchg(&v->counter, new);
12871@@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
12872 */
12873 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
12874 {
12875- long c, old;
12876+ long c, old, new;
12877 c = atomic64_read(v);
12878 for (;;) {
12879- if (unlikely(c == (u)))
12880+ if (unlikely(c == u))
12881 break;
12882- old = atomic64_cmpxchg((v), c, c + (a));
12883+
12884+ asm volatile("add %2,%0\n"
12885+
12886+#ifdef CONFIG_PAX_REFCOUNT
12887+ "jno 0f\n"
12888+ "sub %2,%0\n"
12889+ "int $4\n0:\n"
12890+ _ASM_EXTABLE(0b, 0b)
12891+#endif
12892+
12893+ : "=r" (new)
12894+ : "0" (c), "ir" (a));
12895+
12896+ old = atomic64_cmpxchg(v, c, new);
12897 if (likely(old == c))
12898 break;
12899 c = old;
12900 }
12901- return c != (u);
12902+ return c != u;
12903 }
12904
12905 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12906diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
12907index 6dfd019..28e188d 100644
12908--- a/arch/x86/include/asm/bitops.h
12909+++ b/arch/x86/include/asm/bitops.h
12910@@ -40,7 +40,7 @@
12911 * a mask operation on a byte.
12912 */
12913 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
12914-#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
12915+#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
12916 #define CONST_MASK(nr) (1 << ((nr) & 7))
12917
12918 /**
12919@@ -486,7 +486,7 @@ static inline int fls(int x)
12920 * at position 64.
12921 */
12922 #ifdef CONFIG_X86_64
12923-static __always_inline int fls64(__u64 x)
12924+static __always_inline long fls64(__u64 x)
12925 {
12926 int bitpos = -1;
12927 /*
12928diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
12929index 4fa687a..60f2d39 100644
12930--- a/arch/x86/include/asm/boot.h
12931+++ b/arch/x86/include/asm/boot.h
12932@@ -6,10 +6,15 @@
12933 #include <uapi/asm/boot.h>
12934
12935 /* Physical address where kernel should be loaded. */
12936-#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12937+#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
12938 + (CONFIG_PHYSICAL_ALIGN - 1)) \
12939 & ~(CONFIG_PHYSICAL_ALIGN - 1))
12940
12941+#ifndef __ASSEMBLY__
12942+extern unsigned char __LOAD_PHYSICAL_ADDR[];
12943+#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
12944+#endif
12945+
12946 /* Minimum kernel alignment, as a power of two */
12947 #ifdef CONFIG_X86_64
12948 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
12949diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
12950index 48f99f1..d78ebf9 100644
12951--- a/arch/x86/include/asm/cache.h
12952+++ b/arch/x86/include/asm/cache.h
12953@@ -5,12 +5,13 @@
12954
12955 /* L1 cache line size */
12956 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12957-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12958+#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12959
12960 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
12961+#define __read_only __attribute__((__section__(".data..read_only")))
12962
12963 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
12964-#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
12965+#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
12966
12967 #ifdef CONFIG_X86_VSMP
12968 #ifdef CONFIG_SMP
12969diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
12970index 9863ee3..4a1f8e1 100644
12971--- a/arch/x86/include/asm/cacheflush.h
12972+++ b/arch/x86/include/asm/cacheflush.h
12973@@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
12974 unsigned long pg_flags = pg->flags & _PGMT_MASK;
12975
12976 if (pg_flags == _PGMT_DEFAULT)
12977- return -1;
12978+ return ~0UL;
12979 else if (pg_flags == _PGMT_WC)
12980 return _PAGE_CACHE_WC;
12981 else if (pg_flags == _PGMT_UC_MINUS)
12982diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
12983index 46fc474..b02b0f9 100644
12984--- a/arch/x86/include/asm/checksum_32.h
12985+++ b/arch/x86/include/asm/checksum_32.h
12986@@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
12987 int len, __wsum sum,
12988 int *src_err_ptr, int *dst_err_ptr);
12989
12990+asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
12991+ int len, __wsum sum,
12992+ int *src_err_ptr, int *dst_err_ptr);
12993+
12994+asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
12995+ int len, __wsum sum,
12996+ int *src_err_ptr, int *dst_err_ptr);
12997+
12998 /*
12999 * Note: when you get a NULL pointer exception here this means someone
13000 * passed in an incorrect kernel address to one of these functions.
13001@@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
13002 int *err_ptr)
13003 {
13004 might_sleep();
13005- return csum_partial_copy_generic((__force void *)src, dst,
13006+ return csum_partial_copy_generic_from_user((__force void *)src, dst,
13007 len, sum, err_ptr, NULL);
13008 }
13009
13010@@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
13011 {
13012 might_sleep();
13013 if (access_ok(VERIFY_WRITE, dst, len))
13014- return csum_partial_copy_generic(src, (__force void *)dst,
13015+ return csum_partial_copy_generic_to_user(src, (__force void *)dst,
13016 len, sum, NULL, err_ptr);
13017
13018 if (len)
13019diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
13020index 8d871ea..c1a0dc9 100644
13021--- a/arch/x86/include/asm/cmpxchg.h
13022+++ b/arch/x86/include/asm/cmpxchg.h
13023@@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
13024 __compiletime_error("Bad argument size for cmpxchg");
13025 extern void __xadd_wrong_size(void)
13026 __compiletime_error("Bad argument size for xadd");
13027+extern void __xadd_check_overflow_wrong_size(void)
13028+ __compiletime_error("Bad argument size for xadd_check_overflow");
13029 extern void __add_wrong_size(void)
13030 __compiletime_error("Bad argument size for add");
13031+extern void __add_check_overflow_wrong_size(void)
13032+ __compiletime_error("Bad argument size for add_check_overflow");
13033
13034 /*
13035 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
13036@@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
13037 __ret; \
13038 })
13039
13040+#define __xchg_op_check_overflow(ptr, arg, op, lock) \
13041+ ({ \
13042+ __typeof__ (*(ptr)) __ret = (arg); \
13043+ switch (sizeof(*(ptr))) { \
13044+ case __X86_CASE_L: \
13045+ asm volatile (lock #op "l %0, %1\n" \
13046+ "jno 0f\n" \
13047+ "mov %0,%1\n" \
13048+ "int $4\n0:\n" \
13049+ _ASM_EXTABLE(0b, 0b) \
13050+ : "+r" (__ret), "+m" (*(ptr)) \
13051+ : : "memory", "cc"); \
13052+ break; \
13053+ case __X86_CASE_Q: \
13054+ asm volatile (lock #op "q %q0, %1\n" \
13055+ "jno 0f\n" \
13056+ "mov %0,%1\n" \
13057+ "int $4\n0:\n" \
13058+ _ASM_EXTABLE(0b, 0b) \
13059+ : "+r" (__ret), "+m" (*(ptr)) \
13060+ : : "memory", "cc"); \
13061+ break; \
13062+ default: \
13063+ __ ## op ## _check_overflow_wrong_size(); \
13064+ } \
13065+ __ret; \
13066+ })
13067+
13068 /*
13069 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
13070 * Since this is generally used to protect other memory information, we
13071@@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
13072 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
13073 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
13074
13075+#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
13076+#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
13077+
13078 #define __add(ptr, inc, lock) \
13079 ({ \
13080 __typeof__ (*(ptr)) __ret = (inc); \
13081diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
13082index 59c6c40..5e0b22c 100644
13083--- a/arch/x86/include/asm/compat.h
13084+++ b/arch/x86/include/asm/compat.h
13085@@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
13086 typedef u32 compat_uint_t;
13087 typedef u32 compat_ulong_t;
13088 typedef u64 __attribute__((aligned(4))) compat_u64;
13089-typedef u32 compat_uptr_t;
13090+typedef u32 __user compat_uptr_t;
13091
13092 struct compat_timespec {
13093 compat_time_t tv_sec;
13094diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
13095index 93fe929..90858b7 100644
13096--- a/arch/x86/include/asm/cpufeature.h
13097+++ b/arch/x86/include/asm/cpufeature.h
13098@@ -207,7 +207,7 @@
13099 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
13100 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
13101 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
13102-#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
13103+#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
13104 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
13105 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
13106 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
13107@@ -377,7 +377,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
13108 ".section .discard,\"aw\",@progbits\n"
13109 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
13110 ".previous\n"
13111- ".section .altinstr_replacement,\"ax\"\n"
13112+ ".section .altinstr_replacement,\"a\"\n"
13113 "3: movb $1,%0\n"
13114 "4:\n"
13115 ".previous\n"
13116diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
13117index 8bf1c06..b6ae785 100644
13118--- a/arch/x86/include/asm/desc.h
13119+++ b/arch/x86/include/asm/desc.h
13120@@ -4,6 +4,7 @@
13121 #include <asm/desc_defs.h>
13122 #include <asm/ldt.h>
13123 #include <asm/mmu.h>
13124+#include <asm/pgtable.h>
13125
13126 #include <linux/smp.h>
13127 #include <linux/percpu.h>
13128@@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13129
13130 desc->type = (info->read_exec_only ^ 1) << 1;
13131 desc->type |= info->contents << 2;
13132+ desc->type |= info->seg_not_present ^ 1;
13133
13134 desc->s = 1;
13135 desc->dpl = 0x3;
13136@@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
13137 }
13138
13139 extern struct desc_ptr idt_descr;
13140-extern gate_desc idt_table[];
13141 extern struct desc_ptr nmi_idt_descr;
13142-extern gate_desc nmi_idt_table[];
13143-
13144-struct gdt_page {
13145- struct desc_struct gdt[GDT_ENTRIES];
13146-} __attribute__((aligned(PAGE_SIZE)));
13147-
13148-DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
13149+extern gate_desc idt_table[256];
13150+extern gate_desc nmi_idt_table[256];
13151
13152+extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
13153 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
13154 {
13155- return per_cpu(gdt_page, cpu).gdt;
13156+ return cpu_gdt_table[cpu];
13157 }
13158
13159 #ifdef CONFIG_X86_64
13160@@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
13161 unsigned long base, unsigned dpl, unsigned flags,
13162 unsigned short seg)
13163 {
13164- gate->a = (seg << 16) | (base & 0xffff);
13165- gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
13166+ gate->gate.offset_low = base;
13167+ gate->gate.seg = seg;
13168+ gate->gate.reserved = 0;
13169+ gate->gate.type = type;
13170+ gate->gate.s = 0;
13171+ gate->gate.dpl = dpl;
13172+ gate->gate.p = 1;
13173+ gate->gate.offset_high = base >> 16;
13174 }
13175
13176 #endif
13177@@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
13178
13179 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
13180 {
13181+ pax_open_kernel();
13182 memcpy(&idt[entry], gate, sizeof(*gate));
13183+ pax_close_kernel();
13184 }
13185
13186 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
13187 {
13188+ pax_open_kernel();
13189 memcpy(&ldt[entry], desc, 8);
13190+ pax_close_kernel();
13191 }
13192
13193 static inline void
13194@@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
13195 default: size = sizeof(*gdt); break;
13196 }
13197
13198+ pax_open_kernel();
13199 memcpy(&gdt[entry], desc, size);
13200+ pax_close_kernel();
13201 }
13202
13203 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
13204@@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
13205
13206 static inline void native_load_tr_desc(void)
13207 {
13208+ pax_open_kernel();
13209 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
13210+ pax_close_kernel();
13211 }
13212
13213 static inline void native_load_gdt(const struct desc_ptr *dtr)
13214@@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
13215 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
13216 unsigned int i;
13217
13218+ pax_open_kernel();
13219 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
13220 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
13221+ pax_close_kernel();
13222 }
13223
13224 #define _LDT_empty(info) \
13225@@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
13226 preempt_enable();
13227 }
13228
13229-static inline unsigned long get_desc_base(const struct desc_struct *desc)
13230+static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
13231 {
13232 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
13233 }
13234@@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
13235 }
13236
13237 #ifdef CONFIG_X86_64
13238-static inline void set_nmi_gate(int gate, void *addr)
13239+static inline void set_nmi_gate(int gate, const void *addr)
13240 {
13241 gate_desc s;
13242
13243@@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
13244 }
13245 #endif
13246
13247-static inline void _set_gate(int gate, unsigned type, void *addr,
13248+static inline void _set_gate(int gate, unsigned type, const void *addr,
13249 unsigned dpl, unsigned ist, unsigned seg)
13250 {
13251 gate_desc s;
13252@@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
13253 * Pentium F0 0F bugfix can have resulted in the mapped
13254 * IDT being write-protected.
13255 */
13256-static inline void set_intr_gate(unsigned int n, void *addr)
13257+static inline void set_intr_gate(unsigned int n, const void *addr)
13258 {
13259 BUG_ON((unsigned)n > 0xFF);
13260 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
13261@@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
13262 /*
13263 * This routine sets up an interrupt gate at directory privilege level 3.
13264 */
13265-static inline void set_system_intr_gate(unsigned int n, void *addr)
13266+static inline void set_system_intr_gate(unsigned int n, const void *addr)
13267 {
13268 BUG_ON((unsigned)n > 0xFF);
13269 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
13270 }
13271
13272-static inline void set_system_trap_gate(unsigned int n, void *addr)
13273+static inline void set_system_trap_gate(unsigned int n, const void *addr)
13274 {
13275 BUG_ON((unsigned)n > 0xFF);
13276 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
13277 }
13278
13279-static inline void set_trap_gate(unsigned int n, void *addr)
13280+static inline void set_trap_gate(unsigned int n, const void *addr)
13281 {
13282 BUG_ON((unsigned)n > 0xFF);
13283 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
13284@@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
13285 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
13286 {
13287 BUG_ON((unsigned)n > 0xFF);
13288- _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
13289+ _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
13290 }
13291
13292-static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
13293+static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
13294 {
13295 BUG_ON((unsigned)n > 0xFF);
13296 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
13297 }
13298
13299-static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
13300+static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
13301 {
13302 BUG_ON((unsigned)n > 0xFF);
13303 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
13304 }
13305
13306+#ifdef CONFIG_X86_32
13307+static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
13308+{
13309+ struct desc_struct d;
13310+
13311+ if (likely(limit))
13312+ limit = (limit - 1UL) >> PAGE_SHIFT;
13313+ pack_descriptor(&d, base, limit, 0xFB, 0xC);
13314+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
13315+}
13316+#endif
13317+
13318 #endif /* _ASM_X86_DESC_H */
13319diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
13320index 278441f..b95a174 100644
13321--- a/arch/x86/include/asm/desc_defs.h
13322+++ b/arch/x86/include/asm/desc_defs.h
13323@@ -31,6 +31,12 @@ struct desc_struct {
13324 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
13325 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
13326 };
13327+ struct {
13328+ u16 offset_low;
13329+ u16 seg;
13330+ unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
13331+ unsigned offset_high: 16;
13332+ } gate;
13333 };
13334 } __attribute__((packed));
13335
13336diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
13337index ced283a..ffe04cc 100644
13338--- a/arch/x86/include/asm/div64.h
13339+++ b/arch/x86/include/asm/div64.h
13340@@ -39,7 +39,7 @@
13341 __mod; \
13342 })
13343
13344-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13345+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
13346 {
13347 union {
13348 u64 v64;
13349diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
13350index 9c999c1..3860cb8 100644
13351--- a/arch/x86/include/asm/elf.h
13352+++ b/arch/x86/include/asm/elf.h
13353@@ -243,7 +243,25 @@ extern int force_personality32;
13354 the loader. We need to make sure that it is out of the way of the program
13355 that it will "exec", and that there is sufficient room for the brk. */
13356
13357+#ifdef CONFIG_PAX_SEGMEXEC
13358+#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
13359+#else
13360 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
13361+#endif
13362+
13363+#ifdef CONFIG_PAX_ASLR
13364+#ifdef CONFIG_X86_32
13365+#define PAX_ELF_ET_DYN_BASE 0x10000000UL
13366+
13367+#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13368+#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
13369+#else
13370+#define PAX_ELF_ET_DYN_BASE 0x400000UL
13371+
13372+#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13373+#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
13374+#endif
13375+#endif
13376
13377 /* This yields a mask that user programs can use to figure out what
13378 instruction set this CPU supports. This could be done in user space,
13379@@ -296,16 +314,12 @@ do { \
13380
13381 #define ARCH_DLINFO \
13382 do { \
13383- if (vdso_enabled) \
13384- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13385- (unsigned long)current->mm->context.vdso); \
13386+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13387 } while (0)
13388
13389 #define ARCH_DLINFO_X32 \
13390 do { \
13391- if (vdso_enabled) \
13392- NEW_AUX_ENT(AT_SYSINFO_EHDR, \
13393- (unsigned long)current->mm->context.vdso); \
13394+ NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
13395 } while (0)
13396
13397 #define AT_SYSINFO 32
13398@@ -320,7 +334,7 @@ else \
13399
13400 #endif /* !CONFIG_X86_32 */
13401
13402-#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
13403+#define VDSO_CURRENT_BASE (current->mm->context.vdso)
13404
13405 #define VDSO_ENTRY \
13406 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
13407@@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
13408 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
13409 #define compat_arch_setup_additional_pages syscall32_setup_pages
13410
13411-extern unsigned long arch_randomize_brk(struct mm_struct *mm);
13412-#define arch_randomize_brk arch_randomize_brk
13413-
13414 /*
13415 * True on X86_32 or when emulating IA32 on X86_64
13416 */
13417diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
13418index 75ce3f4..882e801 100644
13419--- a/arch/x86/include/asm/emergency-restart.h
13420+++ b/arch/x86/include/asm/emergency-restart.h
13421@@ -13,6 +13,6 @@ enum reboot_type {
13422
13423 extern enum reboot_type reboot_type;
13424
13425-extern void machine_emergency_restart(void);
13426+extern void machine_emergency_restart(void) __noreturn;
13427
13428 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
13429diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
13430index e25cc33..425d099 100644
13431--- a/arch/x86/include/asm/fpu-internal.h
13432+++ b/arch/x86/include/asm/fpu-internal.h
13433@@ -127,7 +127,9 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
13434 ({ \
13435 int err; \
13436 asm volatile(ASM_STAC "\n" \
13437- "1:" #insn "\n\t" \
13438+ "1:" \
13439+ __copyuser_seg \
13440+ #insn "\n\t" \
13441 "2: " ASM_CLAC "\n" \
13442 ".section .fixup,\"ax\"\n" \
13443 "3: movl $-1,%[err]\n" \
13444@@ -300,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
13445 "emms\n\t" /* clear stack tags */
13446 "fildl %P[addr]", /* set F?P to defined value */
13447 X86_FEATURE_FXSAVE_LEAK,
13448- [addr] "m" (tsk->thread.fpu.has_fpu));
13449+ [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
13450
13451 return fpu_restore_checking(&tsk->thread.fpu);
13452 }
13453diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
13454index be27ba1..8f13ff9 100644
13455--- a/arch/x86/include/asm/futex.h
13456+++ b/arch/x86/include/asm/futex.h
13457@@ -12,6 +12,7 @@
13458 #include <asm/smap.h>
13459
13460 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
13461+ typecheck(u32 __user *, uaddr); \
13462 asm volatile("\t" ASM_STAC "\n" \
13463 "1:\t" insn "\n" \
13464 "2:\t" ASM_CLAC "\n" \
13465@@ -20,15 +21,16 @@
13466 "\tjmp\t2b\n" \
13467 "\t.previous\n" \
13468 _ASM_EXTABLE(1b, 3b) \
13469- : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
13470+ : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
13471 : "i" (-EFAULT), "0" (oparg), "1" (0))
13472
13473 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
13474+ typecheck(u32 __user *, uaddr); \
13475 asm volatile("\t" ASM_STAC "\n" \
13476 "1:\tmovl %2, %0\n" \
13477 "\tmovl\t%0, %3\n" \
13478 "\t" insn "\n" \
13479- "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
13480+ "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
13481 "\tjnz\t1b\n" \
13482 "3:\t" ASM_CLAC "\n" \
13483 "\t.section .fixup,\"ax\"\n" \
13484@@ -38,7 +40,7 @@
13485 _ASM_EXTABLE(1b, 4b) \
13486 _ASM_EXTABLE(2b, 4b) \
13487 : "=&a" (oldval), "=&r" (ret), \
13488- "+m" (*uaddr), "=&r" (tem) \
13489+ "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
13490 : "r" (oparg), "i" (-EFAULT), "1" (0))
13491
13492 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13493@@ -59,10 +61,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
13494
13495 switch (op) {
13496 case FUTEX_OP_SET:
13497- __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
13498+ __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
13499 break;
13500 case FUTEX_OP_ADD:
13501- __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
13502+ __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
13503 uaddr, oparg);
13504 break;
13505 case FUTEX_OP_OR:
13506@@ -116,14 +118,14 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
13507 return -EFAULT;
13508
13509 asm volatile("\t" ASM_STAC "\n"
13510- "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
13511+ "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
13512 "2:\t" ASM_CLAC "\n"
13513 "\t.section .fixup, \"ax\"\n"
13514 "3:\tmov %3, %0\n"
13515 "\tjmp 2b\n"
13516 "\t.previous\n"
13517 _ASM_EXTABLE(1b, 3b)
13518- : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
13519+ : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
13520 : "i" (-EFAULT), "r" (newval), "1" (oldval)
13521 : "memory"
13522 );
13523diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
13524index 10a78c3..cc77143 100644
13525--- a/arch/x86/include/asm/hw_irq.h
13526+++ b/arch/x86/include/asm/hw_irq.h
13527@@ -147,8 +147,8 @@ extern void setup_ioapic_dest(void);
13528 extern void enable_IO_APIC(void);
13529
13530 /* Statistics */
13531-extern atomic_t irq_err_count;
13532-extern atomic_t irq_mis_count;
13533+extern atomic_unchecked_t irq_err_count;
13534+extern atomic_unchecked_t irq_mis_count;
13535
13536 /* EISA */
13537 extern void eisa_set_level_irq(unsigned int irq);
13538diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
13539index a203659..9889f1c 100644
13540--- a/arch/x86/include/asm/i8259.h
13541+++ b/arch/x86/include/asm/i8259.h
13542@@ -62,7 +62,7 @@ struct legacy_pic {
13543 void (*init)(int auto_eoi);
13544 int (*irq_pending)(unsigned int irq);
13545 void (*make_irq)(unsigned int irq);
13546-};
13547+} __do_const;
13548
13549 extern struct legacy_pic *legacy_pic;
13550 extern struct legacy_pic null_legacy_pic;
13551diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
13552index d8e8eef..1765f78 100644
13553--- a/arch/x86/include/asm/io.h
13554+++ b/arch/x86/include/asm/io.h
13555@@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
13556 "m" (*(volatile type __force *)addr) barrier); }
13557
13558 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
13559-build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
13560-build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
13561+build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
13562+build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
13563
13564 build_mmio_read(__readb, "b", unsigned char, "=q", )
13565-build_mmio_read(__readw, "w", unsigned short, "=r", )
13566-build_mmio_read(__readl, "l", unsigned int, "=r", )
13567+build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
13568+build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
13569
13570 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
13571 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
13572@@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
13573 return ioremap_nocache(offset, size);
13574 }
13575
13576-extern void iounmap(volatile void __iomem *addr);
13577+extern void iounmap(const volatile void __iomem *addr);
13578
13579 extern void set_iounmap_nonlazy(void);
13580
13581@@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
13582
13583 #include <linux/vmalloc.h>
13584
13585+#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
13586+static inline int valid_phys_addr_range(unsigned long addr, size_t count)
13587+{
13588+ return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13589+}
13590+
13591+static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
13592+{
13593+ return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
13594+}
13595+
13596 /*
13597 * Convert a virtual cached pointer to an uncached pointer
13598 */
13599diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
13600index bba3cf8..06bc8da 100644
13601--- a/arch/x86/include/asm/irqflags.h
13602+++ b/arch/x86/include/asm/irqflags.h
13603@@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
13604 sti; \
13605 sysexit
13606
13607+#define GET_CR0_INTO_RDI mov %cr0, %rdi
13608+#define SET_RDI_INTO_CR0 mov %rdi, %cr0
13609+#define GET_CR3_INTO_RDI mov %cr3, %rdi
13610+#define SET_RDI_INTO_CR3 mov %rdi, %cr3
13611+
13612 #else
13613 #define INTERRUPT_RETURN iret
13614 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
13615diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
13616index 5a6d287..f815789 100644
13617--- a/arch/x86/include/asm/kprobes.h
13618+++ b/arch/x86/include/asm/kprobes.h
13619@@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
13620 #define RELATIVEJUMP_SIZE 5
13621 #define RELATIVECALL_OPCODE 0xe8
13622 #define RELATIVE_ADDR_SIZE 4
13623-#define MAX_STACK_SIZE 64
13624-#define MIN_STACK_SIZE(ADDR) \
13625- (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
13626- THREAD_SIZE - (unsigned long)(ADDR))) \
13627- ? (MAX_STACK_SIZE) \
13628- : (((unsigned long)current_thread_info()) + \
13629- THREAD_SIZE - (unsigned long)(ADDR)))
13630+#define MAX_STACK_SIZE 64UL
13631+#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
13632
13633 #define flush_insn_slot(p) do { } while (0)
13634
13635diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
13636index 2d89e39..baee879 100644
13637--- a/arch/x86/include/asm/local.h
13638+++ b/arch/x86/include/asm/local.h
13639@@ -10,33 +10,97 @@ typedef struct {
13640 atomic_long_t a;
13641 } local_t;
13642
13643+typedef struct {
13644+ atomic_long_unchecked_t a;
13645+} local_unchecked_t;
13646+
13647 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
13648
13649 #define local_read(l) atomic_long_read(&(l)->a)
13650+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
13651 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
13652+#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
13653
13654 static inline void local_inc(local_t *l)
13655 {
13656- asm volatile(_ASM_INC "%0"
13657+ asm volatile(_ASM_INC "%0\n"
13658+
13659+#ifdef CONFIG_PAX_REFCOUNT
13660+ "jno 0f\n"
13661+ _ASM_DEC "%0\n"
13662+ "int $4\n0:\n"
13663+ _ASM_EXTABLE(0b, 0b)
13664+#endif
13665+
13666+ : "+m" (l->a.counter));
13667+}
13668+
13669+static inline void local_inc_unchecked(local_unchecked_t *l)
13670+{
13671+ asm volatile(_ASM_INC "%0\n"
13672 : "+m" (l->a.counter));
13673 }
13674
13675 static inline void local_dec(local_t *l)
13676 {
13677- asm volatile(_ASM_DEC "%0"
13678+ asm volatile(_ASM_DEC "%0\n"
13679+
13680+#ifdef CONFIG_PAX_REFCOUNT
13681+ "jno 0f\n"
13682+ _ASM_INC "%0\n"
13683+ "int $4\n0:\n"
13684+ _ASM_EXTABLE(0b, 0b)
13685+#endif
13686+
13687+ : "+m" (l->a.counter));
13688+}
13689+
13690+static inline void local_dec_unchecked(local_unchecked_t *l)
13691+{
13692+ asm volatile(_ASM_DEC "%0\n"
13693 : "+m" (l->a.counter));
13694 }
13695
13696 static inline void local_add(long i, local_t *l)
13697 {
13698- asm volatile(_ASM_ADD "%1,%0"
13699+ asm volatile(_ASM_ADD "%1,%0\n"
13700+
13701+#ifdef CONFIG_PAX_REFCOUNT
13702+ "jno 0f\n"
13703+ _ASM_SUB "%1,%0\n"
13704+ "int $4\n0:\n"
13705+ _ASM_EXTABLE(0b, 0b)
13706+#endif
13707+
13708+ : "+m" (l->a.counter)
13709+ : "ir" (i));
13710+}
13711+
13712+static inline void local_add_unchecked(long i, local_unchecked_t *l)
13713+{
13714+ asm volatile(_ASM_ADD "%1,%0\n"
13715 : "+m" (l->a.counter)
13716 : "ir" (i));
13717 }
13718
13719 static inline void local_sub(long i, local_t *l)
13720 {
13721- asm volatile(_ASM_SUB "%1,%0"
13722+ asm volatile(_ASM_SUB "%1,%0\n"
13723+
13724+#ifdef CONFIG_PAX_REFCOUNT
13725+ "jno 0f\n"
13726+ _ASM_ADD "%1,%0\n"
13727+ "int $4\n0:\n"
13728+ _ASM_EXTABLE(0b, 0b)
13729+#endif
13730+
13731+ : "+m" (l->a.counter)
13732+ : "ir" (i));
13733+}
13734+
13735+static inline void local_sub_unchecked(long i, local_unchecked_t *l)
13736+{
13737+ asm volatile(_ASM_SUB "%1,%0\n"
13738 : "+m" (l->a.counter)
13739 : "ir" (i));
13740 }
13741@@ -54,7 +118,16 @@ static inline int local_sub_and_test(long i, local_t *l)
13742 {
13743 unsigned char c;
13744
13745- asm volatile(_ASM_SUB "%2,%0; sete %1"
13746+ asm volatile(_ASM_SUB "%2,%0\n"
13747+
13748+#ifdef CONFIG_PAX_REFCOUNT
13749+ "jno 0f\n"
13750+ _ASM_ADD "%2,%0\n"
13751+ "int $4\n0:\n"
13752+ _ASM_EXTABLE(0b, 0b)
13753+#endif
13754+
13755+ "sete %1\n"
13756 : "+m" (l->a.counter), "=qm" (c)
13757 : "ir" (i) : "memory");
13758 return c;
13759@@ -72,7 +145,16 @@ static inline int local_dec_and_test(local_t *l)
13760 {
13761 unsigned char c;
13762
13763- asm volatile(_ASM_DEC "%0; sete %1"
13764+ asm volatile(_ASM_DEC "%0\n"
13765+
13766+#ifdef CONFIG_PAX_REFCOUNT
13767+ "jno 0f\n"
13768+ _ASM_INC "%0\n"
13769+ "int $4\n0:\n"
13770+ _ASM_EXTABLE(0b, 0b)
13771+#endif
13772+
13773+ "sete %1\n"
13774 : "+m" (l->a.counter), "=qm" (c)
13775 : : "memory");
13776 return c != 0;
13777@@ -90,7 +172,16 @@ static inline int local_inc_and_test(local_t *l)
13778 {
13779 unsigned char c;
13780
13781- asm volatile(_ASM_INC "%0; sete %1"
13782+ asm volatile(_ASM_INC "%0\n"
13783+
13784+#ifdef CONFIG_PAX_REFCOUNT
13785+ "jno 0f\n"
13786+ _ASM_DEC "%0\n"
13787+ "int $4\n0:\n"
13788+ _ASM_EXTABLE(0b, 0b)
13789+#endif
13790+
13791+ "sete %1\n"
13792 : "+m" (l->a.counter), "=qm" (c)
13793 : : "memory");
13794 return c != 0;
13795@@ -109,7 +200,16 @@ static inline int local_add_negative(long i, local_t *l)
13796 {
13797 unsigned char c;
13798
13799- asm volatile(_ASM_ADD "%2,%0; sets %1"
13800+ asm volatile(_ASM_ADD "%2,%0\n"
13801+
13802+#ifdef CONFIG_PAX_REFCOUNT
13803+ "jno 0f\n"
13804+ _ASM_SUB "%2,%0\n"
13805+ "int $4\n0:\n"
13806+ _ASM_EXTABLE(0b, 0b)
13807+#endif
13808+
13809+ "sets %1\n"
13810 : "+m" (l->a.counter), "=qm" (c)
13811 : "ir" (i) : "memory");
13812 return c;
13813@@ -125,6 +225,30 @@ static inline int local_add_negative(long i, local_t *l)
13814 static inline long local_add_return(long i, local_t *l)
13815 {
13816 long __i = i;
13817+ asm volatile(_ASM_XADD "%0, %1\n"
13818+
13819+#ifdef CONFIG_PAX_REFCOUNT
13820+ "jno 0f\n"
13821+ _ASM_MOV "%0,%1\n"
13822+ "int $4\n0:\n"
13823+ _ASM_EXTABLE(0b, 0b)
13824+#endif
13825+
13826+ : "+r" (i), "+m" (l->a.counter)
13827+ : : "memory");
13828+ return i + __i;
13829+}
13830+
13831+/**
13832+ * local_add_return_unchecked - add and return
13833+ * @i: integer value to add
13834+ * @l: pointer to type local_unchecked_t
13835+ *
13836+ * Atomically adds @i to @l and returns @i + @l
13837+ */
13838+static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
13839+{
13840+ long __i = i;
13841 asm volatile(_ASM_XADD "%0, %1;"
13842 : "+r" (i), "+m" (l->a.counter)
13843 : : "memory");
13844@@ -141,6 +265,8 @@ static inline long local_sub_return(long i, local_t *l)
13845
13846 #define local_cmpxchg(l, o, n) \
13847 (cmpxchg_local(&((l)->a.counter), (o), (n)))
13848+#define local_cmpxchg_unchecked(l, o, n) \
13849+ (cmpxchg_local(&((l)->a.counter), (o), (n)))
13850 /* Always has a lock prefix */
13851 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
13852
13853diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
13854new file mode 100644
13855index 0000000..2bfd3ba
13856--- /dev/null
13857+++ b/arch/x86/include/asm/mman.h
13858@@ -0,0 +1,15 @@
13859+#ifndef _X86_MMAN_H
13860+#define _X86_MMAN_H
13861+
13862+#include <uapi/asm/mman.h>
13863+
13864+#ifdef __KERNEL__
13865+#ifndef __ASSEMBLY__
13866+#ifdef CONFIG_X86_32
13867+#define arch_mmap_check i386_mmap_check
13868+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
13869+#endif
13870+#endif
13871+#endif
13872+
13873+#endif /* X86_MMAN_H */
13874diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
13875index 5f55e69..e20bfb1 100644
13876--- a/arch/x86/include/asm/mmu.h
13877+++ b/arch/x86/include/asm/mmu.h
13878@@ -9,7 +9,7 @@
13879 * we put the segment information here.
13880 */
13881 typedef struct {
13882- void *ldt;
13883+ struct desc_struct *ldt;
13884 int size;
13885
13886 #ifdef CONFIG_X86_64
13887@@ -18,7 +18,19 @@ typedef struct {
13888 #endif
13889
13890 struct mutex lock;
13891- void *vdso;
13892+ unsigned long vdso;
13893+
13894+#ifdef CONFIG_X86_32
13895+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
13896+ unsigned long user_cs_base;
13897+ unsigned long user_cs_limit;
13898+
13899+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13900+ cpumask_t cpu_user_cs_mask;
13901+#endif
13902+
13903+#endif
13904+#endif
13905 } mm_context_t;
13906
13907 #ifdef CONFIG_SMP
13908diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
13909index cdbf367..adb37ac 100644
13910--- a/arch/x86/include/asm/mmu_context.h
13911+++ b/arch/x86/include/asm/mmu_context.h
13912@@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
13913
13914 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
13915 {
13916+
13917+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13918+ unsigned int i;
13919+ pgd_t *pgd;
13920+
13921+ pax_open_kernel();
13922+ pgd = get_cpu_pgd(smp_processor_id());
13923+ for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
13924+ set_pgd_batched(pgd+i, native_make_pgd(0));
13925+ pax_close_kernel();
13926+#endif
13927+
13928 #ifdef CONFIG_SMP
13929 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
13930 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
13931@@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13932 struct task_struct *tsk)
13933 {
13934 unsigned cpu = smp_processor_id();
13935+#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13936+ int tlbstate = TLBSTATE_OK;
13937+#endif
13938
13939 if (likely(prev != next)) {
13940 #ifdef CONFIG_SMP
13941+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13942+ tlbstate = this_cpu_read(cpu_tlbstate.state);
13943+#endif
13944 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
13945 this_cpu_write(cpu_tlbstate.active_mm, next);
13946 #endif
13947 cpumask_set_cpu(cpu, mm_cpumask(next));
13948
13949 /* Re-load page tables */
13950+#ifdef CONFIG_PAX_PER_CPU_PGD
13951+ pax_open_kernel();
13952+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13953+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13954+ pax_close_kernel();
13955+ load_cr3(get_cpu_pgd(cpu));
13956+#else
13957 load_cr3(next->pgd);
13958+#endif
13959
13960 /* stop flush ipis for the previous mm */
13961 cpumask_clear_cpu(cpu, mm_cpumask(prev));
13962@@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
13963 */
13964 if (unlikely(prev->context.ldt != next->context.ldt))
13965 load_LDT_nolock(&next->context);
13966- }
13967+
13968+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
13969+ if (!(__supported_pte_mask & _PAGE_NX)) {
13970+ smp_mb__before_clear_bit();
13971+ cpu_clear(cpu, prev->context.cpu_user_cs_mask);
13972+ smp_mb__after_clear_bit();
13973+ cpu_set(cpu, next->context.cpu_user_cs_mask);
13974+ }
13975+#endif
13976+
13977+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
13978+ if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
13979+ prev->context.user_cs_limit != next->context.user_cs_limit))
13980+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13981 #ifdef CONFIG_SMP
13982+ else if (unlikely(tlbstate != TLBSTATE_OK))
13983+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
13984+#endif
13985+#endif
13986+
13987+ }
13988 else {
13989+
13990+#ifdef CONFIG_PAX_PER_CPU_PGD
13991+ pax_open_kernel();
13992+ __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
13993+ __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
13994+ pax_close_kernel();
13995+ load_cr3(get_cpu_pgd(cpu));
13996+#endif
13997+
13998+#ifdef CONFIG_SMP
13999 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
14000 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
14001
14002@@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
14003 * tlb flush IPI delivery. We must reload CR3
14004 * to make sure to use no freed page tables.
14005 */
14006+
14007+#ifndef CONFIG_PAX_PER_CPU_PGD
14008 load_cr3(next->pgd);
14009+#endif
14010+
14011 load_LDT_nolock(&next->context);
14012+
14013+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
14014+ if (!(__supported_pte_mask & _PAGE_NX))
14015+ cpu_set(cpu, next->context.cpu_user_cs_mask);
14016+#endif
14017+
14018+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
14019+#ifdef CONFIG_PAX_PAGEEXEC
14020+ if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
14021+#endif
14022+ set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
14023+#endif
14024+
14025 }
14026+#endif
14027 }
14028-#endif
14029 }
14030
14031 #define activate_mm(prev, next) \
14032diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
14033index e3b7819..b257c64 100644
14034--- a/arch/x86/include/asm/module.h
14035+++ b/arch/x86/include/asm/module.h
14036@@ -5,6 +5,7 @@
14037
14038 #ifdef CONFIG_X86_64
14039 /* X86_64 does not define MODULE_PROC_FAMILY */
14040+#define MODULE_PROC_FAMILY ""
14041 #elif defined CONFIG_M486
14042 #define MODULE_PROC_FAMILY "486 "
14043 #elif defined CONFIG_M586
14044@@ -57,8 +58,20 @@
14045 #error unknown processor family
14046 #endif
14047
14048-#ifdef CONFIG_X86_32
14049-# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
14050+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14051+#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
14052+#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
14053+#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
14054+#else
14055+#define MODULE_PAX_KERNEXEC ""
14056 #endif
14057
14058+#ifdef CONFIG_PAX_MEMORY_UDEREF
14059+#define MODULE_PAX_UDEREF "UDEREF "
14060+#else
14061+#define MODULE_PAX_UDEREF ""
14062+#endif
14063+
14064+#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
14065+
14066 #endif /* _ASM_X86_MODULE_H */
14067diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
14068index c0fa356..07a498a 100644
14069--- a/arch/x86/include/asm/nmi.h
14070+++ b/arch/x86/include/asm/nmi.h
14071@@ -42,11 +42,11 @@ struct nmiaction {
14072 nmi_handler_t handler;
14073 unsigned long flags;
14074 const char *name;
14075-};
14076+} __do_const;
14077
14078 #define register_nmi_handler(t, fn, fg, n, init...) \
14079 ({ \
14080- static struct nmiaction init fn##_na = { \
14081+ static const struct nmiaction init fn##_na = { \
14082 .handler = (fn), \
14083 .name = (n), \
14084 .flags = (fg), \
14085@@ -54,7 +54,7 @@ struct nmiaction {
14086 __register_nmi_handler((t), &fn##_na); \
14087 })
14088
14089-int __register_nmi_handler(unsigned int, struct nmiaction *);
14090+int __register_nmi_handler(unsigned int, const struct nmiaction *);
14091
14092 void unregister_nmi_handler(unsigned int, const char *);
14093
14094diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
14095index 0f1ddee..e2fc3d1 100644
14096--- a/arch/x86/include/asm/page_64.h
14097+++ b/arch/x86/include/asm/page_64.h
14098@@ -7,9 +7,9 @@
14099
14100 /* duplicated to the one in bootmem.h */
14101 extern unsigned long max_pfn;
14102-extern unsigned long phys_base;
14103+extern const unsigned long phys_base;
14104
14105-static inline unsigned long __phys_addr_nodebug(unsigned long x)
14106+static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
14107 {
14108 unsigned long y = x - __START_KERNEL_map;
14109
14110diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
14111index 7361e47..16dc226 100644
14112--- a/arch/x86/include/asm/paravirt.h
14113+++ b/arch/x86/include/asm/paravirt.h
14114@@ -564,7 +564,7 @@ static inline pmd_t __pmd(pmdval_t val)
14115 return (pmd_t) { ret };
14116 }
14117
14118-static inline pmdval_t pmd_val(pmd_t pmd)
14119+static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
14120 {
14121 pmdval_t ret;
14122
14123@@ -630,6 +630,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
14124 val);
14125 }
14126
14127+static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14128+{
14129+ pgdval_t val = native_pgd_val(pgd);
14130+
14131+ if (sizeof(pgdval_t) > sizeof(long))
14132+ PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
14133+ val, (u64)val >> 32);
14134+ else
14135+ PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
14136+ val);
14137+}
14138+
14139 static inline void pgd_clear(pgd_t *pgdp)
14140 {
14141 set_pgd(pgdp, __pgd(0));
14142@@ -714,6 +726,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
14143 pv_mmu_ops.set_fixmap(idx, phys, flags);
14144 }
14145
14146+#ifdef CONFIG_PAX_KERNEXEC
14147+static inline unsigned long pax_open_kernel(void)
14148+{
14149+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
14150+}
14151+
14152+static inline unsigned long pax_close_kernel(void)
14153+{
14154+ return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
14155+}
14156+#else
14157+static inline unsigned long pax_open_kernel(void) { return 0; }
14158+static inline unsigned long pax_close_kernel(void) { return 0; }
14159+#endif
14160+
14161 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
14162
14163 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
14164@@ -930,7 +957,7 @@ extern void default_banner(void);
14165
14166 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
14167 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
14168-#define PARA_INDIRECT(addr) *%cs:addr
14169+#define PARA_INDIRECT(addr) *%ss:addr
14170 #endif
14171
14172 #define INTERRUPT_RETURN \
14173@@ -1005,6 +1032,21 @@ extern void default_banner(void);
14174 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
14175 CLBR_NONE, \
14176 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
14177+
14178+#define GET_CR0_INTO_RDI \
14179+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
14180+ mov %rax,%rdi
14181+
14182+#define SET_RDI_INTO_CR0 \
14183+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
14184+
14185+#define GET_CR3_INTO_RDI \
14186+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
14187+ mov %rax,%rdi
14188+
14189+#define SET_RDI_INTO_CR3 \
14190+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
14191+
14192 #endif /* CONFIG_X86_32 */
14193
14194 #endif /* __ASSEMBLY__ */
14195diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
14196index b3b0ec1..b1cd3eb 100644
14197--- a/arch/x86/include/asm/paravirt_types.h
14198+++ b/arch/x86/include/asm/paravirt_types.h
14199@@ -84,7 +84,7 @@ struct pv_init_ops {
14200 */
14201 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
14202 unsigned long addr, unsigned len);
14203-};
14204+} __no_const;
14205
14206
14207 struct pv_lazy_ops {
14208@@ -98,7 +98,7 @@ struct pv_time_ops {
14209 unsigned long long (*sched_clock)(void);
14210 unsigned long long (*steal_clock)(int cpu);
14211 unsigned long (*get_tsc_khz)(void);
14212-};
14213+} __no_const;
14214
14215 struct pv_cpu_ops {
14216 /* hooks for various privileged instructions */
14217@@ -192,7 +192,7 @@ struct pv_cpu_ops {
14218
14219 void (*start_context_switch)(struct task_struct *prev);
14220 void (*end_context_switch)(struct task_struct *next);
14221-};
14222+} __no_const;
14223
14224 struct pv_irq_ops {
14225 /*
14226@@ -223,7 +223,7 @@ struct pv_apic_ops {
14227 unsigned long start_eip,
14228 unsigned long start_esp);
14229 #endif
14230-};
14231+} __no_const;
14232
14233 struct pv_mmu_ops {
14234 unsigned long (*read_cr2)(void);
14235@@ -313,6 +313,7 @@ struct pv_mmu_ops {
14236 struct paravirt_callee_save make_pud;
14237
14238 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
14239+ void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
14240 #endif /* PAGETABLE_LEVELS == 4 */
14241 #endif /* PAGETABLE_LEVELS >= 3 */
14242
14243@@ -324,6 +325,12 @@ struct pv_mmu_ops {
14244 an mfn. We can tell which is which from the index. */
14245 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
14246 phys_addr_t phys, pgprot_t flags);
14247+
14248+#ifdef CONFIG_PAX_KERNEXEC
14249+ unsigned long (*pax_open_kernel)(void);
14250+ unsigned long (*pax_close_kernel)(void);
14251+#endif
14252+
14253 };
14254
14255 struct arch_spinlock;
14256@@ -334,7 +341,7 @@ struct pv_lock_ops {
14257 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
14258 int (*spin_trylock)(struct arch_spinlock *lock);
14259 void (*spin_unlock)(struct arch_spinlock *lock);
14260-};
14261+} __no_const;
14262
14263 /* This contains all the paravirt structures: we get a convenient
14264 * number for each function using the offset which we use to indicate
14265diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
14266index b4389a4..7024269 100644
14267--- a/arch/x86/include/asm/pgalloc.h
14268+++ b/arch/x86/include/asm/pgalloc.h
14269@@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
14270 pmd_t *pmd, pte_t *pte)
14271 {
14272 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14273+ set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
14274+}
14275+
14276+static inline void pmd_populate_user(struct mm_struct *mm,
14277+ pmd_t *pmd, pte_t *pte)
14278+{
14279+ paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
14280 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
14281 }
14282
14283@@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
14284
14285 #ifdef CONFIG_X86_PAE
14286 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
14287+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
14288+{
14289+ pud_populate(mm, pudp, pmd);
14290+}
14291 #else /* !CONFIG_X86_PAE */
14292 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14293 {
14294 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14295 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
14296 }
14297+
14298+static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
14299+{
14300+ paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
14301+ set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
14302+}
14303 #endif /* CONFIG_X86_PAE */
14304
14305 #if PAGETABLE_LEVELS > 3
14306@@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14307 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
14308 }
14309
14310+static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
14311+{
14312+ paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
14313+ set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
14314+}
14315+
14316 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
14317 {
14318 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
14319diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
14320index f2b489c..4f7e2e5 100644
14321--- a/arch/x86/include/asm/pgtable-2level.h
14322+++ b/arch/x86/include/asm/pgtable-2level.h
14323@@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
14324
14325 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14326 {
14327+ pax_open_kernel();
14328 *pmdp = pmd;
14329+ pax_close_kernel();
14330 }
14331
14332 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14333diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
14334index 4cc9f2b..5fd9226 100644
14335--- a/arch/x86/include/asm/pgtable-3level.h
14336+++ b/arch/x86/include/asm/pgtable-3level.h
14337@@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14338
14339 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14340 {
14341+ pax_open_kernel();
14342 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
14343+ pax_close_kernel();
14344 }
14345
14346 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14347 {
14348+ pax_open_kernel();
14349 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
14350+ pax_close_kernel();
14351 }
14352
14353 /*
14354diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
14355index 1e67223..dd6e7ea 100644
14356--- a/arch/x86/include/asm/pgtable.h
14357+++ b/arch/x86/include/asm/pgtable.h
14358@@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14359
14360 #ifndef __PAGETABLE_PUD_FOLDED
14361 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
14362+#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
14363 #define pgd_clear(pgd) native_pgd_clear(pgd)
14364 #endif
14365
14366@@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
14367
14368 #define arch_end_context_switch(prev) do {} while(0)
14369
14370+#define pax_open_kernel() native_pax_open_kernel()
14371+#define pax_close_kernel() native_pax_close_kernel()
14372 #endif /* CONFIG_PARAVIRT */
14373
14374+#define __HAVE_ARCH_PAX_OPEN_KERNEL
14375+#define __HAVE_ARCH_PAX_CLOSE_KERNEL
14376+
14377+#ifdef CONFIG_PAX_KERNEXEC
14378+static inline unsigned long native_pax_open_kernel(void)
14379+{
14380+ unsigned long cr0;
14381+
14382+ preempt_disable();
14383+ barrier();
14384+ cr0 = read_cr0() ^ X86_CR0_WP;
14385+ BUG_ON(cr0 & X86_CR0_WP);
14386+ write_cr0(cr0);
14387+ return cr0 ^ X86_CR0_WP;
14388+}
14389+
14390+static inline unsigned long native_pax_close_kernel(void)
14391+{
14392+ unsigned long cr0;
14393+
14394+ cr0 = read_cr0() ^ X86_CR0_WP;
14395+ BUG_ON(!(cr0 & X86_CR0_WP));
14396+ write_cr0(cr0);
14397+ barrier();
14398+ preempt_enable_no_resched();
14399+ return cr0 ^ X86_CR0_WP;
14400+}
14401+#else
14402+static inline unsigned long native_pax_open_kernel(void) { return 0; }
14403+static inline unsigned long native_pax_close_kernel(void) { return 0; }
14404+#endif
14405+
14406 /*
14407 * The following only work if pte_present() is true.
14408 * Undefined behaviour if not..
14409 */
14410+static inline int pte_user(pte_t pte)
14411+{
14412+ return pte_val(pte) & _PAGE_USER;
14413+}
14414+
14415 static inline int pte_dirty(pte_t pte)
14416 {
14417 return pte_flags(pte) & _PAGE_DIRTY;
14418@@ -147,6 +187,11 @@ static inline unsigned long pud_pfn(pud_t pud)
14419 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
14420 }
14421
14422+static inline unsigned long pgd_pfn(pgd_t pgd)
14423+{
14424+ return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
14425+}
14426+
14427 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
14428
14429 static inline int pmd_large(pmd_t pte)
14430@@ -200,9 +245,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
14431 return pte_clear_flags(pte, _PAGE_RW);
14432 }
14433
14434+static inline pte_t pte_mkread(pte_t pte)
14435+{
14436+ return __pte(pte_val(pte) | _PAGE_USER);
14437+}
14438+
14439 static inline pte_t pte_mkexec(pte_t pte)
14440 {
14441- return pte_clear_flags(pte, _PAGE_NX);
14442+#ifdef CONFIG_X86_PAE
14443+ if (__supported_pte_mask & _PAGE_NX)
14444+ return pte_clear_flags(pte, _PAGE_NX);
14445+ else
14446+#endif
14447+ return pte_set_flags(pte, _PAGE_USER);
14448+}
14449+
14450+static inline pte_t pte_exprotect(pte_t pte)
14451+{
14452+#ifdef CONFIG_X86_PAE
14453+ if (__supported_pte_mask & _PAGE_NX)
14454+ return pte_set_flags(pte, _PAGE_NX);
14455+ else
14456+#endif
14457+ return pte_clear_flags(pte, _PAGE_USER);
14458 }
14459
14460 static inline pte_t pte_mkdirty(pte_t pte)
14461@@ -394,6 +459,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
14462 #endif
14463
14464 #ifndef __ASSEMBLY__
14465+
14466+#ifdef CONFIG_PAX_PER_CPU_PGD
14467+extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
14468+static inline pgd_t *get_cpu_pgd(unsigned int cpu)
14469+{
14470+ return cpu_pgd[cpu];
14471+}
14472+#endif
14473+
14474 #include <linux/mm_types.h>
14475 #include <linux/log2.h>
14476
14477@@ -529,7 +603,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
14478 * Currently stuck as a macro due to indirect forward reference to
14479 * linux/mmzone.h's __section_mem_map_addr() definition:
14480 */
14481-#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
14482+#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
14483
14484 /* Find an entry in the second-level page table.. */
14485 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
14486@@ -569,7 +643,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
14487 * Currently stuck as a macro due to indirect forward reference to
14488 * linux/mmzone.h's __section_mem_map_addr() definition:
14489 */
14490-#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
14491+#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
14492
14493 /* to find an entry in a page-table-directory. */
14494 static inline unsigned long pud_index(unsigned long address)
14495@@ -584,7 +658,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
14496
14497 static inline int pgd_bad(pgd_t pgd)
14498 {
14499- return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
14500+ return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
14501 }
14502
14503 static inline int pgd_none(pgd_t pgd)
14504@@ -607,7 +681,12 @@ static inline int pgd_none(pgd_t pgd)
14505 * pgd_offset() returns a (pgd_t *)
14506 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
14507 */
14508-#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
14509+#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
14510+
14511+#ifdef CONFIG_PAX_PER_CPU_PGD
14512+#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
14513+#endif
14514+
14515 /*
14516 * a shortcut which implies the use of the kernel's pgd, instead
14517 * of a process's
14518@@ -618,6 +697,22 @@ static inline int pgd_none(pgd_t pgd)
14519 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
14520 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
14521
14522+#ifdef CONFIG_X86_32
14523+#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
14524+#else
14525+#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
14526+#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
14527+
14528+#ifdef CONFIG_PAX_MEMORY_UDEREF
14529+#ifdef __ASSEMBLY__
14530+#define pax_user_shadow_base pax_user_shadow_base(%rip)
14531+#else
14532+extern unsigned long pax_user_shadow_base;
14533+#endif
14534+#endif
14535+
14536+#endif
14537+
14538 #ifndef __ASSEMBLY__
14539
14540 extern int direct_gbpages;
14541@@ -784,11 +879,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
14542 * dst and src can be on the same page, but the range must not overlap,
14543 * and must not cross a page boundary.
14544 */
14545-static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
14546+static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
14547 {
14548- memcpy(dst, src, count * sizeof(pgd_t));
14549+ pax_open_kernel();
14550+ while (count--)
14551+ *dst++ = *src++;
14552+ pax_close_kernel();
14553 }
14554
14555+#ifdef CONFIG_PAX_PER_CPU_PGD
14556+extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
14557+#endif
14558+
14559+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
14560+extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
14561+#else
14562+static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
14563+#endif
14564+
14565 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
14566 static inline int page_level_shift(enum pg_level level)
14567 {
14568diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
14569index 9ee3221..b979c6b 100644
14570--- a/arch/x86/include/asm/pgtable_32.h
14571+++ b/arch/x86/include/asm/pgtable_32.h
14572@@ -25,9 +25,6 @@
14573 struct mm_struct;
14574 struct vm_area_struct;
14575
14576-extern pgd_t swapper_pg_dir[1024];
14577-extern pgd_t initial_page_table[1024];
14578-
14579 static inline void pgtable_cache_init(void) { }
14580 static inline void check_pgt_cache(void) { }
14581 void paging_init(void);
14582@@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14583 # include <asm/pgtable-2level.h>
14584 #endif
14585
14586+extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
14587+extern pgd_t initial_page_table[PTRS_PER_PGD];
14588+#ifdef CONFIG_X86_PAE
14589+extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
14590+#endif
14591+
14592 #if defined(CONFIG_HIGHPTE)
14593 #define pte_offset_map(dir, address) \
14594 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
14595@@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
14596 /* Clear a kernel PTE and flush it from the TLB */
14597 #define kpte_clear_flush(ptep, vaddr) \
14598 do { \
14599+ pax_open_kernel(); \
14600 pte_clear(&init_mm, (vaddr), (ptep)); \
14601+ pax_close_kernel(); \
14602 __flush_tlb_one((vaddr)); \
14603 } while (0)
14604
14605 #endif /* !__ASSEMBLY__ */
14606
14607+#define HAVE_ARCH_UNMAPPED_AREA
14608+#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
14609+
14610 /*
14611 * kern_addr_valid() is (1) for FLATMEM and (0) for
14612 * SPARSEMEM and DISCONTIGMEM
14613diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
14614index ed5903b..c7fe163 100644
14615--- a/arch/x86/include/asm/pgtable_32_types.h
14616+++ b/arch/x86/include/asm/pgtable_32_types.h
14617@@ -8,7 +8,7 @@
14618 */
14619 #ifdef CONFIG_X86_PAE
14620 # include <asm/pgtable-3level_types.h>
14621-# define PMD_SIZE (1UL << PMD_SHIFT)
14622+# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
14623 # define PMD_MASK (~(PMD_SIZE - 1))
14624 #else
14625 # include <asm/pgtable-2level_types.h>
14626@@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
14627 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
14628 #endif
14629
14630+#ifdef CONFIG_PAX_KERNEXEC
14631+#ifndef __ASSEMBLY__
14632+extern unsigned char MODULES_EXEC_VADDR[];
14633+extern unsigned char MODULES_EXEC_END[];
14634+#endif
14635+#include <asm/boot.h>
14636+#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
14637+#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
14638+#else
14639+#define ktla_ktva(addr) (addr)
14640+#define ktva_ktla(addr) (addr)
14641+#endif
14642+
14643 #define MODULES_VADDR VMALLOC_START
14644 #define MODULES_END VMALLOC_END
14645 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
14646diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
14647index e22c1db..23a625a 100644
14648--- a/arch/x86/include/asm/pgtable_64.h
14649+++ b/arch/x86/include/asm/pgtable_64.h
14650@@ -16,10 +16,14 @@
14651
14652 extern pud_t level3_kernel_pgt[512];
14653 extern pud_t level3_ident_pgt[512];
14654+extern pud_t level3_vmalloc_start_pgt[512];
14655+extern pud_t level3_vmalloc_end_pgt[512];
14656+extern pud_t level3_vmemmap_pgt[512];
14657+extern pud_t level2_vmemmap_pgt[512];
14658 extern pmd_t level2_kernel_pgt[512];
14659 extern pmd_t level2_fixmap_pgt[512];
14660-extern pmd_t level2_ident_pgt[512];
14661-extern pgd_t init_level4_pgt[];
14662+extern pmd_t level2_ident_pgt[512*2];
14663+extern pgd_t init_level4_pgt[512];
14664
14665 #define swapper_pg_dir init_level4_pgt
14666
14667@@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
14668
14669 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
14670 {
14671+ pax_open_kernel();
14672 *pmdp = pmd;
14673+ pax_close_kernel();
14674 }
14675
14676 static inline void native_pmd_clear(pmd_t *pmd)
14677@@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
14678
14679 static inline void native_set_pud(pud_t *pudp, pud_t pud)
14680 {
14681+ pax_open_kernel();
14682 *pudp = pud;
14683+ pax_close_kernel();
14684 }
14685
14686 static inline void native_pud_clear(pud_t *pud)
14687@@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
14688
14689 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
14690 {
14691+ pax_open_kernel();
14692+ *pgdp = pgd;
14693+ pax_close_kernel();
14694+}
14695+
14696+static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
14697+{
14698 *pgdp = pgd;
14699 }
14700
14701diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
14702index 2d88344..4679fc3 100644
14703--- a/arch/x86/include/asm/pgtable_64_types.h
14704+++ b/arch/x86/include/asm/pgtable_64_types.h
14705@@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
14706 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
14707 #define MODULES_END _AC(0xffffffffff000000, UL)
14708 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
14709+#define MODULES_EXEC_VADDR MODULES_VADDR
14710+#define MODULES_EXEC_END MODULES_END
14711+
14712+#define ktla_ktva(addr) (addr)
14713+#define ktva_ktla(addr) (addr)
14714
14715 #define EARLY_DYNAMIC_PAGE_TABLES 64
14716
14717diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
14718index 567b5d0..bd91d64 100644
14719--- a/arch/x86/include/asm/pgtable_types.h
14720+++ b/arch/x86/include/asm/pgtable_types.h
14721@@ -16,13 +16,12 @@
14722 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
14723 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
14724 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
14725-#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
14726+#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
14727 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
14728 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
14729 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
14730-#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
14731-#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
14732-#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
14733+#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
14734+#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
14735 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
14736
14737 /* If _PAGE_BIT_PRESENT is clear, we use these: */
14738@@ -40,7 +39,6 @@
14739 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
14740 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
14741 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
14742-#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
14743 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
14744 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
14745 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
14746@@ -57,8 +55,10 @@
14747
14748 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
14749 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
14750-#else
14751+#elif defined(CONFIG_KMEMCHECK)
14752 #define _PAGE_NX (_AT(pteval_t, 0))
14753+#else
14754+#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
14755 #endif
14756
14757 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
14758@@ -116,6 +116,9 @@
14759 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
14760 _PAGE_ACCESSED)
14761
14762+#define PAGE_READONLY_NOEXEC PAGE_READONLY
14763+#define PAGE_SHARED_NOEXEC PAGE_SHARED
14764+
14765 #define __PAGE_KERNEL_EXEC \
14766 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
14767 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
14768@@ -126,7 +129,7 @@
14769 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
14770 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
14771 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
14772-#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
14773+#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
14774 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
14775 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
14776 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
14777@@ -188,8 +191,8 @@
14778 * bits are combined, this will alow user to access the high address mapped
14779 * VDSO in the presence of CONFIG_COMPAT_VDSO
14780 */
14781-#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
14782-#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
14783+#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14784+#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
14785 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
14786 #endif
14787
14788@@ -227,7 +230,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
14789 {
14790 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
14791 }
14792+#endif
14793
14794+#if PAGETABLE_LEVELS == 3
14795+#include <asm-generic/pgtable-nopud.h>
14796+#endif
14797+
14798+#if PAGETABLE_LEVELS == 2
14799+#include <asm-generic/pgtable-nopmd.h>
14800+#endif
14801+
14802+#ifndef __ASSEMBLY__
14803 #if PAGETABLE_LEVELS > 3
14804 typedef struct { pudval_t pud; } pud_t;
14805
14806@@ -241,8 +254,6 @@ static inline pudval_t native_pud_val(pud_t pud)
14807 return pud.pud;
14808 }
14809 #else
14810-#include <asm-generic/pgtable-nopud.h>
14811-
14812 static inline pudval_t native_pud_val(pud_t pud)
14813 {
14814 return native_pgd_val(pud.pgd);
14815@@ -262,8 +273,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
14816 return pmd.pmd;
14817 }
14818 #else
14819-#include <asm-generic/pgtable-nopmd.h>
14820-
14821 static inline pmdval_t native_pmd_val(pmd_t pmd)
14822 {
14823 return native_pgd_val(pmd.pud.pgd);
14824@@ -303,7 +312,6 @@ typedef struct page *pgtable_t;
14825
14826 extern pteval_t __supported_pte_mask;
14827 extern void set_nx(void);
14828-extern int nx_enabled;
14829
14830 #define pgprot_writecombine pgprot_writecombine
14831 extern pgprot_t pgprot_writecombine(pgprot_t prot);
14832diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
14833index 3270116..8d99d82 100644
14834--- a/arch/x86/include/asm/processor.h
14835+++ b/arch/x86/include/asm/processor.h
14836@@ -285,7 +285,7 @@ struct tss_struct {
14837
14838 } ____cacheline_aligned;
14839
14840-DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
14841+extern struct tss_struct init_tss[NR_CPUS];
14842
14843 /*
14844 * Save the original ist values for checking stack pointers during debugging
14845@@ -826,11 +826,18 @@ static inline void spin_lock_prefetch(const void *x)
14846 */
14847 #define TASK_SIZE PAGE_OFFSET
14848 #define TASK_SIZE_MAX TASK_SIZE
14849+
14850+#ifdef CONFIG_PAX_SEGMEXEC
14851+#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
14852+#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
14853+#else
14854 #define STACK_TOP TASK_SIZE
14855-#define STACK_TOP_MAX STACK_TOP
14856+#endif
14857+
14858+#define STACK_TOP_MAX TASK_SIZE
14859
14860 #define INIT_THREAD { \
14861- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14862+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14863 .vm86_info = NULL, \
14864 .sysenter_cs = __KERNEL_CS, \
14865 .io_bitmap_ptr = NULL, \
14866@@ -844,7 +851,7 @@ static inline void spin_lock_prefetch(const void *x)
14867 */
14868 #define INIT_TSS { \
14869 .x86_tss = { \
14870- .sp0 = sizeof(init_stack) + (long)&init_stack, \
14871+ .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
14872 .ss0 = __KERNEL_DS, \
14873 .ss1 = __KERNEL_CS, \
14874 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
14875@@ -855,11 +862,7 @@ static inline void spin_lock_prefetch(const void *x)
14876 extern unsigned long thread_saved_pc(struct task_struct *tsk);
14877
14878 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
14879-#define KSTK_TOP(info) \
14880-({ \
14881- unsigned long *__ptr = (unsigned long *)(info); \
14882- (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
14883-})
14884+#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
14885
14886 /*
14887 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
14888@@ -874,7 +877,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14889 #define task_pt_regs(task) \
14890 ({ \
14891 struct pt_regs *__regs__; \
14892- __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
14893+ __regs__ = (struct pt_regs *)((task)->thread.sp0); \
14894 __regs__ - 1; \
14895 })
14896
14897@@ -884,13 +887,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14898 /*
14899 * User space process size. 47bits minus one guard page.
14900 */
14901-#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
14902+#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
14903
14904 /* This decides where the kernel will search for a free chunk of vm
14905 * space during mmap's.
14906 */
14907 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
14908- 0xc0000000 : 0xFFFFe000)
14909+ 0xc0000000 : 0xFFFFf000)
14910
14911 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
14912 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
14913@@ -901,11 +904,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
14914 #define STACK_TOP_MAX TASK_SIZE_MAX
14915
14916 #define INIT_THREAD { \
14917- .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14918+ .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14919 }
14920
14921 #define INIT_TSS { \
14922- .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
14923+ .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
14924 }
14925
14926 /*
14927@@ -933,6 +936,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
14928 */
14929 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
14930
14931+#ifdef CONFIG_PAX_SEGMEXEC
14932+#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
14933+#endif
14934+
14935 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
14936
14937 /* Get/set a process' ability to use the timestamp counter instruction */
14938@@ -993,7 +1000,7 @@ extern bool cpu_has_amd_erratum(const int *);
14939 #define cpu_has_amd_erratum(x) (false)
14940 #endif /* CONFIG_CPU_SUP_AMD */
14941
14942-extern unsigned long arch_align_stack(unsigned long sp);
14943+#define arch_align_stack(x) ((x) & ~0xfUL)
14944 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
14945
14946 void default_idle(void);
14947@@ -1003,6 +1010,6 @@ bool xen_set_default_idle(void);
14948 #define xen_set_default_idle 0
14949 #endif
14950
14951-void stop_this_cpu(void *dummy);
14952+void stop_this_cpu(void *dummy) __noreturn;
14953
14954 #endif /* _ASM_X86_PROCESSOR_H */
14955diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
14956index 942a086..6c26446 100644
14957--- a/arch/x86/include/asm/ptrace.h
14958+++ b/arch/x86/include/asm/ptrace.h
14959@@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
14960 }
14961
14962 /*
14963- * user_mode_vm(regs) determines whether a register set came from user mode.
14964+ * user_mode(regs) determines whether a register set came from user mode.
14965 * This is true if V8086 mode was enabled OR if the register set was from
14966 * protected mode with RPL-3 CS value. This tricky test checks that with
14967 * one comparison. Many places in the kernel can bypass this full check
14968- * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
14969+ * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
14970+ * be used.
14971 */
14972-static inline int user_mode(struct pt_regs *regs)
14973+static inline int user_mode_novm(struct pt_regs *regs)
14974 {
14975 #ifdef CONFIG_X86_32
14976 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
14977 #else
14978- return !!(regs->cs & 3);
14979+ return !!(regs->cs & SEGMENT_RPL_MASK);
14980 #endif
14981 }
14982
14983-static inline int user_mode_vm(struct pt_regs *regs)
14984+static inline int user_mode(struct pt_regs *regs)
14985 {
14986 #ifdef CONFIG_X86_32
14987 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
14988 USER_RPL;
14989 #else
14990- return user_mode(regs);
14991+ return user_mode_novm(regs);
14992 #endif
14993 }
14994
14995@@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
14996 #ifdef CONFIG_X86_64
14997 static inline bool user_64bit_mode(struct pt_regs *regs)
14998 {
14999+ unsigned long cs = regs->cs & 0xffff;
15000 #ifndef CONFIG_PARAVIRT
15001 /*
15002 * On non-paravirt systems, this is the only long mode CPL 3
15003 * selector. We do not allow long mode selectors in the LDT.
15004 */
15005- return regs->cs == __USER_CS;
15006+ return cs == __USER_CS;
15007 #else
15008 /* Headers are too twisted for this to go in paravirt.h. */
15009- return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
15010+ return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
15011 #endif
15012 }
15013
15014@@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
15015 * Traps from the kernel do not save sp and ss.
15016 * Use the helper function to retrieve sp.
15017 */
15018- if (offset == offsetof(struct pt_regs, sp) &&
15019- regs->cs == __KERNEL_CS)
15020- return kernel_stack_pointer(regs);
15021+ if (offset == offsetof(struct pt_regs, sp)) {
15022+ unsigned long cs = regs->cs & 0xffff;
15023+ if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
15024+ return kernel_stack_pointer(regs);
15025+ }
15026 #endif
15027 return *(unsigned long *)((unsigned long)regs + offset);
15028 }
15029diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
15030index 9c6b890..5305f53 100644
15031--- a/arch/x86/include/asm/realmode.h
15032+++ b/arch/x86/include/asm/realmode.h
15033@@ -22,16 +22,14 @@ struct real_mode_header {
15034 #endif
15035 /* APM/BIOS reboot */
15036 u32 machine_real_restart_asm;
15037-#ifdef CONFIG_X86_64
15038 u32 machine_real_restart_seg;
15039-#endif
15040 };
15041
15042 /* This must match data at trampoline_32/64.S */
15043 struct trampoline_header {
15044 #ifdef CONFIG_X86_32
15045 u32 start;
15046- u16 gdt_pad;
15047+ u16 boot_cs;
15048 u16 gdt_limit;
15049 u32 gdt_base;
15050 #else
15051diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
15052index a82c4f1..ac45053 100644
15053--- a/arch/x86/include/asm/reboot.h
15054+++ b/arch/x86/include/asm/reboot.h
15055@@ -6,13 +6,13 @@
15056 struct pt_regs;
15057
15058 struct machine_ops {
15059- void (*restart)(char *cmd);
15060- void (*halt)(void);
15061- void (*power_off)(void);
15062+ void (* __noreturn restart)(char *cmd);
15063+ void (* __noreturn halt)(void);
15064+ void (* __noreturn power_off)(void);
15065 void (*shutdown)(void);
15066 void (*crash_shutdown)(struct pt_regs *);
15067- void (*emergency_restart)(void);
15068-};
15069+ void (* __noreturn emergency_restart)(void);
15070+} __no_const;
15071
15072 extern struct machine_ops machine_ops;
15073
15074diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
15075index 2dbe4a7..ce1db00 100644
15076--- a/arch/x86/include/asm/rwsem.h
15077+++ b/arch/x86/include/asm/rwsem.h
15078@@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
15079 {
15080 asm volatile("# beginning down_read\n\t"
15081 LOCK_PREFIX _ASM_INC "(%1)\n\t"
15082+
15083+#ifdef CONFIG_PAX_REFCOUNT
15084+ "jno 0f\n"
15085+ LOCK_PREFIX _ASM_DEC "(%1)\n"
15086+ "int $4\n0:\n"
15087+ _ASM_EXTABLE(0b, 0b)
15088+#endif
15089+
15090 /* adds 0x00000001 */
15091 " jns 1f\n"
15092 " call call_rwsem_down_read_failed\n"
15093@@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
15094 "1:\n\t"
15095 " mov %1,%2\n\t"
15096 " add %3,%2\n\t"
15097+
15098+#ifdef CONFIG_PAX_REFCOUNT
15099+ "jno 0f\n"
15100+ "sub %3,%2\n"
15101+ "int $4\n0:\n"
15102+ _ASM_EXTABLE(0b, 0b)
15103+#endif
15104+
15105 " jle 2f\n\t"
15106 LOCK_PREFIX " cmpxchg %2,%0\n\t"
15107 " jnz 1b\n\t"
15108@@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
15109 long tmp;
15110 asm volatile("# beginning down_write\n\t"
15111 LOCK_PREFIX " xadd %1,(%2)\n\t"
15112+
15113+#ifdef CONFIG_PAX_REFCOUNT
15114+ "jno 0f\n"
15115+ "mov %1,(%2)\n"
15116+ "int $4\n0:\n"
15117+ _ASM_EXTABLE(0b, 0b)
15118+#endif
15119+
15120 /* adds 0xffff0001, returns the old value */
15121 " test %1,%1\n\t"
15122 /* was the count 0 before? */
15123@@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
15124 long tmp;
15125 asm volatile("# beginning __up_read\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 /* subtracts 1, returns the old value */
15136 " jns 1f\n\t"
15137 " call call_rwsem_wake\n" /* expects old value in %edx */
15138@@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
15139 long tmp;
15140 asm volatile("# beginning __up_write\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 0xffff0001, returns the old value */
15151 " jns 1f\n\t"
15152 " call call_rwsem_wake\n" /* expects old value in %edx */
15153@@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15154 {
15155 asm volatile("# beginning __downgrade_write\n\t"
15156 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
15157+
15158+#ifdef CONFIG_PAX_REFCOUNT
15159+ "jno 0f\n"
15160+ LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
15161+ "int $4\n0:\n"
15162+ _ASM_EXTABLE(0b, 0b)
15163+#endif
15164+
15165 /*
15166 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
15167 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
15168@@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
15169 */
15170 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15171 {
15172- asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
15173+ asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
15174+
15175+#ifdef CONFIG_PAX_REFCOUNT
15176+ "jno 0f\n"
15177+ LOCK_PREFIX _ASM_SUB "%1,%0\n"
15178+ "int $4\n0:\n"
15179+ _ASM_EXTABLE(0b, 0b)
15180+#endif
15181+
15182 : "+m" (sem->count)
15183 : "er" (delta));
15184 }
15185@@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
15186 */
15187 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
15188 {
15189- return delta + xadd(&sem->count, delta);
15190+ return delta + xadd_check_overflow(&sem->count, delta);
15191 }
15192
15193 #endif /* __KERNEL__ */
15194diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
15195index c48a950..c6d7468 100644
15196--- a/arch/x86/include/asm/segment.h
15197+++ b/arch/x86/include/asm/segment.h
15198@@ -64,10 +64,15 @@
15199 * 26 - ESPFIX small SS
15200 * 27 - per-cpu [ offset to per-cpu data area ]
15201 * 28 - stack_canary-20 [ for stack protector ]
15202- * 29 - unused
15203- * 30 - unused
15204+ * 29 - PCI BIOS CS
15205+ * 30 - PCI BIOS DS
15206 * 31 - TSS for double fault handler
15207 */
15208+#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
15209+#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
15210+#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
15211+#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
15212+
15213 #define GDT_ENTRY_TLS_MIN 6
15214 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
15215
15216@@ -79,6 +84,8 @@
15217
15218 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
15219
15220+#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
15221+
15222 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
15223
15224 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
15225@@ -104,6 +111,12 @@
15226 #define __KERNEL_STACK_CANARY 0
15227 #endif
15228
15229+#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
15230+#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
15231+
15232+#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
15233+#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
15234+
15235 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
15236
15237 /*
15238@@ -141,7 +154,7 @@
15239 */
15240
15241 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
15242-#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
15243+#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
15244
15245
15246 #else
15247@@ -165,6 +178,8 @@
15248 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
15249 #define __USER32_DS __USER_DS
15250
15251+#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
15252+
15253 #define GDT_ENTRY_TSS 8 /* needs two entries */
15254 #define GDT_ENTRY_LDT 10 /* needs two entries */
15255 #define GDT_ENTRY_TLS_MIN 12
15256@@ -185,6 +200,7 @@
15257 #endif
15258
15259 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
15260+#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
15261 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
15262 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
15263 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
15264@@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
15265 {
15266 unsigned long __limit;
15267 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
15268- return __limit + 1;
15269+ return __limit;
15270 }
15271
15272 #endif /* !__ASSEMBLY__ */
15273diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
15274index b073aae..39f9bdd 100644
15275--- a/arch/x86/include/asm/smp.h
15276+++ b/arch/x86/include/asm/smp.h
15277@@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
15278 /* cpus sharing the last level cache: */
15279 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
15280 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
15281-DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
15282+DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
15283
15284 static inline struct cpumask *cpu_sibling_mask(int cpu)
15285 {
15286@@ -79,7 +79,7 @@ struct smp_ops {
15287
15288 void (*send_call_func_ipi)(const struct cpumask *mask);
15289 void (*send_call_func_single_ipi)(int cpu);
15290-};
15291+} __no_const;
15292
15293 /* Globals due to paravirt */
15294 extern void set_cpu_sibling_map(int cpu);
15295@@ -191,14 +191,8 @@ extern unsigned disabled_cpus __cpuinitdata;
15296 extern int safe_smp_processor_id(void);
15297
15298 #elif defined(CONFIG_X86_64_SMP)
15299-#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15300-
15301-#define stack_smp_processor_id() \
15302-({ \
15303- struct thread_info *ti; \
15304- __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
15305- ti->cpu; \
15306-})
15307+#define raw_smp_processor_id() (this_cpu_read(cpu_number))
15308+#define stack_smp_processor_id() raw_smp_processor_id()
15309 #define safe_smp_processor_id() smp_processor_id()
15310
15311 #endif
15312diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
15313index 33692ea..350a534 100644
15314--- a/arch/x86/include/asm/spinlock.h
15315+++ b/arch/x86/include/asm/spinlock.h
15316@@ -172,6 +172,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
15317 static inline void arch_read_lock(arch_rwlock_t *rw)
15318 {
15319 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
15320+
15321+#ifdef CONFIG_PAX_REFCOUNT
15322+ "jno 0f\n"
15323+ LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
15324+ "int $4\n0:\n"
15325+ _ASM_EXTABLE(0b, 0b)
15326+#endif
15327+
15328 "jns 1f\n"
15329 "call __read_lock_failed\n\t"
15330 "1:\n"
15331@@ -181,6 +189,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
15332 static inline void arch_write_lock(arch_rwlock_t *rw)
15333 {
15334 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
15335+
15336+#ifdef CONFIG_PAX_REFCOUNT
15337+ "jno 0f\n"
15338+ LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
15339+ "int $4\n0:\n"
15340+ _ASM_EXTABLE(0b, 0b)
15341+#endif
15342+
15343 "jz 1f\n"
15344 "call __write_lock_failed\n\t"
15345 "1:\n"
15346@@ -210,13 +226,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
15347
15348 static inline void arch_read_unlock(arch_rwlock_t *rw)
15349 {
15350- asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
15351+ asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
15352+
15353+#ifdef CONFIG_PAX_REFCOUNT
15354+ "jno 0f\n"
15355+ LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
15356+ "int $4\n0:\n"
15357+ _ASM_EXTABLE(0b, 0b)
15358+#endif
15359+
15360 :"+m" (rw->lock) : : "memory");
15361 }
15362
15363 static inline void arch_write_unlock(arch_rwlock_t *rw)
15364 {
15365- asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
15366+ asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
15367+
15368+#ifdef CONFIG_PAX_REFCOUNT
15369+ "jno 0f\n"
15370+ LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
15371+ "int $4\n0:\n"
15372+ _ASM_EXTABLE(0b, 0b)
15373+#endif
15374+
15375 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
15376 }
15377
15378diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
15379index 6a99859..03cb807 100644
15380--- a/arch/x86/include/asm/stackprotector.h
15381+++ b/arch/x86/include/asm/stackprotector.h
15382@@ -47,7 +47,7 @@
15383 * head_32 for boot CPU and setup_per_cpu_areas() for others.
15384 */
15385 #define GDT_STACK_CANARY_INIT \
15386- [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
15387+ [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
15388
15389 /*
15390 * Initialize the stackprotector canary value.
15391@@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
15392
15393 static inline void load_stack_canary_segment(void)
15394 {
15395-#ifdef CONFIG_X86_32
15396+#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
15397 asm volatile ("mov %0, %%gs" : : "r" (0));
15398 #endif
15399 }
15400diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
15401index 70bbe39..4ae2bd4 100644
15402--- a/arch/x86/include/asm/stacktrace.h
15403+++ b/arch/x86/include/asm/stacktrace.h
15404@@ -11,28 +11,20 @@
15405
15406 extern int kstack_depth_to_print;
15407
15408-struct thread_info;
15409+struct task_struct;
15410 struct stacktrace_ops;
15411
15412-typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
15413- unsigned long *stack,
15414- unsigned long bp,
15415- const struct stacktrace_ops *ops,
15416- void *data,
15417- unsigned long *end,
15418- int *graph);
15419+typedef unsigned long walk_stack_t(struct task_struct *task,
15420+ void *stack_start,
15421+ unsigned long *stack,
15422+ unsigned long bp,
15423+ const struct stacktrace_ops *ops,
15424+ void *data,
15425+ unsigned long *end,
15426+ int *graph);
15427
15428-extern unsigned long
15429-print_context_stack(struct thread_info *tinfo,
15430- unsigned long *stack, unsigned long bp,
15431- const struct stacktrace_ops *ops, void *data,
15432- unsigned long *end, int *graph);
15433-
15434-extern unsigned long
15435-print_context_stack_bp(struct thread_info *tinfo,
15436- unsigned long *stack, unsigned long bp,
15437- const struct stacktrace_ops *ops, void *data,
15438- unsigned long *end, int *graph);
15439+extern walk_stack_t print_context_stack;
15440+extern walk_stack_t print_context_stack_bp;
15441
15442 /* Generic stack tracer with callbacks */
15443
15444@@ -40,7 +32,7 @@ struct stacktrace_ops {
15445 void (*address)(void *data, unsigned long address, int reliable);
15446 /* On negative return stop dumping */
15447 int (*stack)(void *data, char *name);
15448- walk_stack_t walk_stack;
15449+ walk_stack_t *walk_stack;
15450 };
15451
15452 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
15453diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
15454index 4ec45b3..a4f0a8a 100644
15455--- a/arch/x86/include/asm/switch_to.h
15456+++ b/arch/x86/include/asm/switch_to.h
15457@@ -108,7 +108,7 @@ do { \
15458 "call __switch_to\n\t" \
15459 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
15460 __switch_canary \
15461- "movq %P[thread_info](%%rsi),%%r8\n\t" \
15462+ "movq "__percpu_arg([thread_info])",%%r8\n\t" \
15463 "movq %%rax,%%rdi\n\t" \
15464 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
15465 "jnz ret_from_fork\n\t" \
15466@@ -119,7 +119,7 @@ do { \
15467 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
15468 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
15469 [_tif_fork] "i" (_TIF_FORK), \
15470- [thread_info] "i" (offsetof(struct task_struct, stack)), \
15471+ [thread_info] "m" (current_tinfo), \
15472 [current_task] "m" (current_task) \
15473 __switch_canary_iparam \
15474 : "memory", "cc" __EXTRA_CLOBBER)
15475diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
15476index 2cd056e..0224df8 100644
15477--- a/arch/x86/include/asm/thread_info.h
15478+++ b/arch/x86/include/asm/thread_info.h
15479@@ -10,6 +10,7 @@
15480 #include <linux/compiler.h>
15481 #include <asm/page.h>
15482 #include <asm/types.h>
15483+#include <asm/percpu.h>
15484
15485 /*
15486 * low level task data that entry.S needs immediate access to
15487@@ -23,7 +24,6 @@ struct exec_domain;
15488 #include <linux/atomic.h>
15489
15490 struct thread_info {
15491- struct task_struct *task; /* main task structure */
15492 struct exec_domain *exec_domain; /* execution domain */
15493 __u32 flags; /* low level flags */
15494 __u32 status; /* thread synchronous flags */
15495@@ -33,19 +33,13 @@ struct thread_info {
15496 mm_segment_t addr_limit;
15497 struct restart_block restart_block;
15498 void __user *sysenter_return;
15499-#ifdef CONFIG_X86_32
15500- unsigned long previous_esp; /* ESP of the previous stack in
15501- case of nested (IRQ) stacks
15502- */
15503- __u8 supervisor_stack[0];
15504-#endif
15505+ unsigned long lowest_stack;
15506 unsigned int sig_on_uaccess_error:1;
15507 unsigned int uaccess_err:1; /* uaccess failed */
15508 };
15509
15510-#define INIT_THREAD_INFO(tsk) \
15511+#define INIT_THREAD_INFO \
15512 { \
15513- .task = &tsk, \
15514 .exec_domain = &default_exec_domain, \
15515 .flags = 0, \
15516 .cpu = 0, \
15517@@ -56,7 +50,7 @@ struct thread_info {
15518 }, \
15519 }
15520
15521-#define init_thread_info (init_thread_union.thread_info)
15522+#define init_thread_info (init_thread_union.stack)
15523 #define init_stack (init_thread_union.stack)
15524
15525 #else /* !__ASSEMBLY__ */
15526@@ -97,6 +91,7 @@ struct thread_info {
15527 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
15528 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
15529 #define TIF_X32 30 /* 32-bit native x86-64 binary */
15530+#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
15531
15532 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
15533 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
15534@@ -121,17 +116,18 @@ struct thread_info {
15535 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
15536 #define _TIF_ADDR32 (1 << TIF_ADDR32)
15537 #define _TIF_X32 (1 << TIF_X32)
15538+#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
15539
15540 /* work to do in syscall_trace_enter() */
15541 #define _TIF_WORK_SYSCALL_ENTRY \
15542 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
15543 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
15544- _TIF_NOHZ)
15545+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15546
15547 /* work to do in syscall_trace_leave() */
15548 #define _TIF_WORK_SYSCALL_EXIT \
15549 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
15550- _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
15551+ _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
15552
15553 /* work to do on interrupt/exception return */
15554 #define _TIF_WORK_MASK \
15555@@ -142,7 +138,7 @@ struct thread_info {
15556 /* work to do on any return to user space */
15557 #define _TIF_ALLWORK_MASK \
15558 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
15559- _TIF_NOHZ)
15560+ _TIF_NOHZ | _TIF_GRSEC_SETXID)
15561
15562 /* Only used for 64 bit */
15563 #define _TIF_DO_NOTIFY_MASK \
15564@@ -158,45 +154,40 @@ struct thread_info {
15565
15566 #define PREEMPT_ACTIVE 0x10000000
15567
15568-#ifdef CONFIG_X86_32
15569-
15570-#define STACK_WARN (THREAD_SIZE/8)
15571-/*
15572- * macros/functions for gaining access to the thread information structure
15573- *
15574- * preempt_count needs to be 1 initially, until the scheduler is functional.
15575- */
15576-#ifndef __ASSEMBLY__
15577-
15578-
15579-/* how to get the current stack pointer from C */
15580-register unsigned long current_stack_pointer asm("esp") __used;
15581-
15582-/* how to get the thread information struct from C */
15583-static inline struct thread_info *current_thread_info(void)
15584-{
15585- return (struct thread_info *)
15586- (current_stack_pointer & ~(THREAD_SIZE - 1));
15587-}
15588-
15589-#else /* !__ASSEMBLY__ */
15590-
15591+#ifdef __ASSEMBLY__
15592 /* how to get the thread information struct from ASM */
15593 #define GET_THREAD_INFO(reg) \
15594- movl $-THREAD_SIZE, reg; \
15595- andl %esp, reg
15596+ mov PER_CPU_VAR(current_tinfo), reg
15597
15598 /* use this one if reg already contains %esp */
15599-#define GET_THREAD_INFO_WITH_ESP(reg) \
15600- andl $-THREAD_SIZE, reg
15601+#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
15602+#else
15603+/* how to get the thread information struct from C */
15604+DECLARE_PER_CPU(struct thread_info *, current_tinfo);
15605+
15606+static __always_inline struct thread_info *current_thread_info(void)
15607+{
15608+ return this_cpu_read_stable(current_tinfo);
15609+}
15610+#endif
15611+
15612+#ifdef CONFIG_X86_32
15613+
15614+#define STACK_WARN (THREAD_SIZE/8)
15615+/*
15616+ * macros/functions for gaining access to the thread information structure
15617+ *
15618+ * preempt_count needs to be 1 initially, until the scheduler is functional.
15619+ */
15620+#ifndef __ASSEMBLY__
15621+
15622+/* how to get the current stack pointer from C */
15623+register unsigned long current_stack_pointer asm("esp") __used;
15624
15625 #endif
15626
15627 #else /* X86_32 */
15628
15629-#include <asm/percpu.h>
15630-#define KERNEL_STACK_OFFSET (5*8)
15631-
15632 /*
15633 * macros/functions for gaining access to the thread information structure
15634 * preempt_count needs to be 1 initially, until the scheduler is functional.
15635@@ -204,27 +195,8 @@ static inline struct thread_info *current_thread_info(void)
15636 #ifndef __ASSEMBLY__
15637 DECLARE_PER_CPU(unsigned long, kernel_stack);
15638
15639-static inline struct thread_info *current_thread_info(void)
15640-{
15641- struct thread_info *ti;
15642- ti = (void *)(this_cpu_read_stable(kernel_stack) +
15643- KERNEL_STACK_OFFSET - THREAD_SIZE);
15644- return ti;
15645-}
15646-
15647-#else /* !__ASSEMBLY__ */
15648-
15649-/* how to get the thread information struct from ASM */
15650-#define GET_THREAD_INFO(reg) \
15651- movq PER_CPU_VAR(kernel_stack),reg ; \
15652- subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
15653-
15654-/*
15655- * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
15656- * a certain register (to be used in assembler memory operands).
15657- */
15658-#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
15659-
15660+/* how to get the current stack pointer from C */
15661+register unsigned long current_stack_pointer asm("rsp") __used;
15662 #endif
15663
15664 #endif /* !X86_32 */
15665@@ -285,5 +257,12 @@ static inline bool is_ia32_task(void)
15666 extern void arch_task_cache_init(void);
15667 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
15668 extern void arch_release_task_struct(struct task_struct *tsk);
15669+
15670+#define __HAVE_THREAD_FUNCTIONS
15671+#define task_thread_info(task) (&(task)->tinfo)
15672+#define task_stack_page(task) ((task)->stack)
15673+#define setup_thread_stack(p, org) do {} while (0)
15674+#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
15675+
15676 #endif
15677 #endif /* _ASM_X86_THREAD_INFO_H */
15678diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
15679index 5ee2687..70d5895 100644
15680--- a/arch/x86/include/asm/uaccess.h
15681+++ b/arch/x86/include/asm/uaccess.h
15682@@ -7,6 +7,7 @@
15683 #include <linux/compiler.h>
15684 #include <linux/thread_info.h>
15685 #include <linux/string.h>
15686+#include <linux/sched.h>
15687 #include <asm/asm.h>
15688 #include <asm/page.h>
15689 #include <asm/smap.h>
15690@@ -29,7 +30,12 @@
15691
15692 #define get_ds() (KERNEL_DS)
15693 #define get_fs() (current_thread_info()->addr_limit)
15694+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15695+void __set_fs(mm_segment_t x);
15696+void set_fs(mm_segment_t x);
15697+#else
15698 #define set_fs(x) (current_thread_info()->addr_limit = (x))
15699+#endif
15700
15701 #define segment_eq(a, b) ((a).seg == (b).seg)
15702
15703@@ -77,8 +83,33 @@
15704 * checks that the pointer is in the user space range - after calling
15705 * this function, memory access functions may still return -EFAULT.
15706 */
15707-#define access_ok(type, addr, size) \
15708- (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15709+#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
15710+#define access_ok(type, addr, size) \
15711+({ \
15712+ long __size = size; \
15713+ unsigned long __addr = (unsigned long)addr; \
15714+ unsigned long __addr_ao = __addr & PAGE_MASK; \
15715+ unsigned long __end_ao = __addr + __size - 1; \
15716+ bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
15717+ if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
15718+ while(__addr_ao <= __end_ao) { \
15719+ char __c_ao; \
15720+ __addr_ao += PAGE_SIZE; \
15721+ if (__size > PAGE_SIZE) \
15722+ cond_resched(); \
15723+ if (__get_user(__c_ao, (char __user *)__addr)) \
15724+ break; \
15725+ if (type != VERIFY_WRITE) { \
15726+ __addr = __addr_ao; \
15727+ continue; \
15728+ } \
15729+ if (__put_user(__c_ao, (char __user *)__addr)) \
15730+ break; \
15731+ __addr = __addr_ao; \
15732+ } \
15733+ } \
15734+ __ret_ao; \
15735+})
15736
15737 /*
15738 * The exception table consists of pairs of addresses relative to the
15739@@ -176,13 +207,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15740 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
15741 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
15742
15743-
15744+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
15745+#define __copyuser_seg "gs;"
15746+#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
15747+#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
15748+#else
15749+#define __copyuser_seg
15750+#define __COPYUSER_SET_ES
15751+#define __COPYUSER_RESTORE_ES
15752+#endif
15753
15754 #ifdef CONFIG_X86_32
15755 #define __put_user_asm_u64(x, addr, err, errret) \
15756 asm volatile(ASM_STAC "\n" \
15757- "1: movl %%eax,0(%2)\n" \
15758- "2: movl %%edx,4(%2)\n" \
15759+ "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
15760+ "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
15761 "3: " ASM_CLAC "\n" \
15762 ".section .fixup,\"ax\"\n" \
15763 "4: movl %3,%0\n" \
15764@@ -195,8 +234,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
15765
15766 #define __put_user_asm_ex_u64(x, addr) \
15767 asm volatile(ASM_STAC "\n" \
15768- "1: movl %%eax,0(%1)\n" \
15769- "2: movl %%edx,4(%1)\n" \
15770+ "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
15771+ "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
15772 "3: " ASM_CLAC "\n" \
15773 _ASM_EXTABLE_EX(1b, 2b) \
15774 _ASM_EXTABLE_EX(2b, 3b) \
15775@@ -246,7 +285,7 @@ extern void __put_user_8(void);
15776 __typeof__(*(ptr)) __pu_val; \
15777 __chk_user_ptr(ptr); \
15778 might_fault(); \
15779- __pu_val = x; \
15780+ __pu_val = (x); \
15781 switch (sizeof(*(ptr))) { \
15782 case 1: \
15783 __put_user_x(1, __pu_val, ptr, __ret_pu); \
15784@@ -345,7 +384,7 @@ do { \
15785
15786 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15787 asm volatile(ASM_STAC "\n" \
15788- "1: mov"itype" %2,%"rtype"1\n" \
15789+ "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
15790 "2: " ASM_CLAC "\n" \
15791 ".section .fixup,\"ax\"\n" \
15792 "3: mov %3,%0\n" \
15793@@ -353,7 +392,7 @@ do { \
15794 " jmp 2b\n" \
15795 ".previous\n" \
15796 _ASM_EXTABLE(1b, 3b) \
15797- : "=r" (err), ltype(x) \
15798+ : "=r" (err), ltype (x) \
15799 : "m" (__m(addr)), "i" (errret), "0" (err))
15800
15801 #define __get_user_size_ex(x, ptr, size) \
15802@@ -378,7 +417,7 @@ do { \
15803 } while (0)
15804
15805 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
15806- asm volatile("1: mov"itype" %1,%"rtype"0\n" \
15807+ asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
15808 "2:\n" \
15809 _ASM_EXTABLE_EX(1b, 2b) \
15810 : ltype(x) : "m" (__m(addr)))
15811@@ -395,13 +434,24 @@ do { \
15812 int __gu_err; \
15813 unsigned long __gu_val; \
15814 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
15815- (x) = (__force __typeof__(*(ptr)))__gu_val; \
15816+ (x) = (__typeof__(*(ptr)))__gu_val; \
15817 __gu_err; \
15818 })
15819
15820 /* FIXME: this hack is definitely wrong -AK */
15821 struct __large_struct { unsigned long buf[100]; };
15822-#define __m(x) (*(struct __large_struct __user *)(x))
15823+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15824+#define ____m(x) \
15825+({ \
15826+ unsigned long ____x = (unsigned long)(x); \
15827+ if (____x < pax_user_shadow_base) \
15828+ ____x += pax_user_shadow_base; \
15829+ (typeof(x))____x; \
15830+})
15831+#else
15832+#define ____m(x) (x)
15833+#endif
15834+#define __m(x) (*(struct __large_struct __user *)____m(x))
15835
15836 /*
15837 * Tell gcc we read from memory instead of writing: this is because
15838@@ -410,7 +460,7 @@ struct __large_struct { unsigned long buf[100]; };
15839 */
15840 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
15841 asm volatile(ASM_STAC "\n" \
15842- "1: mov"itype" %"rtype"1,%2\n" \
15843+ "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
15844 "2: " ASM_CLAC "\n" \
15845 ".section .fixup,\"ax\"\n" \
15846 "3: mov %3,%0\n" \
15847@@ -418,10 +468,10 @@ struct __large_struct { unsigned long buf[100]; };
15848 ".previous\n" \
15849 _ASM_EXTABLE(1b, 3b) \
15850 : "=r"(err) \
15851- : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
15852+ : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
15853
15854 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
15855- asm volatile("1: mov"itype" %"rtype"0,%1\n" \
15856+ asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
15857 "2:\n" \
15858 _ASM_EXTABLE_EX(1b, 2b) \
15859 : : ltype(x), "m" (__m(addr)))
15860@@ -460,8 +510,12 @@ struct __large_struct { unsigned long buf[100]; };
15861 * On error, the variable @x is set to zero.
15862 */
15863
15864+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15865+#define __get_user(x, ptr) get_user((x), (ptr))
15866+#else
15867 #define __get_user(x, ptr) \
15868 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
15869+#endif
15870
15871 /**
15872 * __put_user: - Write a simple value into user space, with less checking.
15873@@ -483,8 +537,12 @@ struct __large_struct { unsigned long buf[100]; };
15874 * Returns zero on success, or -EFAULT on error.
15875 */
15876
15877+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
15878+#define __put_user(x, ptr) put_user((x), (ptr))
15879+#else
15880 #define __put_user(x, ptr) \
15881 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
15882+#endif
15883
15884 #define __get_user_unaligned __get_user
15885 #define __put_user_unaligned __put_user
15886@@ -502,7 +560,7 @@ struct __large_struct { unsigned long buf[100]; };
15887 #define get_user_ex(x, ptr) do { \
15888 unsigned long __gue_val; \
15889 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
15890- (x) = (__force __typeof__(*(ptr)))__gue_val; \
15891+ (x) = (__typeof__(*(ptr)))__gue_val; \
15892 } while (0)
15893
15894 #define put_user_try uaccess_try
15895@@ -519,8 +577,8 @@ strncpy_from_user(char *dst, const char __user *src, long count);
15896 extern __must_check long strlen_user(const char __user *str);
15897 extern __must_check long strnlen_user(const char __user *str, long n);
15898
15899-unsigned long __must_check clear_user(void __user *mem, unsigned long len);
15900-unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
15901+unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15902+unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
15903
15904 /*
15905 * movsl can be slow when source and dest are not both 8-byte aligned
15906diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
15907index 7f760a9..04b1c65 100644
15908--- a/arch/x86/include/asm/uaccess_32.h
15909+++ b/arch/x86/include/asm/uaccess_32.h
15910@@ -11,15 +11,15 @@
15911 #include <asm/page.h>
15912
15913 unsigned long __must_check __copy_to_user_ll
15914- (void __user *to, const void *from, unsigned long n);
15915+ (void __user *to, const void *from, unsigned long n) __size_overflow(3);
15916 unsigned long __must_check __copy_from_user_ll
15917- (void *to, const void __user *from, unsigned long n);
15918+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15919 unsigned long __must_check __copy_from_user_ll_nozero
15920- (void *to, const void __user *from, unsigned long n);
15921+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15922 unsigned long __must_check __copy_from_user_ll_nocache
15923- (void *to, const void __user *from, unsigned long n);
15924+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15925 unsigned long __must_check __copy_from_user_ll_nocache_nozero
15926- (void *to, const void __user *from, unsigned long n);
15927+ (void *to, const void __user *from, unsigned long n) __size_overflow(3);
15928
15929 /**
15930 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
15931@@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
15932 static __always_inline unsigned long __must_check
15933 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
15934 {
15935+ if ((long)n < 0)
15936+ return n;
15937+
15938+ check_object_size(from, n, true);
15939+
15940 if (__builtin_constant_p(n)) {
15941 unsigned long ret;
15942
15943@@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
15944 __copy_to_user(void __user *to, const void *from, unsigned long n)
15945 {
15946 might_fault();
15947+
15948 return __copy_to_user_inatomic(to, from, n);
15949 }
15950
15951 static __always_inline unsigned long
15952 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
15953 {
15954+ if ((long)n < 0)
15955+ return n;
15956+
15957 /* Avoid zeroing the tail if the copy fails..
15958 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
15959 * but as the zeroing behaviour is only significant when n is not
15960@@ -137,6 +146,12 @@ static __always_inline unsigned long
15961 __copy_from_user(void *to, const void __user *from, unsigned long n)
15962 {
15963 might_fault();
15964+
15965+ if ((long)n < 0)
15966+ return n;
15967+
15968+ check_object_size(to, n, false);
15969+
15970 if (__builtin_constant_p(n)) {
15971 unsigned long ret;
15972
15973@@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
15974 const void __user *from, unsigned long n)
15975 {
15976 might_fault();
15977+
15978+ if ((long)n < 0)
15979+ return n;
15980+
15981 if (__builtin_constant_p(n)) {
15982 unsigned long ret;
15983
15984@@ -181,15 +200,19 @@ static __always_inline unsigned long
15985 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
15986 unsigned long n)
15987 {
15988- return __copy_from_user_ll_nocache_nozero(to, from, n);
15989+ if ((long)n < 0)
15990+ return n;
15991+
15992+ return __copy_from_user_ll_nocache_nozero(to, from, n);
15993 }
15994
15995-unsigned long __must_check copy_to_user(void __user *to,
15996- const void *from, unsigned long n);
15997-unsigned long __must_check _copy_from_user(void *to,
15998- const void __user *from,
15999- unsigned long n);
16000-
16001+extern void copy_to_user_overflow(void)
16002+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16003+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16004+#else
16005+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16006+#endif
16007+;
16008
16009 extern void copy_from_user_overflow(void)
16010 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16011@@ -199,17 +222,60 @@ extern void copy_from_user_overflow(void)
16012 #endif
16013 ;
16014
16015-static inline unsigned long __must_check copy_from_user(void *to,
16016- const void __user *from,
16017- unsigned long n)
16018+/**
16019+ * copy_to_user: - Copy a block of data into user space.
16020+ * @to: Destination address, in user space.
16021+ * @from: Source address, in kernel space.
16022+ * @n: Number of bytes to copy.
16023+ *
16024+ * Context: User context only. This function may sleep.
16025+ *
16026+ * Copy data from kernel space to user space.
16027+ *
16028+ * Returns number of bytes that could not be copied.
16029+ * On success, this will be zero.
16030+ */
16031+static inline unsigned long __must_check
16032+copy_to_user(void __user *to, const void *from, unsigned long n)
16033 {
16034- int sz = __compiletime_object_size(to);
16035+ size_t sz = __compiletime_object_size(from);
16036
16037- if (likely(sz == -1 || sz >= n))
16038- n = _copy_from_user(to, from, n);
16039- else
16040+ if (unlikely(sz != (size_t)-1 && sz < n))
16041+ copy_to_user_overflow();
16042+ else if (access_ok(VERIFY_WRITE, to, n))
16043+ n = __copy_to_user(to, from, n);
16044+ return n;
16045+}
16046+
16047+/**
16048+ * copy_from_user: - Copy a block of data from user space.
16049+ * @to: Destination address, in kernel space.
16050+ * @from: Source address, in user space.
16051+ * @n: Number of bytes to copy.
16052+ *
16053+ * Context: User context only. This function may sleep.
16054+ *
16055+ * Copy data from user space to kernel space.
16056+ *
16057+ * Returns number of bytes that could not be copied.
16058+ * On success, this will be zero.
16059+ *
16060+ * If some data could not be copied, this function will pad the copied
16061+ * data to the requested size using zero bytes.
16062+ */
16063+static inline unsigned long __must_check
16064+copy_from_user(void *to, const void __user *from, unsigned long n)
16065+{
16066+ size_t sz = __compiletime_object_size(to);
16067+
16068+ check_object_size(to, n, false);
16069+
16070+ if (unlikely(sz != (size_t)-1 && sz < n))
16071 copy_from_user_overflow();
16072-
16073+ else if (access_ok(VERIFY_READ, from, n))
16074+ n = __copy_from_user(to, from, n);
16075+ else if ((long)n > 0)
16076+ memset(to, 0, n);
16077 return n;
16078 }
16079
16080diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
16081index 142810c..1f2a0a7 100644
16082--- a/arch/x86/include/asm/uaccess_64.h
16083+++ b/arch/x86/include/asm/uaccess_64.h
16084@@ -10,6 +10,9 @@
16085 #include <asm/alternative.h>
16086 #include <asm/cpufeature.h>
16087 #include <asm/page.h>
16088+#include <asm/pgtable.h>
16089+
16090+#define set_fs(x) (current_thread_info()->addr_limit = (x))
16091
16092 /*
16093 * Copy To/From Userspace
16094@@ -17,13 +20,13 @@
16095
16096 /* Handles exceptions in both to and from, but doesn't do access_ok */
16097 __must_check unsigned long
16098-copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
16099+copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
16100 __must_check unsigned long
16101-copy_user_generic_string(void *to, const void *from, unsigned len);
16102+copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
16103 __must_check unsigned long
16104-copy_user_generic_unrolled(void *to, const void *from, unsigned len);
16105+copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
16106
16107-static __always_inline __must_check unsigned long
16108+static __always_inline __must_check __size_overflow(3) unsigned long
16109 copy_user_generic(void *to, const void *from, unsigned len)
16110 {
16111 unsigned ret;
16112@@ -41,142 +44,204 @@ copy_user_generic(void *to, const void *from, unsigned len)
16113 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
16114 "=d" (len)),
16115 "1" (to), "2" (from), "3" (len)
16116- : "memory", "rcx", "r8", "r9", "r10", "r11");
16117+ : "memory", "rcx", "r8", "r9", "r11");
16118 return ret;
16119 }
16120
16121+static __always_inline __must_check unsigned long
16122+__copy_to_user(void __user *to, const void *from, unsigned long len);
16123+static __always_inline __must_check unsigned long
16124+__copy_from_user(void *to, const void __user *from, unsigned long len);
16125 __must_check unsigned long
16126-_copy_to_user(void __user *to, const void *from, unsigned len);
16127-__must_check unsigned long
16128-_copy_from_user(void *to, const void __user *from, unsigned len);
16129-__must_check unsigned long
16130-copy_in_user(void __user *to, const void __user *from, unsigned len);
16131+copy_in_user(void __user *to, const void __user *from, unsigned long len);
16132+
16133+extern void copy_to_user_overflow(void)
16134+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16135+ __compiletime_error("copy_to_user() buffer size is not provably correct")
16136+#else
16137+ __compiletime_warning("copy_to_user() buffer size is not provably correct")
16138+#endif
16139+;
16140+
16141+extern void copy_from_user_overflow(void)
16142+#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
16143+ __compiletime_error("copy_from_user() buffer size is not provably correct")
16144+#else
16145+ __compiletime_warning("copy_from_user() buffer size is not provably correct")
16146+#endif
16147+;
16148
16149 static inline unsigned long __must_check copy_from_user(void *to,
16150 const void __user *from,
16151 unsigned long n)
16152 {
16153- int sz = __compiletime_object_size(to);
16154-
16155 might_fault();
16156- if (likely(sz == -1 || sz >= n))
16157- n = _copy_from_user(to, from, n);
16158-#ifdef CONFIG_DEBUG_VM
16159- else
16160- WARN(1, "Buffer overflow detected!\n");
16161-#endif
16162+
16163+ check_object_size(to, n, false);
16164+
16165+ if (access_ok(VERIFY_READ, from, n))
16166+ n = __copy_from_user(to, from, n);
16167+ else if (n < INT_MAX)
16168+ memset(to, 0, n);
16169 return n;
16170 }
16171
16172 static __always_inline __must_check
16173-int copy_to_user(void __user *dst, const void *src, unsigned size)
16174+int copy_to_user(void __user *dst, const void *src, unsigned long size)
16175 {
16176 might_fault();
16177
16178- return _copy_to_user(dst, src, size);
16179+ if (access_ok(VERIFY_WRITE, dst, size))
16180+ size = __copy_to_user(dst, src, size);
16181+ return size;
16182 }
16183
16184 static __always_inline __must_check
16185-int __copy_from_user(void *dst, const void __user *src, unsigned size)
16186+unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
16187 {
16188- int ret = 0;
16189+ size_t sz = __compiletime_object_size(dst);
16190+ unsigned ret = 0;
16191
16192 might_fault();
16193+
16194+ if (size > INT_MAX)
16195+ return size;
16196+
16197+ check_object_size(dst, size, false);
16198+
16199+#ifdef CONFIG_PAX_MEMORY_UDEREF
16200+ if (!__access_ok(VERIFY_READ, src, size))
16201+ return size;
16202+#endif
16203+
16204+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16205+ copy_from_user_overflow();
16206+ return size;
16207+ }
16208+
16209 if (!__builtin_constant_p(size))
16210- return copy_user_generic(dst, (__force void *)src, size);
16211+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16212 switch (size) {
16213- case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
16214+ case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
16215 ret, "b", "b", "=q", 1);
16216 return ret;
16217- case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
16218+ case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
16219 ret, "w", "w", "=r", 2);
16220 return ret;
16221- case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
16222+ case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
16223 ret, "l", "k", "=r", 4);
16224 return ret;
16225- case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
16226+ case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16227 ret, "q", "", "=r", 8);
16228 return ret;
16229 case 10:
16230- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16231+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16232 ret, "q", "", "=r", 10);
16233 if (unlikely(ret))
16234 return ret;
16235 __get_user_asm(*(u16 *)(8 + (char *)dst),
16236- (u16 __user *)(8 + (char __user *)src),
16237+ (const u16 __user *)(8 + (const char __user *)src),
16238 ret, "w", "w", "=r", 2);
16239 return ret;
16240 case 16:
16241- __get_user_asm(*(u64 *)dst, (u64 __user *)src,
16242+ __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
16243 ret, "q", "", "=r", 16);
16244 if (unlikely(ret))
16245 return ret;
16246 __get_user_asm(*(u64 *)(8 + (char *)dst),
16247- (u64 __user *)(8 + (char __user *)src),
16248+ (const u64 __user *)(8 + (const char __user *)src),
16249 ret, "q", "", "=r", 8);
16250 return ret;
16251 default:
16252- return copy_user_generic(dst, (__force void *)src, size);
16253+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16254 }
16255 }
16256
16257 static __always_inline __must_check
16258-int __copy_to_user(void __user *dst, const void *src, unsigned size)
16259+unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
16260 {
16261- int ret = 0;
16262+ size_t sz = __compiletime_object_size(src);
16263+ unsigned ret = 0;
16264
16265 might_fault();
16266+
16267+ if (size > INT_MAX)
16268+ return size;
16269+
16270+ check_object_size(src, size, true);
16271+
16272+#ifdef CONFIG_PAX_MEMORY_UDEREF
16273+ if (!__access_ok(VERIFY_WRITE, dst, size))
16274+ return size;
16275+#endif
16276+
16277+ if (unlikely(sz != (size_t)-1 && sz < size)) {
16278+ copy_to_user_overflow();
16279+ return size;
16280+ }
16281+
16282 if (!__builtin_constant_p(size))
16283- return copy_user_generic((__force void *)dst, src, size);
16284+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16285 switch (size) {
16286- case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
16287+ case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
16288 ret, "b", "b", "iq", 1);
16289 return ret;
16290- case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
16291+ case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
16292 ret, "w", "w", "ir", 2);
16293 return ret;
16294- case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
16295+ case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
16296 ret, "l", "k", "ir", 4);
16297 return ret;
16298- case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
16299+ case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16300 ret, "q", "", "er", 8);
16301 return ret;
16302 case 10:
16303- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16304+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16305 ret, "q", "", "er", 10);
16306 if (unlikely(ret))
16307 return ret;
16308 asm("":::"memory");
16309- __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
16310+ __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
16311 ret, "w", "w", "ir", 2);
16312 return ret;
16313 case 16:
16314- __put_user_asm(*(u64 *)src, (u64 __user *)dst,
16315+ __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
16316 ret, "q", "", "er", 16);
16317 if (unlikely(ret))
16318 return ret;
16319 asm("":::"memory");
16320- __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
16321+ __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
16322 ret, "q", "", "er", 8);
16323 return ret;
16324 default:
16325- return copy_user_generic((__force void *)dst, src, size);
16326+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16327 }
16328 }
16329
16330 static __always_inline __must_check
16331-int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16332+unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
16333 {
16334- int ret = 0;
16335+ unsigned ret = 0;
16336
16337 might_fault();
16338+
16339+ if (size > INT_MAX)
16340+ return size;
16341+
16342+#ifdef CONFIG_PAX_MEMORY_UDEREF
16343+ if (!__access_ok(VERIFY_READ, src, size))
16344+ return size;
16345+ if (!__access_ok(VERIFY_WRITE, dst, size))
16346+ return size;
16347+#endif
16348+
16349 if (!__builtin_constant_p(size))
16350- return copy_user_generic((__force void *)dst,
16351- (__force void *)src, size);
16352+ return copy_user_generic((__force_kernel void *)____m(dst),
16353+ (__force_kernel const void *)____m(src), size);
16354 switch (size) {
16355 case 1: {
16356 u8 tmp;
16357- __get_user_asm(tmp, (u8 __user *)src,
16358+ __get_user_asm(tmp, (const u8 __user *)src,
16359 ret, "b", "b", "=q", 1);
16360 if (likely(!ret))
16361 __put_user_asm(tmp, (u8 __user *)dst,
16362@@ -185,7 +250,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16363 }
16364 case 2: {
16365 u16 tmp;
16366- __get_user_asm(tmp, (u16 __user *)src,
16367+ __get_user_asm(tmp, (const u16 __user *)src,
16368 ret, "w", "w", "=r", 2);
16369 if (likely(!ret))
16370 __put_user_asm(tmp, (u16 __user *)dst,
16371@@ -195,7 +260,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16372
16373 case 4: {
16374 u32 tmp;
16375- __get_user_asm(tmp, (u32 __user *)src,
16376+ __get_user_asm(tmp, (const u32 __user *)src,
16377 ret, "l", "k", "=r", 4);
16378 if (likely(!ret))
16379 __put_user_asm(tmp, (u32 __user *)dst,
16380@@ -204,7 +269,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16381 }
16382 case 8: {
16383 u64 tmp;
16384- __get_user_asm(tmp, (u64 __user *)src,
16385+ __get_user_asm(tmp, (const u64 __user *)src,
16386 ret, "q", "", "=r", 8);
16387 if (likely(!ret))
16388 __put_user_asm(tmp, (u64 __user *)dst,
16389@@ -212,41 +277,72 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
16390 return ret;
16391 }
16392 default:
16393- return copy_user_generic((__force void *)dst,
16394- (__force void *)src, size);
16395+ return copy_user_generic((__force_kernel void *)____m(dst),
16396+ (__force_kernel const void *)____m(src), size);
16397 }
16398 }
16399
16400 static __must_check __always_inline int
16401-__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
16402+__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
16403 {
16404- return copy_user_generic(dst, (__force const void *)src, size);
16405+ if (size > INT_MAX)
16406+ return size;
16407+
16408+#ifdef CONFIG_PAX_MEMORY_UDEREF
16409+ if (!__access_ok(VERIFY_READ, src, size))
16410+ return size;
16411+#endif
16412+
16413+ return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
16414 }
16415
16416-static __must_check __always_inline int
16417-__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
16418+static __must_check __always_inline unsigned long
16419+__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
16420 {
16421- return copy_user_generic((__force void *)dst, src, size);
16422+ if (size > INT_MAX)
16423+ return size;
16424+
16425+#ifdef CONFIG_PAX_MEMORY_UDEREF
16426+ if (!__access_ok(VERIFY_WRITE, dst, size))
16427+ return size;
16428+#endif
16429+
16430+ return copy_user_generic((__force_kernel void *)____m(dst), src, size);
16431 }
16432
16433-extern long __copy_user_nocache(void *dst, const void __user *src,
16434- unsigned size, int zerorest);
16435+extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
16436+ unsigned long size, int zerorest) __size_overflow(3);
16437
16438-static inline int
16439-__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
16440+static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
16441 {
16442 might_sleep();
16443+
16444+ if (size > INT_MAX)
16445+ return size;
16446+
16447+#ifdef CONFIG_PAX_MEMORY_UDEREF
16448+ if (!__access_ok(VERIFY_READ, src, size))
16449+ return size;
16450+#endif
16451+
16452 return __copy_user_nocache(dst, src, size, 1);
16453 }
16454
16455-static inline int
16456-__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16457- unsigned size)
16458+static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
16459+ unsigned long size)
16460 {
16461+ if (size > INT_MAX)
16462+ return size;
16463+
16464+#ifdef CONFIG_PAX_MEMORY_UDEREF
16465+ if (!__access_ok(VERIFY_READ, src, size))
16466+ return size;
16467+#endif
16468+
16469 return __copy_user_nocache(dst, src, size, 0);
16470 }
16471
16472-unsigned long
16473-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
16474+extern unsigned long
16475+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
16476
16477 #endif /* _ASM_X86_UACCESS_64_H */
16478diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
16479index 5b238981..77fdd78 100644
16480--- a/arch/x86/include/asm/word-at-a-time.h
16481+++ b/arch/x86/include/asm/word-at-a-time.h
16482@@ -11,7 +11,7 @@
16483 * and shift, for example.
16484 */
16485 struct word_at_a_time {
16486- const unsigned long one_bits, high_bits;
16487+ unsigned long one_bits, high_bits;
16488 };
16489
16490 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
16491diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
16492index d8d9922..bf6cecb 100644
16493--- a/arch/x86/include/asm/x86_init.h
16494+++ b/arch/x86/include/asm/x86_init.h
16495@@ -129,7 +129,7 @@ struct x86_init_ops {
16496 struct x86_init_timers timers;
16497 struct x86_init_iommu iommu;
16498 struct x86_init_pci pci;
16499-};
16500+} __no_const;
16501
16502 /**
16503 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
16504@@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
16505 void (*setup_percpu_clockev)(void);
16506 void (*early_percpu_clock_init)(void);
16507 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
16508-};
16509+} __no_const;
16510
16511 /**
16512 * struct x86_platform_ops - platform specific runtime functions
16513@@ -166,7 +166,7 @@ struct x86_platform_ops {
16514 void (*save_sched_clock_state)(void);
16515 void (*restore_sched_clock_state)(void);
16516 void (*apic_post_init)(void);
16517-};
16518+} __no_const;
16519
16520 struct pci_dev;
16521 struct msi_msg;
16522@@ -180,7 +180,7 @@ struct x86_msi_ops {
16523 void (*teardown_msi_irqs)(struct pci_dev *dev);
16524 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
16525 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
16526-};
16527+} __no_const;
16528
16529 struct IO_APIC_route_entry;
16530 struct io_apic_irq_attr;
16531@@ -201,7 +201,7 @@ struct x86_io_apic_ops {
16532 unsigned int destination, int vector,
16533 struct io_apic_irq_attr *attr);
16534 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
16535-};
16536+} __no_const;
16537
16538 extern struct x86_init_ops x86_init;
16539 extern struct x86_cpuinit_ops x86_cpuinit;
16540diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
16541index 0415cda..b43d877 100644
16542--- a/arch/x86/include/asm/xsave.h
16543+++ b/arch/x86/include/asm/xsave.h
16544@@ -71,7 +71,9 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16545 return -EFAULT;
16546
16547 __asm__ __volatile__(ASM_STAC "\n"
16548- "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
16549+ "1:"
16550+ __copyuser_seg
16551+ ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
16552 "2: " ASM_CLAC "\n"
16553 ".section .fixup,\"ax\"\n"
16554 "3: movl $-1,%[err]\n"
16555@@ -87,12 +89,14 @@ static inline int xsave_user(struct xsave_struct __user *buf)
16556 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
16557 {
16558 int err;
16559- struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
16560+ struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
16561 u32 lmask = mask;
16562 u32 hmask = mask >> 32;
16563
16564 __asm__ __volatile__(ASM_STAC "\n"
16565- "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16566+ "1:"
16567+ __copyuser_seg
16568+ ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
16569 "2: " ASM_CLAC "\n"
16570 ".section .fixup,\"ax\"\n"
16571 "3: movl $-1,%[err]\n"
16572diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
16573index bbae024..e1528f9 100644
16574--- a/arch/x86/include/uapi/asm/e820.h
16575+++ b/arch/x86/include/uapi/asm/e820.h
16576@@ -63,7 +63,7 @@ struct e820map {
16577 #define ISA_START_ADDRESS 0xa0000
16578 #define ISA_END_ADDRESS 0x100000
16579
16580-#define BIOS_BEGIN 0x000a0000
16581+#define BIOS_BEGIN 0x000c0000
16582 #define BIOS_END 0x00100000
16583
16584 #define BIOS_ROM_BASE 0xffe00000
16585diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
16586index 7bd3bd3..5dac791 100644
16587--- a/arch/x86/kernel/Makefile
16588+++ b/arch/x86/kernel/Makefile
16589@@ -22,7 +22,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
16590 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
16591 obj-$(CONFIG_IRQ_WORK) += irq_work.o
16592 obj-y += probe_roms.o
16593-obj-$(CONFIG_X86_32) += i386_ksyms_32.o
16594+obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
16595 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
16596 obj-y += syscall_$(BITS).o
16597 obj-$(CONFIG_X86_64) += vsyscall_64.o
16598diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
16599index 230c8ea..f915130 100644
16600--- a/arch/x86/kernel/acpi/boot.c
16601+++ b/arch/x86/kernel/acpi/boot.c
16602@@ -1361,7 +1361,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
16603 * If your system is blacklisted here, but you find that acpi=force
16604 * works for you, please contact linux-acpi@vger.kernel.org
16605 */
16606-static struct dmi_system_id __initdata acpi_dmi_table[] = {
16607+static const struct dmi_system_id __initconst acpi_dmi_table[] = {
16608 /*
16609 * Boxes that need ACPI disabled
16610 */
16611@@ -1436,7 +1436,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
16612 };
16613
16614 /* second table for DMI checks that should run after early-quirks */
16615-static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
16616+static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
16617 /*
16618 * HP laptops which use a DSDT reporting as HP/SB400/10000,
16619 * which includes some code which overrides all temperature
16620diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
16621index 0532f5d..36afc0a 100644
16622--- a/arch/x86/kernel/acpi/sleep.c
16623+++ b/arch/x86/kernel/acpi/sleep.c
16624@@ -74,8 +74,12 @@ int acpi_suspend_lowlevel(void)
16625 #else /* CONFIG_64BIT */
16626 #ifdef CONFIG_SMP
16627 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
16628+
16629+ pax_open_kernel();
16630 early_gdt_descr.address =
16631 (unsigned long)get_cpu_gdt_table(smp_processor_id());
16632+ pax_close_kernel();
16633+
16634 initial_gs = per_cpu_offset(smp_processor_id());
16635 #endif
16636 initial_code = (unsigned long)wakeup_long64;
16637diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
16638index 13ab720..95d5442 100644
16639--- a/arch/x86/kernel/acpi/wakeup_32.S
16640+++ b/arch/x86/kernel/acpi/wakeup_32.S
16641@@ -30,13 +30,11 @@ wakeup_pmode_return:
16642 # and restore the stack ... but you need gdt for this to work
16643 movl saved_context_esp, %esp
16644
16645- movl %cs:saved_magic, %eax
16646- cmpl $0x12345678, %eax
16647+ cmpl $0x12345678, saved_magic
16648 jne bogus_magic
16649
16650 # jump to place where we left off
16651- movl saved_eip, %eax
16652- jmp *%eax
16653+ jmp *(saved_eip)
16654
16655 bogus_magic:
16656 jmp bogus_magic
16657diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
16658index ef5ccca..bd83949 100644
16659--- a/arch/x86/kernel/alternative.c
16660+++ b/arch/x86/kernel/alternative.c
16661@@ -268,6 +268,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
16662 */
16663 for (a = start; a < end; a++) {
16664 instr = (u8 *)&a->instr_offset + a->instr_offset;
16665+
16666+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16667+ instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16668+ if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
16669+ instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16670+#endif
16671+
16672 replacement = (u8 *)&a->repl_offset + a->repl_offset;
16673 BUG_ON(a->replacementlen > a->instrlen);
16674 BUG_ON(a->instrlen > sizeof(insnbuf));
16675@@ -299,10 +306,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
16676 for (poff = start; poff < end; poff++) {
16677 u8 *ptr = (u8 *)poff + *poff;
16678
16679+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16680+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16681+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16682+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16683+#endif
16684+
16685 if (!*poff || ptr < text || ptr >= text_end)
16686 continue;
16687 /* turn DS segment override prefix into lock prefix */
16688- if (*ptr == 0x3e)
16689+ if (*ktla_ktva(ptr) == 0x3e)
16690 text_poke(ptr, ((unsigned char []){0xf0}), 1);
16691 }
16692 mutex_unlock(&text_mutex);
16693@@ -317,10 +330,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
16694 for (poff = start; poff < end; poff++) {
16695 u8 *ptr = (u8 *)poff + *poff;
16696
16697+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
16698+ ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16699+ if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
16700+ ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
16701+#endif
16702+
16703 if (!*poff || ptr < text || ptr >= text_end)
16704 continue;
16705 /* turn lock prefix into DS segment override prefix */
16706- if (*ptr == 0xf0)
16707+ if (*ktla_ktva(ptr) == 0xf0)
16708 text_poke(ptr, ((unsigned char []){0x3E}), 1);
16709 }
16710 mutex_unlock(&text_mutex);
16711@@ -468,7 +487,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
16712
16713 BUG_ON(p->len > MAX_PATCH_LEN);
16714 /* prep the buffer with the original instructions */
16715- memcpy(insnbuf, p->instr, p->len);
16716+ memcpy(insnbuf, ktla_ktva(p->instr), p->len);
16717 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
16718 (unsigned long)p->instr, p->len);
16719
16720@@ -515,7 +534,7 @@ void __init alternative_instructions(void)
16721 if (!uniproc_patched || num_possible_cpus() == 1)
16722 free_init_pages("SMP alternatives",
16723 (unsigned long)__smp_locks,
16724- (unsigned long)__smp_locks_end);
16725+ PAGE_ALIGN((unsigned long)__smp_locks_end));
16726 #endif
16727
16728 apply_paravirt(__parainstructions, __parainstructions_end);
16729@@ -535,13 +554,17 @@ void __init alternative_instructions(void)
16730 * instructions. And on the local CPU you need to be protected again NMI or MCE
16731 * handlers seeing an inconsistent instruction while you patch.
16732 */
16733-void *__init_or_module text_poke_early(void *addr, const void *opcode,
16734+void *__kprobes text_poke_early(void *addr, const void *opcode,
16735 size_t len)
16736 {
16737 unsigned long flags;
16738 local_irq_save(flags);
16739- memcpy(addr, opcode, len);
16740+
16741+ pax_open_kernel();
16742+ memcpy(ktla_ktva(addr), opcode, len);
16743 sync_core();
16744+ pax_close_kernel();
16745+
16746 local_irq_restore(flags);
16747 /* Could also do a CLFLUSH here to speed up CPU recovery; but
16748 that causes hangs on some VIA CPUs. */
16749@@ -563,36 +586,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
16750 */
16751 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
16752 {
16753- unsigned long flags;
16754- char *vaddr;
16755+ unsigned char *vaddr = ktla_ktva(addr);
16756 struct page *pages[2];
16757- int i;
16758+ size_t i;
16759
16760 if (!core_kernel_text((unsigned long)addr)) {
16761- pages[0] = vmalloc_to_page(addr);
16762- pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
16763+ pages[0] = vmalloc_to_page(vaddr);
16764+ pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
16765 } else {
16766- pages[0] = virt_to_page(addr);
16767+ pages[0] = virt_to_page(vaddr);
16768 WARN_ON(!PageReserved(pages[0]));
16769- pages[1] = virt_to_page(addr + PAGE_SIZE);
16770+ pages[1] = virt_to_page(vaddr + PAGE_SIZE);
16771 }
16772 BUG_ON(!pages[0]);
16773- local_irq_save(flags);
16774- set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
16775- if (pages[1])
16776- set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
16777- vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
16778- memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
16779- clear_fixmap(FIX_TEXT_POKE0);
16780- if (pages[1])
16781- clear_fixmap(FIX_TEXT_POKE1);
16782- local_flush_tlb();
16783- sync_core();
16784- /* Could also do a CLFLUSH here to speed up CPU recovery; but
16785- that causes hangs on some VIA CPUs. */
16786+ text_poke_early(addr, opcode, len);
16787 for (i = 0; i < len; i++)
16788- BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
16789- local_irq_restore(flags);
16790+ BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
16791 return addr;
16792 }
16793
16794diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
16795index 904611b..004dde6 100644
16796--- a/arch/x86/kernel/apic/apic.c
16797+++ b/arch/x86/kernel/apic/apic.c
16798@@ -189,7 +189,7 @@ int first_system_vector = 0xfe;
16799 /*
16800 * Debug level, exported for io_apic.c
16801 */
16802-unsigned int apic_verbosity;
16803+int apic_verbosity;
16804
16805 int pic_mode;
16806
16807@@ -1955,7 +1955,7 @@ void smp_error_interrupt(struct pt_regs *regs)
16808 apic_write(APIC_ESR, 0);
16809 v1 = apic_read(APIC_ESR);
16810 ack_APIC_irq();
16811- atomic_inc(&irq_err_count);
16812+ atomic_inc_unchecked(&irq_err_count);
16813
16814 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
16815 smp_processor_id(), v0 , v1);
16816diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
16817index 00c77cf..2dc6a2d 100644
16818--- a/arch/x86/kernel/apic/apic_flat_64.c
16819+++ b/arch/x86/kernel/apic/apic_flat_64.c
16820@@ -157,7 +157,7 @@ static int flat_probe(void)
16821 return 1;
16822 }
16823
16824-static struct apic apic_flat = {
16825+static struct apic apic_flat __read_only = {
16826 .name = "flat",
16827 .probe = flat_probe,
16828 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
16829@@ -271,7 +271,7 @@ static int physflat_probe(void)
16830 return 0;
16831 }
16832
16833-static struct apic apic_physflat = {
16834+static struct apic apic_physflat __read_only = {
16835
16836 .name = "physical flat",
16837 .probe = physflat_probe,
16838diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
16839index e145f28..2752888 100644
16840--- a/arch/x86/kernel/apic/apic_noop.c
16841+++ b/arch/x86/kernel/apic/apic_noop.c
16842@@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
16843 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
16844 }
16845
16846-struct apic apic_noop = {
16847+struct apic apic_noop __read_only = {
16848 .name = "noop",
16849 .probe = noop_probe,
16850 .acpi_madt_oem_check = NULL,
16851diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
16852index d50e364..543bee3 100644
16853--- a/arch/x86/kernel/apic/bigsmp_32.c
16854+++ b/arch/x86/kernel/apic/bigsmp_32.c
16855@@ -152,7 +152,7 @@ static int probe_bigsmp(void)
16856 return dmi_bigsmp;
16857 }
16858
16859-static struct apic apic_bigsmp = {
16860+static struct apic apic_bigsmp __read_only = {
16861
16862 .name = "bigsmp",
16863 .probe = probe_bigsmp,
16864diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
16865index 0874799..a7a7892 100644
16866--- a/arch/x86/kernel/apic/es7000_32.c
16867+++ b/arch/x86/kernel/apic/es7000_32.c
16868@@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
16869 return ret && es7000_apic_is_cluster();
16870 }
16871
16872-/* We've been warned by a false positive warning.Use __refdata to keep calm. */
16873-static struct apic __refdata apic_es7000_cluster = {
16874+static struct apic apic_es7000_cluster __read_only = {
16875
16876 .name = "es7000",
16877 .probe = probe_es7000,
16878@@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
16879 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
16880 };
16881
16882-static struct apic __refdata apic_es7000 = {
16883+static struct apic apic_es7000 __read_only = {
16884
16885 .name = "es7000",
16886 .probe = probe_es7000,
16887diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
16888index 9ed796c..e930fe4 100644
16889--- a/arch/x86/kernel/apic/io_apic.c
16890+++ b/arch/x86/kernel/apic/io_apic.c
16891@@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
16892 }
16893 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
16894
16895-void lock_vector_lock(void)
16896+void lock_vector_lock(void) __acquires(vector_lock)
16897 {
16898 /* Used to the online set of cpus does not change
16899 * during assign_irq_vector.
16900@@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
16901 raw_spin_lock(&vector_lock);
16902 }
16903
16904-void unlock_vector_lock(void)
16905+void unlock_vector_lock(void) __releases(vector_lock)
16906 {
16907 raw_spin_unlock(&vector_lock);
16908 }
16909@@ -2362,7 +2362,7 @@ static void ack_apic_edge(struct irq_data *data)
16910 ack_APIC_irq();
16911 }
16912
16913-atomic_t irq_mis_count;
16914+atomic_unchecked_t irq_mis_count;
16915
16916 #ifdef CONFIG_GENERIC_PENDING_IRQ
16917 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
16918@@ -2503,7 +2503,7 @@ static void ack_apic_level(struct irq_data *data)
16919 * at the cpu.
16920 */
16921 if (!(v & (1 << (i & 0x1f)))) {
16922- atomic_inc(&irq_mis_count);
16923+ atomic_inc_unchecked(&irq_mis_count);
16924
16925 eoi_ioapic_irq(irq, cfg);
16926 }
16927diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
16928index d661ee9..791fd33 100644
16929--- a/arch/x86/kernel/apic/numaq_32.c
16930+++ b/arch/x86/kernel/apic/numaq_32.c
16931@@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
16932 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
16933 }
16934
16935-/* Use __refdata to keep false positive warning calm. */
16936-static struct apic __refdata apic_numaq = {
16937+static struct apic apic_numaq __read_only = {
16938
16939 .name = "NUMAQ",
16940 .probe = probe_numaq,
16941diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
16942index eb35ef9..f184a21 100644
16943--- a/arch/x86/kernel/apic/probe_32.c
16944+++ b/arch/x86/kernel/apic/probe_32.c
16945@@ -72,7 +72,7 @@ static int probe_default(void)
16946 return 1;
16947 }
16948
16949-static struct apic apic_default = {
16950+static struct apic apic_default __read_only = {
16951
16952 .name = "default",
16953 .probe = probe_default,
16954diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
16955index 77c95c0..434f8a4 100644
16956--- a/arch/x86/kernel/apic/summit_32.c
16957+++ b/arch/x86/kernel/apic/summit_32.c
16958@@ -486,7 +486,7 @@ void setup_summit(void)
16959 }
16960 #endif
16961
16962-static struct apic apic_summit = {
16963+static struct apic apic_summit __read_only = {
16964
16965 .name = "summit",
16966 .probe = probe_summit,
16967diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
16968index c88baa4..757aee1 100644
16969--- a/arch/x86/kernel/apic/x2apic_cluster.c
16970+++ b/arch/x86/kernel/apic/x2apic_cluster.c
16971@@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
16972 return notifier_from_errno(err);
16973 }
16974
16975-static struct notifier_block __refdata x2apic_cpu_notifier = {
16976+static struct notifier_block x2apic_cpu_notifier = {
16977 .notifier_call = update_clusterinfo,
16978 };
16979
16980@@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
16981 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
16982 }
16983
16984-static struct apic apic_x2apic_cluster = {
16985+static struct apic apic_x2apic_cluster __read_only = {
16986
16987 .name = "cluster x2apic",
16988 .probe = x2apic_cluster_probe,
16989diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
16990index 562a76d..a003c0f 100644
16991--- a/arch/x86/kernel/apic/x2apic_phys.c
16992+++ b/arch/x86/kernel/apic/x2apic_phys.c
16993@@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
16994 return apic == &apic_x2apic_phys;
16995 }
16996
16997-static struct apic apic_x2apic_phys = {
16998+static struct apic apic_x2apic_phys __read_only = {
16999
17000 .name = "physical x2apic",
17001 .probe = x2apic_phys_probe,
17002diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
17003index 794f6eb..67e1db2 100644
17004--- a/arch/x86/kernel/apic/x2apic_uv_x.c
17005+++ b/arch/x86/kernel/apic/x2apic_uv_x.c
17006@@ -342,7 +342,7 @@ static int uv_probe(void)
17007 return apic == &apic_x2apic_uv_x;
17008 }
17009
17010-static struct apic __refdata apic_x2apic_uv_x = {
17011+static struct apic apic_x2apic_uv_x __read_only = {
17012
17013 .name = "UV large system",
17014 .probe = uv_probe,
17015diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
17016index 66b5faf..3442423 100644
17017--- a/arch/x86/kernel/apm_32.c
17018+++ b/arch/x86/kernel/apm_32.c
17019@@ -434,7 +434,7 @@ static DEFINE_MUTEX(apm_mutex);
17020 * This is for buggy BIOS's that refer to (real mode) segment 0x40
17021 * even though they are called in protected mode.
17022 */
17023-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
17024+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
17025 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
17026
17027 static const char driver_version[] = "1.16ac"; /* no spaces */
17028@@ -612,7 +612,10 @@ static long __apm_bios_call(void *_call)
17029 BUG_ON(cpu != 0);
17030 gdt = get_cpu_gdt_table(cpu);
17031 save_desc_40 = gdt[0x40 / 8];
17032+
17033+ pax_open_kernel();
17034 gdt[0x40 / 8] = bad_bios_desc;
17035+ pax_close_kernel();
17036
17037 apm_irq_save(flags);
17038 APM_DO_SAVE_SEGS;
17039@@ -621,7 +624,11 @@ static long __apm_bios_call(void *_call)
17040 &call->esi);
17041 APM_DO_RESTORE_SEGS;
17042 apm_irq_restore(flags);
17043+
17044+ pax_open_kernel();
17045 gdt[0x40 / 8] = save_desc_40;
17046+ pax_close_kernel();
17047+
17048 put_cpu();
17049
17050 return call->eax & 0xff;
17051@@ -688,7 +695,10 @@ static long __apm_bios_call_simple(void *_call)
17052 BUG_ON(cpu != 0);
17053 gdt = get_cpu_gdt_table(cpu);
17054 save_desc_40 = gdt[0x40 / 8];
17055+
17056+ pax_open_kernel();
17057 gdt[0x40 / 8] = bad_bios_desc;
17058+ pax_close_kernel();
17059
17060 apm_irq_save(flags);
17061 APM_DO_SAVE_SEGS;
17062@@ -696,7 +706,11 @@ static long __apm_bios_call_simple(void *_call)
17063 &call->eax);
17064 APM_DO_RESTORE_SEGS;
17065 apm_irq_restore(flags);
17066+
17067+ pax_open_kernel();
17068 gdt[0x40 / 8] = save_desc_40;
17069+ pax_close_kernel();
17070+
17071 put_cpu();
17072 return error;
17073 }
17074@@ -2363,12 +2377,15 @@ static int __init apm_init(void)
17075 * code to that CPU.
17076 */
17077 gdt = get_cpu_gdt_table(0);
17078+
17079+ pax_open_kernel();
17080 set_desc_base(&gdt[APM_CS >> 3],
17081 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
17082 set_desc_base(&gdt[APM_CS_16 >> 3],
17083 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
17084 set_desc_base(&gdt[APM_DS >> 3],
17085 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
17086+ pax_close_kernel();
17087
17088 proc_create("apm", 0, NULL, &apm_file_ops);
17089
17090diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
17091index 2861082..6d4718e 100644
17092--- a/arch/x86/kernel/asm-offsets.c
17093+++ b/arch/x86/kernel/asm-offsets.c
17094@@ -33,6 +33,8 @@ void common(void) {
17095 OFFSET(TI_status, thread_info, status);
17096 OFFSET(TI_addr_limit, thread_info, addr_limit);
17097 OFFSET(TI_preempt_count, thread_info, preempt_count);
17098+ OFFSET(TI_lowest_stack, thread_info, lowest_stack);
17099+ DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
17100
17101 BLANK();
17102 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
17103@@ -53,8 +55,26 @@ void common(void) {
17104 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
17105 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
17106 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
17107+
17108+#ifdef CONFIG_PAX_KERNEXEC
17109+ OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
17110 #endif
17111
17112+#ifdef CONFIG_PAX_MEMORY_UDEREF
17113+ OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
17114+ OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
17115+#ifdef CONFIG_X86_64
17116+ OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
17117+#endif
17118+#endif
17119+
17120+#endif
17121+
17122+ BLANK();
17123+ DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
17124+ DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
17125+ DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
17126+
17127 #ifdef CONFIG_XEN
17128 BLANK();
17129 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
17130diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
17131index 1b4754f..fbb4227 100644
17132--- a/arch/x86/kernel/asm-offsets_64.c
17133+++ b/arch/x86/kernel/asm-offsets_64.c
17134@@ -76,6 +76,7 @@ int main(void)
17135 BLANK();
17136 #undef ENTRY
17137
17138+ DEFINE(TSS_size, sizeof(struct tss_struct));
17139 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
17140 BLANK();
17141
17142diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
17143index a0e067d..9c7db16 100644
17144--- a/arch/x86/kernel/cpu/Makefile
17145+++ b/arch/x86/kernel/cpu/Makefile
17146@@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
17147 CFLAGS_REMOVE_perf_event.o = -pg
17148 endif
17149
17150-# Make sure load_percpu_segment has no stackprotector
17151-nostackp := $(call cc-option, -fno-stack-protector)
17152-CFLAGS_common.o := $(nostackp)
17153-
17154 obj-y := intel_cacheinfo.o scattered.o topology.o
17155 obj-y += proc.o capflags.o powerflags.o common.o
17156 obj-y += vmware.o hypervisor.o mshyperv.o
17157diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
17158index fa96eb0..03efe73 100644
17159--- a/arch/x86/kernel/cpu/amd.c
17160+++ b/arch/x86/kernel/cpu/amd.c
17161@@ -737,7 +737,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
17162 unsigned int size)
17163 {
17164 /* AMD errata T13 (order #21922) */
17165- if ((c->x86 == 6)) {
17166+ if (c->x86 == 6) {
17167 /* Duron Rev A0 */
17168 if (c->x86_model == 3 && c->x86_mask == 0)
17169 size = 64;
17170diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
17171index d814772..c615653 100644
17172--- a/arch/x86/kernel/cpu/common.c
17173+++ b/arch/x86/kernel/cpu/common.c
17174@@ -88,60 +88,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
17175
17176 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
17177
17178-DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
17179-#ifdef CONFIG_X86_64
17180- /*
17181- * We need valid kernel segments for data and code in long mode too
17182- * IRET will check the segment types kkeil 2000/10/28
17183- * Also sysret mandates a special GDT layout
17184- *
17185- * TLS descriptors are currently at a different place compared to i386.
17186- * Hopefully nobody expects them at a fixed place (Wine?)
17187- */
17188- [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
17189- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
17190- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
17191- [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
17192- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
17193- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
17194-#else
17195- [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
17196- [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17197- [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
17198- [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
17199- /*
17200- * Segments used for calling PnP BIOS have byte granularity.
17201- * They code segments and data segments have fixed 64k limits,
17202- * the transfer segment sizes are set at run time.
17203- */
17204- /* 32-bit code */
17205- [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17206- /* 16-bit code */
17207- [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17208- /* 16-bit data */
17209- [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
17210- /* 16-bit data */
17211- [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
17212- /* 16-bit data */
17213- [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
17214- /*
17215- * The APM segments have byte granularity and their bases
17216- * are set at run time. All have 64k limits.
17217- */
17218- /* 32-bit code */
17219- [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
17220- /* 16-bit code */
17221- [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
17222- /* data */
17223- [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
17224-
17225- [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17226- [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
17227- GDT_STACK_CANARY_INIT
17228-#endif
17229-} };
17230-EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
17231-
17232 static int __init x86_xsave_setup(char *s)
17233 {
17234 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
17235@@ -386,7 +332,7 @@ void switch_to_new_gdt(int cpu)
17236 {
17237 struct desc_ptr gdt_descr;
17238
17239- gdt_descr.address = (long)get_cpu_gdt_table(cpu);
17240+ gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
17241 gdt_descr.size = GDT_SIZE - 1;
17242 load_gdt(&gdt_descr);
17243 /* Reload the per-cpu base */
17244@@ -882,6 +828,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
17245 /* Filter out anything that depends on CPUID levels we don't have */
17246 filter_cpuid_features(c, true);
17247
17248+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
17249+ setup_clear_cpu_cap(X86_FEATURE_SEP);
17250+#endif
17251+
17252 /* If the model name is still unset, do table lookup. */
17253 if (!c->x86_model_id[0]) {
17254 const char *p;
17255@@ -1065,10 +1015,12 @@ static __init int setup_disablecpuid(char *arg)
17256 }
17257 __setup("clearcpuid=", setup_disablecpuid);
17258
17259+DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
17260+EXPORT_PER_CPU_SYMBOL(current_tinfo);
17261+
17262 #ifdef CONFIG_X86_64
17263 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
17264-struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
17265- (unsigned long) nmi_idt_table };
17266+struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
17267
17268 DEFINE_PER_CPU_FIRST(union irq_stack_union,
17269 irq_stack_union) __aligned(PAGE_SIZE);
17270@@ -1082,7 +1034,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
17271 EXPORT_PER_CPU_SYMBOL(current_task);
17272
17273 DEFINE_PER_CPU(unsigned long, kernel_stack) =
17274- (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
17275+ (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
17276 EXPORT_PER_CPU_SYMBOL(kernel_stack);
17277
17278 DEFINE_PER_CPU(char *, irq_stack_ptr) =
17279@@ -1227,7 +1179,7 @@ void __cpuinit cpu_init(void)
17280 load_ucode_ap();
17281
17282 cpu = stack_smp_processor_id();
17283- t = &per_cpu(init_tss, cpu);
17284+ t = init_tss + cpu;
17285 oist = &per_cpu(orig_ist, cpu);
17286
17287 #ifdef CONFIG_NUMA
17288@@ -1253,7 +1205,7 @@ void __cpuinit cpu_init(void)
17289 switch_to_new_gdt(cpu);
17290 loadsegment(fs, 0);
17291
17292- load_idt((const struct desc_ptr *)&idt_descr);
17293+ load_idt(&idt_descr);
17294
17295 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
17296 syscall_init();
17297@@ -1262,7 +1214,6 @@ void __cpuinit cpu_init(void)
17298 wrmsrl(MSR_KERNEL_GS_BASE, 0);
17299 barrier();
17300
17301- x86_configure_nx();
17302 enable_x2apic();
17303
17304 /*
17305@@ -1314,7 +1265,7 @@ void __cpuinit cpu_init(void)
17306 {
17307 int cpu = smp_processor_id();
17308 struct task_struct *curr = current;
17309- struct tss_struct *t = &per_cpu(init_tss, cpu);
17310+ struct tss_struct *t = init_tss + cpu;
17311 struct thread_struct *thread = &curr->thread;
17312
17313 show_ucode_info_early();
17314diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
17315index 1905ce9..a7ac587 100644
17316--- a/arch/x86/kernel/cpu/intel.c
17317+++ b/arch/x86/kernel/cpu/intel.c
17318@@ -173,7 +173,7 @@ static void __cpuinit trap_init_f00f_bug(void)
17319 * Update the IDT descriptor and reload the IDT so that
17320 * it uses the read-only mapped virtual address.
17321 */
17322- idt_descr.address = fix_to_virt(FIX_F00F_IDT);
17323+ idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
17324 load_idt(&idt_descr);
17325 }
17326 #endif
17327diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
17328index 7c6f7d5..8cac382 100644
17329--- a/arch/x86/kernel/cpu/intel_cacheinfo.c
17330+++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
17331@@ -1017,6 +1017,22 @@ static struct attribute *default_attrs[] = {
17332 };
17333
17334 #ifdef CONFIG_AMD_NB
17335+static struct attribute *default_attrs_amd_nb[] = {
17336+ &type.attr,
17337+ &level.attr,
17338+ &coherency_line_size.attr,
17339+ &physical_line_partition.attr,
17340+ &ways_of_associativity.attr,
17341+ &number_of_sets.attr,
17342+ &size.attr,
17343+ &shared_cpu_map.attr,
17344+ &shared_cpu_list.attr,
17345+ NULL,
17346+ NULL,
17347+ NULL,
17348+ NULL
17349+};
17350+
17351 static struct attribute ** __cpuinit amd_l3_attrs(void)
17352 {
17353 static struct attribute **attrs;
17354@@ -1027,18 +1043,7 @@ static struct attribute ** __cpuinit amd_l3_attrs(void)
17355
17356 n = ARRAY_SIZE(default_attrs);
17357
17358- if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
17359- n += 2;
17360-
17361- if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
17362- n += 1;
17363-
17364- attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
17365- if (attrs == NULL)
17366- return attrs = default_attrs;
17367-
17368- for (n = 0; default_attrs[n]; n++)
17369- attrs[n] = default_attrs[n];
17370+ attrs = default_attrs_amd_nb;
17371
17372 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
17373 attrs[n++] = &cache_disable_0.attr;
17374@@ -1089,6 +1094,13 @@ static struct kobj_type ktype_cache = {
17375 .default_attrs = default_attrs,
17376 };
17377
17378+#ifdef CONFIG_AMD_NB
17379+static struct kobj_type ktype_cache_amd_nb = {
17380+ .sysfs_ops = &sysfs_ops,
17381+ .default_attrs = default_attrs_amd_nb,
17382+};
17383+#endif
17384+
17385 static struct kobj_type ktype_percpu_entry = {
17386 .sysfs_ops = &sysfs_ops,
17387 };
17388@@ -1154,20 +1166,26 @@ static int __cpuinit cache_add_dev(struct device *dev)
17389 return retval;
17390 }
17391
17392+#ifdef CONFIG_AMD_NB
17393+ amd_l3_attrs();
17394+#endif
17395+
17396 for (i = 0; i < num_cache_leaves; i++) {
17397+ struct kobj_type *ktype;
17398+
17399 this_object = INDEX_KOBJECT_PTR(cpu, i);
17400 this_object->cpu = cpu;
17401 this_object->index = i;
17402
17403 this_leaf = CPUID4_INFO_IDX(cpu, i);
17404
17405- ktype_cache.default_attrs = default_attrs;
17406+ ktype = &ktype_cache;
17407 #ifdef CONFIG_AMD_NB
17408 if (this_leaf->base.nb)
17409- ktype_cache.default_attrs = amd_l3_attrs();
17410+ ktype = &ktype_cache_amd_nb;
17411 #endif
17412 retval = kobject_init_and_add(&(this_object->kobj),
17413- &ktype_cache,
17414+ ktype,
17415 per_cpu(ici_cache_kobject, cpu),
17416 "index%1lu", i);
17417 if (unlikely(retval)) {
17418@@ -1222,7 +1240,7 @@ static int __cpuinit cacheinfo_cpu_callback(struct notifier_block *nfb,
17419 return NOTIFY_OK;
17420 }
17421
17422-static struct notifier_block __cpuinitdata cacheinfo_cpu_notifier = {
17423+static struct notifier_block cacheinfo_cpu_notifier = {
17424 .notifier_call = cacheinfo_cpu_callback,
17425 };
17426
17427diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
17428index 7bc1263..bff5686 100644
17429--- a/arch/x86/kernel/cpu/mcheck/mce.c
17430+++ b/arch/x86/kernel/cpu/mcheck/mce.c
17431@@ -45,6 +45,7 @@
17432 #include <asm/processor.h>
17433 #include <asm/mce.h>
17434 #include <asm/msr.h>
17435+#include <asm/local.h>
17436
17437 #include "mce-internal.h"
17438
17439@@ -246,7 +247,7 @@ static void print_mce(struct mce *m)
17440 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
17441 m->cs, m->ip);
17442
17443- if (m->cs == __KERNEL_CS)
17444+ if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
17445 print_symbol("{%s}", m->ip);
17446 pr_cont("\n");
17447 }
17448@@ -279,10 +280,10 @@ static void print_mce(struct mce *m)
17449
17450 #define PANIC_TIMEOUT 5 /* 5 seconds */
17451
17452-static atomic_t mce_paniced;
17453+static atomic_unchecked_t mce_paniced;
17454
17455 static int fake_panic;
17456-static atomic_t mce_fake_paniced;
17457+static atomic_unchecked_t mce_fake_paniced;
17458
17459 /* Panic in progress. Enable interrupts and wait for final IPI */
17460 static void wait_for_panic(void)
17461@@ -306,7 +307,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17462 /*
17463 * Make sure only one CPU runs in machine check panic
17464 */
17465- if (atomic_inc_return(&mce_paniced) > 1)
17466+ if (atomic_inc_return_unchecked(&mce_paniced) > 1)
17467 wait_for_panic();
17468 barrier();
17469
17470@@ -314,7 +315,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17471 console_verbose();
17472 } else {
17473 /* Don't log too much for fake panic */
17474- if (atomic_inc_return(&mce_fake_paniced) > 1)
17475+ if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
17476 return;
17477 }
17478 /* First print corrected ones that are still unlogged */
17479@@ -353,7 +354,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
17480 if (!fake_panic) {
17481 if (panic_timeout == 0)
17482 panic_timeout = mca_cfg.panic_timeout;
17483- panic(msg);
17484+ panic("%s", msg);
17485 } else
17486 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
17487 }
17488@@ -683,7 +684,7 @@ static int mce_timed_out(u64 *t)
17489 * might have been modified by someone else.
17490 */
17491 rmb();
17492- if (atomic_read(&mce_paniced))
17493+ if (atomic_read_unchecked(&mce_paniced))
17494 wait_for_panic();
17495 if (!mca_cfg.monarch_timeout)
17496 goto out;
17497@@ -1654,7 +1655,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
17498 }
17499
17500 /* Call the installed machine check handler for this CPU setup. */
17501-void (*machine_check_vector)(struct pt_regs *, long error_code) =
17502+void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
17503 unexpected_machine_check;
17504
17505 /*
17506@@ -1677,7 +1678,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17507 return;
17508 }
17509
17510+ pax_open_kernel();
17511 machine_check_vector = do_machine_check;
17512+ pax_close_kernel();
17513
17514 __mcheck_cpu_init_generic();
17515 __mcheck_cpu_init_vendor(c);
17516@@ -1691,7 +1694,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
17517 */
17518
17519 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
17520-static int mce_chrdev_open_count; /* #times opened */
17521+static local_t mce_chrdev_open_count; /* #times opened */
17522 static int mce_chrdev_open_exclu; /* already open exclusive? */
17523
17524 static int mce_chrdev_open(struct inode *inode, struct file *file)
17525@@ -1699,7 +1702,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17526 spin_lock(&mce_chrdev_state_lock);
17527
17528 if (mce_chrdev_open_exclu ||
17529- (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
17530+ (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
17531 spin_unlock(&mce_chrdev_state_lock);
17532
17533 return -EBUSY;
17534@@ -1707,7 +1710,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
17535
17536 if (file->f_flags & O_EXCL)
17537 mce_chrdev_open_exclu = 1;
17538- mce_chrdev_open_count++;
17539+ local_inc(&mce_chrdev_open_count);
17540
17541 spin_unlock(&mce_chrdev_state_lock);
17542
17543@@ -1718,7 +1721,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
17544 {
17545 spin_lock(&mce_chrdev_state_lock);
17546
17547- mce_chrdev_open_count--;
17548+ local_dec(&mce_chrdev_open_count);
17549 mce_chrdev_open_exclu = 0;
17550
17551 spin_unlock(&mce_chrdev_state_lock);
17552@@ -2364,7 +2367,7 @@ mce_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
17553 return NOTIFY_OK;
17554 }
17555
17556-static struct notifier_block mce_cpu_notifier __cpuinitdata = {
17557+static struct notifier_block mce_cpu_notifier = {
17558 .notifier_call = mce_cpu_callback,
17559 };
17560
17561@@ -2374,7 +2377,7 @@ static __init void mce_init_banks(void)
17562
17563 for (i = 0; i < mca_cfg.banks; i++) {
17564 struct mce_bank *b = &mce_banks[i];
17565- struct device_attribute *a = &b->attr;
17566+ device_attribute_no_const *a = &b->attr;
17567
17568 sysfs_attr_init(&a->attr);
17569 a->attr.name = b->attrname;
17570@@ -2442,7 +2445,7 @@ struct dentry *mce_get_debugfs_dir(void)
17571 static void mce_reset(void)
17572 {
17573 cpu_missing = 0;
17574- atomic_set(&mce_fake_paniced, 0);
17575+ atomic_set_unchecked(&mce_fake_paniced, 0);
17576 atomic_set(&mce_executing, 0);
17577 atomic_set(&mce_callin, 0);
17578 atomic_set(&global_nwo, 0);
17579diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
17580index 1c044b1..37a2a43 100644
17581--- a/arch/x86/kernel/cpu/mcheck/p5.c
17582+++ b/arch/x86/kernel/cpu/mcheck/p5.c
17583@@ -11,6 +11,7 @@
17584 #include <asm/processor.h>
17585 #include <asm/mce.h>
17586 #include <asm/msr.h>
17587+#include <asm/pgtable.h>
17588
17589 /* By default disabled */
17590 int mce_p5_enabled __read_mostly;
17591@@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
17592 if (!cpu_has(c, X86_FEATURE_MCE))
17593 return;
17594
17595+ pax_open_kernel();
17596 machine_check_vector = pentium_machine_check;
17597+ pax_close_kernel();
17598 /* Make sure the vector pointer is visible before we enable MCEs: */
17599 wmb();
17600
17601diff --git a/arch/x86/kernel/cpu/mcheck/therm_throt.c b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17602index 47a1870..8c019a7 100644
17603--- a/arch/x86/kernel/cpu/mcheck/therm_throt.c
17604+++ b/arch/x86/kernel/cpu/mcheck/therm_throt.c
17605@@ -288,7 +288,7 @@ thermal_throttle_cpu_callback(struct notifier_block *nfb,
17606 return notifier_from_errno(err);
17607 }
17608
17609-static struct notifier_block thermal_throttle_cpu_notifier __cpuinitdata =
17610+static struct notifier_block thermal_throttle_cpu_notifier =
17611 {
17612 .notifier_call = thermal_throttle_cpu_callback,
17613 };
17614diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
17615index e9a701a..35317d6 100644
17616--- a/arch/x86/kernel/cpu/mcheck/winchip.c
17617+++ b/arch/x86/kernel/cpu/mcheck/winchip.c
17618@@ -10,6 +10,7 @@
17619 #include <asm/processor.h>
17620 #include <asm/mce.h>
17621 #include <asm/msr.h>
17622+#include <asm/pgtable.h>
17623
17624 /* Machine check handler for WinChip C6: */
17625 static void winchip_machine_check(struct pt_regs *regs, long error_code)
17626@@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
17627 {
17628 u32 lo, hi;
17629
17630+ pax_open_kernel();
17631 machine_check_vector = winchip_machine_check;
17632+ pax_close_kernel();
17633 /* Make sure the vector pointer is visible before we enable MCEs: */
17634 wmb();
17635
17636diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
17637index 726bf96..81f0526 100644
17638--- a/arch/x86/kernel/cpu/mtrr/main.c
17639+++ b/arch/x86/kernel/cpu/mtrr/main.c
17640@@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
17641 u64 size_or_mask, size_and_mask;
17642 static bool mtrr_aps_delayed_init;
17643
17644-static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
17645+static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
17646
17647 const struct mtrr_ops *mtrr_if;
17648
17649diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
17650index df5e41f..816c719 100644
17651--- a/arch/x86/kernel/cpu/mtrr/mtrr.h
17652+++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
17653@@ -25,7 +25,7 @@ struct mtrr_ops {
17654 int (*validate_add_page)(unsigned long base, unsigned long size,
17655 unsigned int type);
17656 int (*have_wrcomb)(void);
17657-};
17658+} __do_const;
17659
17660 extern int generic_get_free_region(unsigned long base, unsigned long size,
17661 int replace_reg);
17662diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
17663index bf0f01a..9adfee1 100644
17664--- a/arch/x86/kernel/cpu/perf_event.c
17665+++ b/arch/x86/kernel/cpu/perf_event.c
17666@@ -1305,7 +1305,7 @@ static void __init pmu_check_apic(void)
17667 pr_info("no hardware sampling interrupt available.\n");
17668 }
17669
17670-static struct attribute_group x86_pmu_format_group = {
17671+static attribute_group_no_const x86_pmu_format_group = {
17672 .name = "format",
17673 .attrs = NULL,
17674 };
17675@@ -1374,7 +1374,7 @@ static struct attribute *events_attr[] = {
17676 NULL,
17677 };
17678
17679-static struct attribute_group x86_pmu_events_group = {
17680+static attribute_group_no_const x86_pmu_events_group = {
17681 .name = "events",
17682 .attrs = events_attr,
17683 };
17684@@ -1873,7 +1873,7 @@ static unsigned long get_segment_base(unsigned int segment)
17685 if (idx > GDT_ENTRIES)
17686 return 0;
17687
17688- desc = __this_cpu_ptr(&gdt_page.gdt[0]);
17689+ desc = get_cpu_gdt_table(smp_processor_id());
17690 }
17691
17692 return get_desc_base(desc + idx);
17693@@ -1963,7 +1963,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
17694 break;
17695
17696 perf_callchain_store(entry, frame.return_address);
17697- fp = frame.next_frame;
17698+ fp = (const void __force_user *)frame.next_frame;
17699 }
17700 }
17701
17702diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
17703index 4a0a462..be3b204 100644
17704--- a/arch/x86/kernel/cpu/perf_event_intel.c
17705+++ b/arch/x86/kernel/cpu/perf_event_intel.c
17706@@ -1994,10 +1994,10 @@ __init int intel_pmu_init(void)
17707 * v2 and above have a perf capabilities MSR
17708 */
17709 if (version > 1) {
17710- u64 capabilities;
17711+ u64 capabilities = x86_pmu.intel_cap.capabilities;
17712
17713- rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
17714- x86_pmu.intel_cap.capabilities = capabilities;
17715+ if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
17716+ x86_pmu.intel_cap.capabilities = capabilities;
17717 }
17718
17719 intel_ds_init();
17720diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17721index 3e091f0..d2dc8d6 100644
17722--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17723+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
17724@@ -2428,7 +2428,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
17725 static int __init uncore_type_init(struct intel_uncore_type *type)
17726 {
17727 struct intel_uncore_pmu *pmus;
17728- struct attribute_group *attr_group;
17729+ attribute_group_no_const *attr_group;
17730 struct attribute **attrs;
17731 int i, j;
17732
17733@@ -2826,7 +2826,7 @@ static int
17734 return NOTIFY_OK;
17735 }
17736
17737-static struct notifier_block uncore_cpu_nb __cpuinitdata = {
17738+static struct notifier_block uncore_cpu_nb = {
17739 .notifier_call = uncore_cpu_notifier,
17740 /*
17741 * to migrate uncore events, our notifier should be executed
17742diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17743index e68a455..975a932 100644
17744--- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17745+++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
17746@@ -428,7 +428,7 @@ struct intel_uncore_box {
17747 struct uncore_event_desc {
17748 struct kobj_attribute attr;
17749 const char *config;
17750-};
17751+} __do_const;
17752
17753 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
17754 { \
17755diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
17756index 1e4dbcf..b9a34c2 100644
17757--- a/arch/x86/kernel/cpuid.c
17758+++ b/arch/x86/kernel/cpuid.c
17759@@ -171,7 +171,7 @@ static int __cpuinit cpuid_class_cpu_callback(struct notifier_block *nfb,
17760 return notifier_from_errno(err);
17761 }
17762
17763-static struct notifier_block __refdata cpuid_class_cpu_notifier =
17764+static struct notifier_block cpuid_class_cpu_notifier =
17765 {
17766 .notifier_call = cpuid_class_cpu_callback,
17767 };
17768diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
17769index 74467fe..18793d5 100644
17770--- a/arch/x86/kernel/crash.c
17771+++ b/arch/x86/kernel/crash.c
17772@@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
17773 {
17774 #ifdef CONFIG_X86_32
17775 struct pt_regs fixed_regs;
17776-#endif
17777
17778-#ifdef CONFIG_X86_32
17779- if (!user_mode_vm(regs)) {
17780+ if (!user_mode(regs)) {
17781 crash_fixup_ss_esp(&fixed_regs, regs);
17782 regs = &fixed_regs;
17783 }
17784diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
17785index afa64ad..dce67dd 100644
17786--- a/arch/x86/kernel/crash_dump_64.c
17787+++ b/arch/x86/kernel/crash_dump_64.c
17788@@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
17789 return -ENOMEM;
17790
17791 if (userbuf) {
17792- if (copy_to_user(buf, vaddr + offset, csize)) {
17793+ if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
17794 iounmap(vaddr);
17795 return -EFAULT;
17796 }
17797diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
17798index 37250fe..bf2ec74 100644
17799--- a/arch/x86/kernel/doublefault_32.c
17800+++ b/arch/x86/kernel/doublefault_32.c
17801@@ -11,7 +11,7 @@
17802
17803 #define DOUBLEFAULT_STACKSIZE (1024)
17804 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
17805-#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
17806+#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
17807
17808 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
17809
17810@@ -21,7 +21,7 @@ static void doublefault_fn(void)
17811 unsigned long gdt, tss;
17812
17813 store_gdt(&gdt_desc);
17814- gdt = gdt_desc.address;
17815+ gdt = (unsigned long)gdt_desc.address;
17816
17817 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
17818
17819@@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
17820 /* 0x2 bit is always set */
17821 .flags = X86_EFLAGS_SF | 0x2,
17822 .sp = STACK_START,
17823- .es = __USER_DS,
17824+ .es = __KERNEL_DS,
17825 .cs = __KERNEL_CS,
17826 .ss = __KERNEL_DS,
17827- .ds = __USER_DS,
17828+ .ds = __KERNEL_DS,
17829 .fs = __KERNEL_PERCPU,
17830
17831 .__cr3 = __pa_nodebug(swapper_pg_dir),
17832diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
17833index c8797d5..c605e53 100644
17834--- a/arch/x86/kernel/dumpstack.c
17835+++ b/arch/x86/kernel/dumpstack.c
17836@@ -2,6 +2,9 @@
17837 * Copyright (C) 1991, 1992 Linus Torvalds
17838 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
17839 */
17840+#ifdef CONFIG_GRKERNSEC_HIDESYM
17841+#define __INCLUDED_BY_HIDESYM 1
17842+#endif
17843 #include <linux/kallsyms.h>
17844 #include <linux/kprobes.h>
17845 #include <linux/uaccess.h>
17846@@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
17847 static void
17848 print_ftrace_graph_addr(unsigned long addr, void *data,
17849 const struct stacktrace_ops *ops,
17850- struct thread_info *tinfo, int *graph)
17851+ struct task_struct *task, int *graph)
17852 {
17853- struct task_struct *task;
17854 unsigned long ret_addr;
17855 int index;
17856
17857 if (addr != (unsigned long)return_to_handler)
17858 return;
17859
17860- task = tinfo->task;
17861 index = task->curr_ret_stack;
17862
17863 if (!task->ret_stack || index < *graph)
17864@@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17865 static inline void
17866 print_ftrace_graph_addr(unsigned long addr, void *data,
17867 const struct stacktrace_ops *ops,
17868- struct thread_info *tinfo, int *graph)
17869+ struct task_struct *task, int *graph)
17870 { }
17871 #endif
17872
17873@@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
17874 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
17875 */
17876
17877-static inline int valid_stack_ptr(struct thread_info *tinfo,
17878- void *p, unsigned int size, void *end)
17879+static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
17880 {
17881- void *t = tinfo;
17882 if (end) {
17883 if (p < end && p >= (end-THREAD_SIZE))
17884 return 1;
17885@@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
17886 }
17887
17888 unsigned long
17889-print_context_stack(struct thread_info *tinfo,
17890+print_context_stack(struct task_struct *task, void *stack_start,
17891 unsigned long *stack, unsigned long bp,
17892 const struct stacktrace_ops *ops, void *data,
17893 unsigned long *end, int *graph)
17894 {
17895 struct stack_frame *frame = (struct stack_frame *)bp;
17896
17897- while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
17898+ while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
17899 unsigned long addr;
17900
17901 addr = *stack;
17902@@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
17903 } else {
17904 ops->address(data, addr, 0);
17905 }
17906- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17907+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17908 }
17909 stack++;
17910 }
17911@@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
17912 EXPORT_SYMBOL_GPL(print_context_stack);
17913
17914 unsigned long
17915-print_context_stack_bp(struct thread_info *tinfo,
17916+print_context_stack_bp(struct task_struct *task, void *stack_start,
17917 unsigned long *stack, unsigned long bp,
17918 const struct stacktrace_ops *ops, void *data,
17919 unsigned long *end, int *graph)
17920@@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17921 struct stack_frame *frame = (struct stack_frame *)bp;
17922 unsigned long *ret_addr = &frame->return_address;
17923
17924- while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
17925+ while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
17926 unsigned long addr = *ret_addr;
17927
17928 if (!__kernel_text_address(addr))
17929@@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
17930 ops->address(data, addr, 1);
17931 frame = frame->next_frame;
17932 ret_addr = &frame->return_address;
17933- print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
17934+ print_ftrace_graph_addr(addr, data, ops, task, graph);
17935 }
17936
17937 return (unsigned long)frame;
17938@@ -189,7 +188,7 @@ void dump_stack(void)
17939
17940 bp = stack_frame(current, NULL);
17941 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
17942- current->pid, current->comm, print_tainted(),
17943+ task_pid_nr(current), current->comm, print_tainted(),
17944 init_utsname()->release,
17945 (int)strcspn(init_utsname()->version, " "),
17946 init_utsname()->version);
17947@@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
17948 }
17949 EXPORT_SYMBOL_GPL(oops_begin);
17950
17951+extern void gr_handle_kernel_exploit(void);
17952+
17953 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17954 {
17955 if (regs && kexec_should_crash(current))
17956@@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
17957 panic("Fatal exception in interrupt");
17958 if (panic_on_oops)
17959 panic("Fatal exception");
17960- do_exit(signr);
17961+
17962+ gr_handle_kernel_exploit();
17963+
17964+ do_group_exit(signr);
17965 }
17966
17967 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17968@@ -274,7 +278,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
17969 print_modules();
17970 show_regs(regs);
17971 #ifdef CONFIG_X86_32
17972- if (user_mode_vm(regs)) {
17973+ if (user_mode(regs)) {
17974 sp = regs->sp;
17975 ss = regs->ss & 0xffff;
17976 } else {
17977@@ -302,7 +306,7 @@ void die(const char *str, struct pt_regs *regs, long err)
17978 unsigned long flags = oops_begin();
17979 int sig = SIGSEGV;
17980
17981- if (!user_mode_vm(regs))
17982+ if (!user_mode(regs))
17983 report_bug(regs->ip, regs);
17984
17985 if (__die(str, regs, err))
17986diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
17987index 1038a41..db2c12b 100644
17988--- a/arch/x86/kernel/dumpstack_32.c
17989+++ b/arch/x86/kernel/dumpstack_32.c
17990@@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
17991 bp = stack_frame(task, regs);
17992
17993 for (;;) {
17994- struct thread_info *context;
17995+ void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
17996
17997- context = (struct thread_info *)
17998- ((unsigned long)stack & (~(THREAD_SIZE - 1)));
17999- bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
18000+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18001
18002- stack = (unsigned long *)context->previous_esp;
18003- if (!stack)
18004+ if (stack_start == task_stack_page(task))
18005 break;
18006+ stack = *(unsigned long **)stack_start;
18007 if (ops->stack(data, "IRQ") < 0)
18008 break;
18009 touch_nmi_watchdog();
18010@@ -86,7 +84,7 @@ void show_regs(struct pt_regs *regs)
18011 {
18012 int i;
18013
18014- __show_regs(regs, !user_mode_vm(regs));
18015+ __show_regs(regs, !user_mode(regs));
18016
18017 pr_emerg("Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
18018 TASK_COMM_LEN, current->comm, task_pid_nr(current),
18019@@ -95,21 +93,22 @@ void show_regs(struct pt_regs *regs)
18020 * When in-kernel, we also print out the stack and code at the
18021 * time of the fault..
18022 */
18023- if (!user_mode_vm(regs)) {
18024+ if (!user_mode(regs)) {
18025 unsigned int code_prologue = code_bytes * 43 / 64;
18026 unsigned int code_len = code_bytes;
18027 unsigned char c;
18028 u8 *ip;
18029+ unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
18030
18031 pr_emerg("Stack:\n");
18032 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
18033
18034 pr_emerg("Code:");
18035
18036- ip = (u8 *)regs->ip - code_prologue;
18037+ ip = (u8 *)regs->ip - code_prologue + cs_base;
18038 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
18039 /* try starting at IP */
18040- ip = (u8 *)regs->ip;
18041+ ip = (u8 *)regs->ip + cs_base;
18042 code_len = code_len - code_prologue + 1;
18043 }
18044 for (i = 0; i < code_len; i++, ip++) {
18045@@ -118,7 +117,7 @@ void show_regs(struct pt_regs *regs)
18046 pr_cont(" Bad EIP value.");
18047 break;
18048 }
18049- if (ip == (u8 *)regs->ip)
18050+ if (ip == (u8 *)regs->ip + cs_base)
18051 pr_cont(" <%02x>", c);
18052 else
18053 pr_cont(" %02x", c);
18054@@ -131,6 +130,7 @@ int is_valid_bugaddr(unsigned long ip)
18055 {
18056 unsigned short ud2;
18057
18058+ ip = ktla_ktva(ip);
18059 if (ip < PAGE_OFFSET)
18060 return 0;
18061 if (probe_kernel_address((unsigned short *)ip, ud2))
18062@@ -138,3 +138,15 @@ int is_valid_bugaddr(unsigned long ip)
18063
18064 return ud2 == 0x0b0f;
18065 }
18066+
18067+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18068+void pax_check_alloca(unsigned long size)
18069+{
18070+ unsigned long sp = (unsigned long)&sp, stack_left;
18071+
18072+ /* all kernel stacks are of the same size */
18073+ stack_left = sp & (THREAD_SIZE - 1);
18074+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18075+}
18076+EXPORT_SYMBOL(pax_check_alloca);
18077+#endif
18078diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
18079index b653675..51cc8c0 100644
18080--- a/arch/x86/kernel/dumpstack_64.c
18081+++ b/arch/x86/kernel/dumpstack_64.c
18082@@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18083 unsigned long *irq_stack_end =
18084 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
18085 unsigned used = 0;
18086- struct thread_info *tinfo;
18087 int graph = 0;
18088 unsigned long dummy;
18089+ void *stack_start;
18090
18091 if (!task)
18092 task = current;
18093@@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18094 * current stack address. If the stacks consist of nested
18095 * exceptions
18096 */
18097- tinfo = task_thread_info(task);
18098 for (;;) {
18099 char *id;
18100 unsigned long *estack_end;
18101+
18102 estack_end = in_exception_stack(cpu, (unsigned long)stack,
18103 &used, &id);
18104
18105@@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18106 if (ops->stack(data, id) < 0)
18107 break;
18108
18109- bp = ops->walk_stack(tinfo, stack, bp, ops,
18110+ bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
18111 data, estack_end, &graph);
18112 ops->stack(data, "<EOE>");
18113 /*
18114@@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18115 * second-to-last pointer (index -2 to end) in the
18116 * exception stack:
18117 */
18118+ if ((u16)estack_end[-1] != __KERNEL_DS)
18119+ goto out;
18120 stack = (unsigned long *) estack_end[-2];
18121 continue;
18122 }
18123@@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18124 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
18125 if (ops->stack(data, "IRQ") < 0)
18126 break;
18127- bp = ops->walk_stack(tinfo, stack, bp,
18128+ bp = ops->walk_stack(task, irq_stack, stack, bp,
18129 ops, data, irq_stack_end, &graph);
18130 /*
18131 * We link to the next stack (which would be
18132@@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
18133 /*
18134 * This handles the process stack:
18135 */
18136- bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
18137+ stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
18138+ bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
18139+out:
18140 put_cpu();
18141 }
18142 EXPORT_SYMBOL(dump_trace);
18143@@ -249,7 +253,7 @@ void show_regs(struct pt_regs *regs)
18144 {
18145 int i;
18146 unsigned long sp;
18147- const int cpu = smp_processor_id();
18148+ const int cpu = raw_smp_processor_id();
18149 struct task_struct *cur = current;
18150
18151 sp = regs->sp;
18152@@ -304,3 +308,50 @@ int is_valid_bugaddr(unsigned long ip)
18153
18154 return ud2 == 0x0b0f;
18155 }
18156+
18157+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18158+void pax_check_alloca(unsigned long size)
18159+{
18160+ unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
18161+ unsigned cpu, used;
18162+ char *id;
18163+
18164+ /* check the process stack first */
18165+ stack_start = (unsigned long)task_stack_page(current);
18166+ stack_end = stack_start + THREAD_SIZE;
18167+ if (likely(stack_start <= sp && sp < stack_end)) {
18168+ unsigned long stack_left = sp & (THREAD_SIZE - 1);
18169+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18170+ return;
18171+ }
18172+
18173+ cpu = get_cpu();
18174+
18175+ /* check the irq stacks */
18176+ stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
18177+ stack_start = stack_end - IRQ_STACK_SIZE;
18178+ if (stack_start <= sp && sp < stack_end) {
18179+ unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
18180+ put_cpu();
18181+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18182+ return;
18183+ }
18184+
18185+ /* check the exception stacks */
18186+ used = 0;
18187+ stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
18188+ stack_start = stack_end - EXCEPTION_STKSZ;
18189+ if (stack_end && stack_start <= sp && sp < stack_end) {
18190+ unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
18191+ put_cpu();
18192+ BUG_ON(stack_left < 256 || size >= stack_left - 256);
18193+ return;
18194+ }
18195+
18196+ put_cpu();
18197+
18198+ /* unknown stack */
18199+ BUG();
18200+}
18201+EXPORT_SYMBOL(pax_check_alloca);
18202+#endif
18203diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
18204index d32abea..74daf4f 100644
18205--- a/arch/x86/kernel/e820.c
18206+++ b/arch/x86/kernel/e820.c
18207@@ -800,8 +800,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
18208
18209 static void early_panic(char *msg)
18210 {
18211- early_printk(msg);
18212- panic(msg);
18213+ early_printk("%s", msg);
18214+ panic("%s", msg);
18215 }
18216
18217 static int userdef __initdata;
18218diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
18219index 9b9f18b..9fcaa04 100644
18220--- a/arch/x86/kernel/early_printk.c
18221+++ b/arch/x86/kernel/early_printk.c
18222@@ -7,6 +7,7 @@
18223 #include <linux/pci_regs.h>
18224 #include <linux/pci_ids.h>
18225 #include <linux/errno.h>
18226+#include <linux/sched.h>
18227 #include <asm/io.h>
18228 #include <asm/processor.h>
18229 #include <asm/fcntl.h>
18230diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
18231index 8f3e2de..934870f 100644
18232--- a/arch/x86/kernel/entry_32.S
18233+++ b/arch/x86/kernel/entry_32.S
18234@@ -177,13 +177,153 @@
18235 /*CFI_REL_OFFSET gs, PT_GS*/
18236 .endm
18237 .macro SET_KERNEL_GS reg
18238+
18239+#ifdef CONFIG_CC_STACKPROTECTOR
18240 movl $(__KERNEL_STACK_CANARY), \reg
18241+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
18242+ movl $(__USER_DS), \reg
18243+#else
18244+ xorl \reg, \reg
18245+#endif
18246+
18247 movl \reg, %gs
18248 .endm
18249
18250 #endif /* CONFIG_X86_32_LAZY_GS */
18251
18252-.macro SAVE_ALL
18253+.macro pax_enter_kernel
18254+#ifdef CONFIG_PAX_KERNEXEC
18255+ call pax_enter_kernel
18256+#endif
18257+.endm
18258+
18259+.macro pax_exit_kernel
18260+#ifdef CONFIG_PAX_KERNEXEC
18261+ call pax_exit_kernel
18262+#endif
18263+.endm
18264+
18265+#ifdef CONFIG_PAX_KERNEXEC
18266+ENTRY(pax_enter_kernel)
18267+#ifdef CONFIG_PARAVIRT
18268+ pushl %eax
18269+ pushl %ecx
18270+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
18271+ mov %eax, %esi
18272+#else
18273+ mov %cr0, %esi
18274+#endif
18275+ bts $16, %esi
18276+ jnc 1f
18277+ mov %cs, %esi
18278+ cmp $__KERNEL_CS, %esi
18279+ jz 3f
18280+ ljmp $__KERNEL_CS, $3f
18281+1: ljmp $__KERNEXEC_KERNEL_CS, $2f
18282+2:
18283+#ifdef CONFIG_PARAVIRT
18284+ mov %esi, %eax
18285+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
18286+#else
18287+ mov %esi, %cr0
18288+#endif
18289+3:
18290+#ifdef CONFIG_PARAVIRT
18291+ popl %ecx
18292+ popl %eax
18293+#endif
18294+ ret
18295+ENDPROC(pax_enter_kernel)
18296+
18297+ENTRY(pax_exit_kernel)
18298+#ifdef CONFIG_PARAVIRT
18299+ pushl %eax
18300+ pushl %ecx
18301+#endif
18302+ mov %cs, %esi
18303+ cmp $__KERNEXEC_KERNEL_CS, %esi
18304+ jnz 2f
18305+#ifdef CONFIG_PARAVIRT
18306+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
18307+ mov %eax, %esi
18308+#else
18309+ mov %cr0, %esi
18310+#endif
18311+ btr $16, %esi
18312+ ljmp $__KERNEL_CS, $1f
18313+1:
18314+#ifdef CONFIG_PARAVIRT
18315+ mov %esi, %eax
18316+ call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
18317+#else
18318+ mov %esi, %cr0
18319+#endif
18320+2:
18321+#ifdef CONFIG_PARAVIRT
18322+ popl %ecx
18323+ popl %eax
18324+#endif
18325+ ret
18326+ENDPROC(pax_exit_kernel)
18327+#endif
18328+
18329+.macro pax_erase_kstack
18330+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18331+ call pax_erase_kstack
18332+#endif
18333+.endm
18334+
18335+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
18336+/*
18337+ * ebp: thread_info
18338+ */
18339+ENTRY(pax_erase_kstack)
18340+ pushl %edi
18341+ pushl %ecx
18342+ pushl %eax
18343+
18344+ mov TI_lowest_stack(%ebp), %edi
18345+ mov $-0xBEEF, %eax
18346+ std
18347+
18348+1: mov %edi, %ecx
18349+ and $THREAD_SIZE_asm - 1, %ecx
18350+ shr $2, %ecx
18351+ repne scasl
18352+ jecxz 2f
18353+
18354+ cmp $2*16, %ecx
18355+ jc 2f
18356+
18357+ mov $2*16, %ecx
18358+ repe scasl
18359+ jecxz 2f
18360+ jne 1b
18361+
18362+2: cld
18363+ mov %esp, %ecx
18364+ sub %edi, %ecx
18365+
18366+ cmp $THREAD_SIZE_asm, %ecx
18367+ jb 3f
18368+ ud2
18369+3:
18370+
18371+ shr $2, %ecx
18372+ rep stosl
18373+
18374+ mov TI_task_thread_sp0(%ebp), %edi
18375+ sub $128, %edi
18376+ mov %edi, TI_lowest_stack(%ebp)
18377+
18378+ popl %eax
18379+ popl %ecx
18380+ popl %edi
18381+ ret
18382+ENDPROC(pax_erase_kstack)
18383+#endif
18384+
18385+.macro __SAVE_ALL _DS
18386 cld
18387 PUSH_GS
18388 pushl_cfi %fs
18389@@ -206,7 +346,7 @@
18390 CFI_REL_OFFSET ecx, 0
18391 pushl_cfi %ebx
18392 CFI_REL_OFFSET ebx, 0
18393- movl $(__USER_DS), %edx
18394+ movl $\_DS, %edx
18395 movl %edx, %ds
18396 movl %edx, %es
18397 movl $(__KERNEL_PERCPU), %edx
18398@@ -214,6 +354,15 @@
18399 SET_KERNEL_GS %edx
18400 .endm
18401
18402+.macro SAVE_ALL
18403+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
18404+ __SAVE_ALL __KERNEL_DS
18405+ pax_enter_kernel
18406+#else
18407+ __SAVE_ALL __USER_DS
18408+#endif
18409+.endm
18410+
18411 .macro RESTORE_INT_REGS
18412 popl_cfi %ebx
18413 CFI_RESTORE ebx
18414@@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
18415 popfl_cfi
18416 jmp syscall_exit
18417 CFI_ENDPROC
18418-END(ret_from_fork)
18419+ENDPROC(ret_from_fork)
18420
18421 ENTRY(ret_from_kernel_thread)
18422 CFI_STARTPROC
18423@@ -344,7 +493,15 @@ ret_from_intr:
18424 andl $SEGMENT_RPL_MASK, %eax
18425 #endif
18426 cmpl $USER_RPL, %eax
18427+
18428+#ifdef CONFIG_PAX_KERNEXEC
18429+ jae resume_userspace
18430+
18431+ pax_exit_kernel
18432+ jmp resume_kernel
18433+#else
18434 jb resume_kernel # not returning to v8086 or userspace
18435+#endif
18436
18437 ENTRY(resume_userspace)
18438 LOCKDEP_SYS_EXIT
18439@@ -356,8 +513,8 @@ ENTRY(resume_userspace)
18440 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
18441 # int/exception return?
18442 jne work_pending
18443- jmp restore_all
18444-END(ret_from_exception)
18445+ jmp restore_all_pax
18446+ENDPROC(ret_from_exception)
18447
18448 #ifdef CONFIG_PREEMPT
18449 ENTRY(resume_kernel)
18450@@ -372,7 +529,7 @@ need_resched:
18451 jz restore_all
18452 call preempt_schedule_irq
18453 jmp need_resched
18454-END(resume_kernel)
18455+ENDPROC(resume_kernel)
18456 #endif
18457 CFI_ENDPROC
18458 /*
18459@@ -406,30 +563,45 @@ sysenter_past_esp:
18460 /*CFI_REL_OFFSET cs, 0*/
18461 /*
18462 * Push current_thread_info()->sysenter_return to the stack.
18463- * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
18464- * pushed above; +8 corresponds to copy_thread's esp0 setting.
18465 */
18466- pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
18467+ pushl_cfi $0
18468 CFI_REL_OFFSET eip, 0
18469
18470 pushl_cfi %eax
18471 SAVE_ALL
18472+ GET_THREAD_INFO(%ebp)
18473+ movl TI_sysenter_return(%ebp),%ebp
18474+ movl %ebp,PT_EIP(%esp)
18475 ENABLE_INTERRUPTS(CLBR_NONE)
18476
18477 /*
18478 * Load the potential sixth argument from user stack.
18479 * Careful about security.
18480 */
18481+ movl PT_OLDESP(%esp),%ebp
18482+
18483+#ifdef CONFIG_PAX_MEMORY_UDEREF
18484+ mov PT_OLDSS(%esp),%ds
18485+1: movl %ds:(%ebp),%ebp
18486+ push %ss
18487+ pop %ds
18488+#else
18489 cmpl $__PAGE_OFFSET-3,%ebp
18490 jae syscall_fault
18491 ASM_STAC
18492 1: movl (%ebp),%ebp
18493 ASM_CLAC
18494+#endif
18495+
18496 movl %ebp,PT_EBP(%esp)
18497 _ASM_EXTABLE(1b,syscall_fault)
18498
18499 GET_THREAD_INFO(%ebp)
18500
18501+#ifdef CONFIG_PAX_RANDKSTACK
18502+ pax_erase_kstack
18503+#endif
18504+
18505 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18506 jnz sysenter_audit
18507 sysenter_do_call:
18508@@ -444,12 +616,24 @@ sysenter_do_call:
18509 testl $_TIF_ALLWORK_MASK, %ecx
18510 jne sysexit_audit
18511 sysenter_exit:
18512+
18513+#ifdef CONFIG_PAX_RANDKSTACK
18514+ pushl_cfi %eax
18515+ movl %esp, %eax
18516+ call pax_randomize_kstack
18517+ popl_cfi %eax
18518+#endif
18519+
18520+ pax_erase_kstack
18521+
18522 /* if something modifies registers it must also disable sysexit */
18523 movl PT_EIP(%esp), %edx
18524 movl PT_OLDESP(%esp), %ecx
18525 xorl %ebp,%ebp
18526 TRACE_IRQS_ON
18527 1: mov PT_FS(%esp), %fs
18528+2: mov PT_DS(%esp), %ds
18529+3: mov PT_ES(%esp), %es
18530 PTGS_TO_GS
18531 ENABLE_INTERRUPTS_SYSEXIT
18532
18533@@ -466,6 +650,9 @@ sysenter_audit:
18534 movl %eax,%edx /* 2nd arg: syscall number */
18535 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
18536 call __audit_syscall_entry
18537+
18538+ pax_erase_kstack
18539+
18540 pushl_cfi %ebx
18541 movl PT_EAX(%esp),%eax /* reload syscall number */
18542 jmp sysenter_do_call
18543@@ -491,10 +678,16 @@ sysexit_audit:
18544
18545 CFI_ENDPROC
18546 .pushsection .fixup,"ax"
18547-2: movl $0,PT_FS(%esp)
18548+4: movl $0,PT_FS(%esp)
18549+ jmp 1b
18550+5: movl $0,PT_DS(%esp)
18551+ jmp 1b
18552+6: movl $0,PT_ES(%esp)
18553 jmp 1b
18554 .popsection
18555- _ASM_EXTABLE(1b,2b)
18556+ _ASM_EXTABLE(1b,4b)
18557+ _ASM_EXTABLE(2b,5b)
18558+ _ASM_EXTABLE(3b,6b)
18559 PTGS_TO_GS_EX
18560 ENDPROC(ia32_sysenter_target)
18561
18562@@ -509,6 +702,11 @@ ENTRY(system_call)
18563 pushl_cfi %eax # save orig_eax
18564 SAVE_ALL
18565 GET_THREAD_INFO(%ebp)
18566+
18567+#ifdef CONFIG_PAX_RANDKSTACK
18568+ pax_erase_kstack
18569+#endif
18570+
18571 # system call tracing in operation / emulation
18572 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
18573 jnz syscall_trace_entry
18574@@ -527,6 +725,15 @@ syscall_exit:
18575 testl $_TIF_ALLWORK_MASK, %ecx # current->work
18576 jne syscall_exit_work
18577
18578+restore_all_pax:
18579+
18580+#ifdef CONFIG_PAX_RANDKSTACK
18581+ movl %esp, %eax
18582+ call pax_randomize_kstack
18583+#endif
18584+
18585+ pax_erase_kstack
18586+
18587 restore_all:
18588 TRACE_IRQS_IRET
18589 restore_all_notrace:
18590@@ -583,14 +790,34 @@ ldt_ss:
18591 * compensating for the offset by changing to the ESPFIX segment with
18592 * a base address that matches for the difference.
18593 */
18594-#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
18595+#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
18596 mov %esp, %edx /* load kernel esp */
18597 mov PT_OLDESP(%esp), %eax /* load userspace esp */
18598 mov %dx, %ax /* eax: new kernel esp */
18599 sub %eax, %edx /* offset (low word is 0) */
18600+#ifdef CONFIG_SMP
18601+ movl PER_CPU_VAR(cpu_number), %ebx
18602+ shll $PAGE_SHIFT_asm, %ebx
18603+ addl $cpu_gdt_table, %ebx
18604+#else
18605+ movl $cpu_gdt_table, %ebx
18606+#endif
18607 shr $16, %edx
18608- mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
18609- mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
18610+
18611+#ifdef CONFIG_PAX_KERNEXEC
18612+ mov %cr0, %esi
18613+ btr $16, %esi
18614+ mov %esi, %cr0
18615+#endif
18616+
18617+ mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
18618+ mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
18619+
18620+#ifdef CONFIG_PAX_KERNEXEC
18621+ bts $16, %esi
18622+ mov %esi, %cr0
18623+#endif
18624+
18625 pushl_cfi $__ESPFIX_SS
18626 pushl_cfi %eax /* new kernel esp */
18627 /* Disable interrupts, but do not irqtrace this section: we
18628@@ -619,20 +846,18 @@ work_resched:
18629 movl TI_flags(%ebp), %ecx
18630 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
18631 # than syscall tracing?
18632- jz restore_all
18633+ jz restore_all_pax
18634 testb $_TIF_NEED_RESCHED, %cl
18635 jnz work_resched
18636
18637 work_notifysig: # deal with pending signals and
18638 # notify-resume requests
18639+ movl %esp, %eax
18640 #ifdef CONFIG_VM86
18641 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
18642- movl %esp, %eax
18643 jne work_notifysig_v86 # returning to kernel-space or
18644 # vm86-space
18645 1:
18646-#else
18647- movl %esp, %eax
18648 #endif
18649 TRACE_IRQS_ON
18650 ENABLE_INTERRUPTS(CLBR_NONE)
18651@@ -653,7 +878,7 @@ work_notifysig_v86:
18652 movl %eax, %esp
18653 jmp 1b
18654 #endif
18655-END(work_pending)
18656+ENDPROC(work_pending)
18657
18658 # perform syscall exit tracing
18659 ALIGN
18660@@ -661,11 +886,14 @@ syscall_trace_entry:
18661 movl $-ENOSYS,PT_EAX(%esp)
18662 movl %esp, %eax
18663 call syscall_trace_enter
18664+
18665+ pax_erase_kstack
18666+
18667 /* What it returned is what we'll actually use. */
18668 cmpl $(NR_syscalls), %eax
18669 jnae syscall_call
18670 jmp syscall_exit
18671-END(syscall_trace_entry)
18672+ENDPROC(syscall_trace_entry)
18673
18674 # perform syscall exit tracing
18675 ALIGN
18676@@ -678,21 +906,25 @@ syscall_exit_work:
18677 movl %esp, %eax
18678 call syscall_trace_leave
18679 jmp resume_userspace
18680-END(syscall_exit_work)
18681+ENDPROC(syscall_exit_work)
18682 CFI_ENDPROC
18683
18684 RING0_INT_FRAME # can't unwind into user space anyway
18685 syscall_fault:
18686+#ifdef CONFIG_PAX_MEMORY_UDEREF
18687+ push %ss
18688+ pop %ds
18689+#endif
18690 ASM_CLAC
18691 GET_THREAD_INFO(%ebp)
18692 movl $-EFAULT,PT_EAX(%esp)
18693 jmp resume_userspace
18694-END(syscall_fault)
18695+ENDPROC(syscall_fault)
18696
18697 syscall_badsys:
18698 movl $-ENOSYS,PT_EAX(%esp)
18699 jmp resume_userspace
18700-END(syscall_badsys)
18701+ENDPROC(syscall_badsys)
18702 CFI_ENDPROC
18703 /*
18704 * End of kprobes section
18705@@ -708,8 +940,15 @@ END(syscall_badsys)
18706 * normal stack and adjusts ESP with the matching offset.
18707 */
18708 /* fixup the stack */
18709- mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
18710- mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
18711+#ifdef CONFIG_SMP
18712+ movl PER_CPU_VAR(cpu_number), %ebx
18713+ shll $PAGE_SHIFT_asm, %ebx
18714+ addl $cpu_gdt_table, %ebx
18715+#else
18716+ movl $cpu_gdt_table, %ebx
18717+#endif
18718+ mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
18719+ mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
18720 shl $16, %eax
18721 addl %esp, %eax /* the adjusted stack pointer */
18722 pushl_cfi $__KERNEL_DS
18723@@ -762,7 +1001,7 @@ vector=vector+1
18724 .endr
18725 2: jmp common_interrupt
18726 .endr
18727-END(irq_entries_start)
18728+ENDPROC(irq_entries_start)
18729
18730 .previous
18731 END(interrupt)
18732@@ -813,7 +1052,7 @@ ENTRY(coprocessor_error)
18733 pushl_cfi $do_coprocessor_error
18734 jmp error_code
18735 CFI_ENDPROC
18736-END(coprocessor_error)
18737+ENDPROC(coprocessor_error)
18738
18739 ENTRY(simd_coprocessor_error)
18740 RING0_INT_FRAME
18741@@ -835,7 +1074,7 @@ ENTRY(simd_coprocessor_error)
18742 #endif
18743 jmp error_code
18744 CFI_ENDPROC
18745-END(simd_coprocessor_error)
18746+ENDPROC(simd_coprocessor_error)
18747
18748 ENTRY(device_not_available)
18749 RING0_INT_FRAME
18750@@ -844,18 +1083,18 @@ ENTRY(device_not_available)
18751 pushl_cfi $do_device_not_available
18752 jmp error_code
18753 CFI_ENDPROC
18754-END(device_not_available)
18755+ENDPROC(device_not_available)
18756
18757 #ifdef CONFIG_PARAVIRT
18758 ENTRY(native_iret)
18759 iret
18760 _ASM_EXTABLE(native_iret, iret_exc)
18761-END(native_iret)
18762+ENDPROC(native_iret)
18763
18764 ENTRY(native_irq_enable_sysexit)
18765 sti
18766 sysexit
18767-END(native_irq_enable_sysexit)
18768+ENDPROC(native_irq_enable_sysexit)
18769 #endif
18770
18771 ENTRY(overflow)
18772@@ -865,7 +1104,7 @@ ENTRY(overflow)
18773 pushl_cfi $do_overflow
18774 jmp error_code
18775 CFI_ENDPROC
18776-END(overflow)
18777+ENDPROC(overflow)
18778
18779 ENTRY(bounds)
18780 RING0_INT_FRAME
18781@@ -874,7 +1113,7 @@ ENTRY(bounds)
18782 pushl_cfi $do_bounds
18783 jmp error_code
18784 CFI_ENDPROC
18785-END(bounds)
18786+ENDPROC(bounds)
18787
18788 ENTRY(invalid_op)
18789 RING0_INT_FRAME
18790@@ -883,7 +1122,7 @@ ENTRY(invalid_op)
18791 pushl_cfi $do_invalid_op
18792 jmp error_code
18793 CFI_ENDPROC
18794-END(invalid_op)
18795+ENDPROC(invalid_op)
18796
18797 ENTRY(coprocessor_segment_overrun)
18798 RING0_INT_FRAME
18799@@ -892,7 +1131,7 @@ ENTRY(coprocessor_segment_overrun)
18800 pushl_cfi $do_coprocessor_segment_overrun
18801 jmp error_code
18802 CFI_ENDPROC
18803-END(coprocessor_segment_overrun)
18804+ENDPROC(coprocessor_segment_overrun)
18805
18806 ENTRY(invalid_TSS)
18807 RING0_EC_FRAME
18808@@ -900,7 +1139,7 @@ ENTRY(invalid_TSS)
18809 pushl_cfi $do_invalid_TSS
18810 jmp error_code
18811 CFI_ENDPROC
18812-END(invalid_TSS)
18813+ENDPROC(invalid_TSS)
18814
18815 ENTRY(segment_not_present)
18816 RING0_EC_FRAME
18817@@ -908,7 +1147,7 @@ ENTRY(segment_not_present)
18818 pushl_cfi $do_segment_not_present
18819 jmp error_code
18820 CFI_ENDPROC
18821-END(segment_not_present)
18822+ENDPROC(segment_not_present)
18823
18824 ENTRY(stack_segment)
18825 RING0_EC_FRAME
18826@@ -916,7 +1155,7 @@ ENTRY(stack_segment)
18827 pushl_cfi $do_stack_segment
18828 jmp error_code
18829 CFI_ENDPROC
18830-END(stack_segment)
18831+ENDPROC(stack_segment)
18832
18833 ENTRY(alignment_check)
18834 RING0_EC_FRAME
18835@@ -924,7 +1163,7 @@ ENTRY(alignment_check)
18836 pushl_cfi $do_alignment_check
18837 jmp error_code
18838 CFI_ENDPROC
18839-END(alignment_check)
18840+ENDPROC(alignment_check)
18841
18842 ENTRY(divide_error)
18843 RING0_INT_FRAME
18844@@ -933,7 +1172,7 @@ ENTRY(divide_error)
18845 pushl_cfi $do_divide_error
18846 jmp error_code
18847 CFI_ENDPROC
18848-END(divide_error)
18849+ENDPROC(divide_error)
18850
18851 #ifdef CONFIG_X86_MCE
18852 ENTRY(machine_check)
18853@@ -943,7 +1182,7 @@ ENTRY(machine_check)
18854 pushl_cfi machine_check_vector
18855 jmp error_code
18856 CFI_ENDPROC
18857-END(machine_check)
18858+ENDPROC(machine_check)
18859 #endif
18860
18861 ENTRY(spurious_interrupt_bug)
18862@@ -953,7 +1192,7 @@ ENTRY(spurious_interrupt_bug)
18863 pushl_cfi $do_spurious_interrupt_bug
18864 jmp error_code
18865 CFI_ENDPROC
18866-END(spurious_interrupt_bug)
18867+ENDPROC(spurious_interrupt_bug)
18868 /*
18869 * End of kprobes section
18870 */
18871@@ -1063,7 +1302,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
18872
18873 ENTRY(mcount)
18874 ret
18875-END(mcount)
18876+ENDPROC(mcount)
18877
18878 ENTRY(ftrace_caller)
18879 cmpl $0, function_trace_stop
18880@@ -1096,7 +1335,7 @@ ftrace_graph_call:
18881 .globl ftrace_stub
18882 ftrace_stub:
18883 ret
18884-END(ftrace_caller)
18885+ENDPROC(ftrace_caller)
18886
18887 ENTRY(ftrace_regs_caller)
18888 pushf /* push flags before compare (in cs location) */
18889@@ -1197,7 +1436,7 @@ trace:
18890 popl %ecx
18891 popl %eax
18892 jmp ftrace_stub
18893-END(mcount)
18894+ENDPROC(mcount)
18895 #endif /* CONFIG_DYNAMIC_FTRACE */
18896 #endif /* CONFIG_FUNCTION_TRACER */
18897
18898@@ -1215,7 +1454,7 @@ ENTRY(ftrace_graph_caller)
18899 popl %ecx
18900 popl %eax
18901 ret
18902-END(ftrace_graph_caller)
18903+ENDPROC(ftrace_graph_caller)
18904
18905 .globl return_to_handler
18906 return_to_handler:
18907@@ -1271,15 +1510,18 @@ error_code:
18908 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
18909 REG_TO_PTGS %ecx
18910 SET_KERNEL_GS %ecx
18911- movl $(__USER_DS), %ecx
18912+ movl $(__KERNEL_DS), %ecx
18913 movl %ecx, %ds
18914 movl %ecx, %es
18915+
18916+ pax_enter_kernel
18917+
18918 TRACE_IRQS_OFF
18919 movl %esp,%eax # pt_regs pointer
18920 call *%edi
18921 jmp ret_from_exception
18922 CFI_ENDPROC
18923-END(page_fault)
18924+ENDPROC(page_fault)
18925
18926 /*
18927 * Debug traps and NMI can happen at the one SYSENTER instruction
18928@@ -1322,7 +1564,7 @@ debug_stack_correct:
18929 call do_debug
18930 jmp ret_from_exception
18931 CFI_ENDPROC
18932-END(debug)
18933+ENDPROC(debug)
18934
18935 /*
18936 * NMI is doubly nasty. It can happen _while_ we're handling
18937@@ -1360,6 +1602,9 @@ nmi_stack_correct:
18938 xorl %edx,%edx # zero error code
18939 movl %esp,%eax # pt_regs pointer
18940 call do_nmi
18941+
18942+ pax_exit_kernel
18943+
18944 jmp restore_all_notrace
18945 CFI_ENDPROC
18946
18947@@ -1396,12 +1641,15 @@ nmi_espfix_stack:
18948 FIXUP_ESPFIX_STACK # %eax == %esp
18949 xorl %edx,%edx # zero error code
18950 call do_nmi
18951+
18952+ pax_exit_kernel
18953+
18954 RESTORE_REGS
18955 lss 12+4(%esp), %esp # back to espfix stack
18956 CFI_ADJUST_CFA_OFFSET -24
18957 jmp irq_return
18958 CFI_ENDPROC
18959-END(nmi)
18960+ENDPROC(nmi)
18961
18962 ENTRY(int3)
18963 RING0_INT_FRAME
18964@@ -1414,14 +1662,14 @@ ENTRY(int3)
18965 call do_int3
18966 jmp ret_from_exception
18967 CFI_ENDPROC
18968-END(int3)
18969+ENDPROC(int3)
18970
18971 ENTRY(general_protection)
18972 RING0_EC_FRAME
18973 pushl_cfi $do_general_protection
18974 jmp error_code
18975 CFI_ENDPROC
18976-END(general_protection)
18977+ENDPROC(general_protection)
18978
18979 #ifdef CONFIG_KVM_GUEST
18980 ENTRY(async_page_fault)
18981@@ -1430,7 +1678,7 @@ ENTRY(async_page_fault)
18982 pushl_cfi $do_async_page_fault
18983 jmp error_code
18984 CFI_ENDPROC
18985-END(async_page_fault)
18986+ENDPROC(async_page_fault)
18987 #endif
18988
18989 /*
18990diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
18991index c1d01e6..7f633850 100644
18992--- a/arch/x86/kernel/entry_64.S
18993+++ b/arch/x86/kernel/entry_64.S
18994@@ -59,6 +59,8 @@
18995 #include <asm/context_tracking.h>
18996 #include <asm/smap.h>
18997 #include <linux/err.h>
18998+#include <asm/pgtable.h>
18999+#include <asm/alternative-asm.h>
19000
19001 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
19002 #include <linux/elf-em.h>
19003@@ -80,8 +82,9 @@
19004 #ifdef CONFIG_DYNAMIC_FTRACE
19005
19006 ENTRY(function_hook)
19007+ pax_force_retaddr
19008 retq
19009-END(function_hook)
19010+ENDPROC(function_hook)
19011
19012 /* skip is set if stack has been adjusted */
19013 .macro ftrace_caller_setup skip=0
19014@@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
19015 #endif
19016
19017 GLOBAL(ftrace_stub)
19018+ pax_force_retaddr
19019 retq
19020-END(ftrace_caller)
19021+ENDPROC(ftrace_caller)
19022
19023 ENTRY(ftrace_regs_caller)
19024 /* Save the current flags before compare (in SS location)*/
19025@@ -191,7 +195,7 @@ ftrace_restore_flags:
19026 popfq
19027 jmp ftrace_stub
19028
19029-END(ftrace_regs_caller)
19030+ENDPROC(ftrace_regs_caller)
19031
19032
19033 #else /* ! CONFIG_DYNAMIC_FTRACE */
19034@@ -212,6 +216,7 @@ ENTRY(function_hook)
19035 #endif
19036
19037 GLOBAL(ftrace_stub)
19038+ pax_force_retaddr
19039 retq
19040
19041 trace:
19042@@ -225,12 +230,13 @@ trace:
19043 #endif
19044 subq $MCOUNT_INSN_SIZE, %rdi
19045
19046+ pax_force_fptr ftrace_trace_function
19047 call *ftrace_trace_function
19048
19049 MCOUNT_RESTORE_FRAME
19050
19051 jmp ftrace_stub
19052-END(function_hook)
19053+ENDPROC(function_hook)
19054 #endif /* CONFIG_DYNAMIC_FTRACE */
19055 #endif /* CONFIG_FUNCTION_TRACER */
19056
19057@@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
19058
19059 MCOUNT_RESTORE_FRAME
19060
19061+ pax_force_retaddr
19062 retq
19063-END(ftrace_graph_caller)
19064+ENDPROC(ftrace_graph_caller)
19065
19066 GLOBAL(return_to_handler)
19067 subq $24, %rsp
19068@@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
19069 movq 8(%rsp), %rdx
19070 movq (%rsp), %rax
19071 addq $24, %rsp
19072+ pax_force_fptr %rdi
19073 jmp *%rdi
19074+ENDPROC(return_to_handler)
19075 #endif
19076
19077
19078@@ -284,6 +293,309 @@ ENTRY(native_usergs_sysret64)
19079 ENDPROC(native_usergs_sysret64)
19080 #endif /* CONFIG_PARAVIRT */
19081
19082+ .macro ljmpq sel, off
19083+#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
19084+ .byte 0x48; ljmp *1234f(%rip)
19085+ .pushsection .rodata
19086+ .align 16
19087+ 1234: .quad \off; .word \sel
19088+ .popsection
19089+#else
19090+ pushq $\sel
19091+ pushq $\off
19092+ lretq
19093+#endif
19094+ .endm
19095+
19096+ .macro pax_enter_kernel
19097+ pax_set_fptr_mask
19098+#ifdef CONFIG_PAX_KERNEXEC
19099+ call pax_enter_kernel
19100+#endif
19101+ .endm
19102+
19103+ .macro pax_exit_kernel
19104+#ifdef CONFIG_PAX_KERNEXEC
19105+ call pax_exit_kernel
19106+#endif
19107+ .endm
19108+
19109+#ifdef CONFIG_PAX_KERNEXEC
19110+ENTRY(pax_enter_kernel)
19111+ pushq %rdi
19112+
19113+#ifdef CONFIG_PARAVIRT
19114+ PV_SAVE_REGS(CLBR_RDI)
19115+#endif
19116+
19117+ GET_CR0_INTO_RDI
19118+ bts $16,%rdi
19119+ jnc 3f
19120+ mov %cs,%edi
19121+ cmp $__KERNEL_CS,%edi
19122+ jnz 2f
19123+1:
19124+
19125+#ifdef CONFIG_PARAVIRT
19126+ PV_RESTORE_REGS(CLBR_RDI)
19127+#endif
19128+
19129+ popq %rdi
19130+ pax_force_retaddr
19131+ retq
19132+
19133+2: ljmpq __KERNEL_CS,1b
19134+3: ljmpq __KERNEXEC_KERNEL_CS,4f
19135+4: SET_RDI_INTO_CR0
19136+ jmp 1b
19137+ENDPROC(pax_enter_kernel)
19138+
19139+ENTRY(pax_exit_kernel)
19140+ pushq %rdi
19141+
19142+#ifdef CONFIG_PARAVIRT
19143+ PV_SAVE_REGS(CLBR_RDI)
19144+#endif
19145+
19146+ mov %cs,%rdi
19147+ cmp $__KERNEXEC_KERNEL_CS,%edi
19148+ jz 2f
19149+ GET_CR0_INTO_RDI
19150+ bts $16,%rdi
19151+ jnc 4f
19152+1:
19153+
19154+#ifdef CONFIG_PARAVIRT
19155+ PV_RESTORE_REGS(CLBR_RDI);
19156+#endif
19157+
19158+ popq %rdi
19159+ pax_force_retaddr
19160+ retq
19161+
19162+2: GET_CR0_INTO_RDI
19163+ btr $16,%rdi
19164+ jnc 4f
19165+ ljmpq __KERNEL_CS,3f
19166+3: SET_RDI_INTO_CR0
19167+ jmp 1b
19168+4: ud2
19169+ jmp 4b
19170+ENDPROC(pax_exit_kernel)
19171+#endif
19172+
19173+ .macro pax_enter_kernel_user
19174+ pax_set_fptr_mask
19175+#ifdef CONFIG_PAX_MEMORY_UDEREF
19176+ call pax_enter_kernel_user
19177+#endif
19178+ .endm
19179+
19180+ .macro pax_exit_kernel_user
19181+#ifdef CONFIG_PAX_MEMORY_UDEREF
19182+ call pax_exit_kernel_user
19183+#endif
19184+#ifdef CONFIG_PAX_RANDKSTACK
19185+ pushq %rax
19186+ pushq %r11
19187+ call pax_randomize_kstack
19188+ popq %r11
19189+ popq %rax
19190+#endif
19191+ .endm
19192+
19193+#ifdef CONFIG_PAX_MEMORY_UDEREF
19194+ENTRY(pax_enter_kernel_user)
19195+ pushq %rdi
19196+ pushq %rbx
19197+
19198+#ifdef CONFIG_PARAVIRT
19199+ PV_SAVE_REGS(CLBR_RDI)
19200+#endif
19201+
19202+ GET_CR3_INTO_RDI
19203+ mov %rdi,%rbx
19204+ add $__START_KERNEL_map,%rbx
19205+ sub phys_base(%rip),%rbx
19206+
19207+#ifdef CONFIG_PARAVIRT
19208+ cmpl $0, pv_info+PARAVIRT_enabled
19209+ jz 1f
19210+ pushq %rdi
19211+ i = 0
19212+ .rept USER_PGD_PTRS
19213+ mov i*8(%rbx),%rsi
19214+ mov $0,%sil
19215+ lea i*8(%rbx),%rdi
19216+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19217+ i = i + 1
19218+ .endr
19219+ popq %rdi
19220+ jmp 2f
19221+1:
19222+#endif
19223+
19224+ i = 0
19225+ .rept USER_PGD_PTRS
19226+ movb $0,i*8(%rbx)
19227+ i = i + 1
19228+ .endr
19229+
19230+#ifdef CONFIG_PARAVIRT
19231+2:
19232+#endif
19233+ SET_RDI_INTO_CR3
19234+
19235+#ifdef CONFIG_PAX_KERNEXEC
19236+ GET_CR0_INTO_RDI
19237+ bts $16,%rdi
19238+ SET_RDI_INTO_CR0
19239+#endif
19240+
19241+#ifdef CONFIG_PARAVIRT
19242+ PV_RESTORE_REGS(CLBR_RDI)
19243+#endif
19244+
19245+ popq %rbx
19246+ popq %rdi
19247+ pax_force_retaddr
19248+ retq
19249+ENDPROC(pax_enter_kernel_user)
19250+
19251+ENTRY(pax_exit_kernel_user)
19252+ pushq %rdi
19253+ pushq %rbx
19254+
19255+#ifdef CONFIG_PARAVIRT
19256+ PV_SAVE_REGS(CLBR_RDI)
19257+#endif
19258+
19259+#ifdef CONFIG_PAX_KERNEXEC
19260+ GET_CR0_INTO_RDI
19261+ btr $16,%rdi
19262+ jnc 3f
19263+ SET_RDI_INTO_CR0
19264+#endif
19265+
19266+ GET_CR3_INTO_RDI
19267+ mov %rdi,%rbx
19268+ add $__START_KERNEL_map,%rbx
19269+ sub phys_base(%rip),%rbx
19270+
19271+#ifdef CONFIG_PARAVIRT
19272+ cmpl $0, pv_info+PARAVIRT_enabled
19273+ jz 1f
19274+ i = 0
19275+ .rept USER_PGD_PTRS
19276+ mov i*8(%rbx),%rsi
19277+ mov $0x67,%sil
19278+ lea i*8(%rbx),%rdi
19279+ call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
19280+ i = i + 1
19281+ .endr
19282+ jmp 2f
19283+1:
19284+#endif
19285+
19286+ i = 0
19287+ .rept USER_PGD_PTRS
19288+ movb $0x67,i*8(%rbx)
19289+ i = i + 1
19290+ .endr
19291+
19292+#ifdef CONFIG_PARAVIRT
19293+2: PV_RESTORE_REGS(CLBR_RDI)
19294+#endif
19295+
19296+ popq %rbx
19297+ popq %rdi
19298+ pax_force_retaddr
19299+ retq
19300+3: ud2
19301+ jmp 3b
19302+ENDPROC(pax_exit_kernel_user)
19303+#endif
19304+
19305+ .macro pax_enter_kernel_nmi
19306+ pax_set_fptr_mask
19307+
19308+#ifdef CONFIG_PAX_KERNEXEC
19309+ GET_CR0_INTO_RDI
19310+ bts $16,%rdi
19311+ jc 110f
19312+ SET_RDI_INTO_CR0
19313+ or $2,%ebx
19314+110:
19315+#endif
19316+ .endm
19317+
19318+ .macro pax_exit_kernel_nmi
19319+#ifdef CONFIG_PAX_KERNEXEC
19320+ btr $1,%ebx
19321+ jnc 110f
19322+ GET_CR0_INTO_RDI
19323+ btr $16,%rdi
19324+ SET_RDI_INTO_CR0
19325+110:
19326+#endif
19327+ .endm
19328+
19329+.macro pax_erase_kstack
19330+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19331+ call pax_erase_kstack
19332+#endif
19333+.endm
19334+
19335+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
19336+ENTRY(pax_erase_kstack)
19337+ pushq %rdi
19338+ pushq %rcx
19339+ pushq %rax
19340+ pushq %r11
19341+
19342+ GET_THREAD_INFO(%r11)
19343+ mov TI_lowest_stack(%r11), %rdi
19344+ mov $-0xBEEF, %rax
19345+ std
19346+
19347+1: mov %edi, %ecx
19348+ and $THREAD_SIZE_asm - 1, %ecx
19349+ shr $3, %ecx
19350+ repne scasq
19351+ jecxz 2f
19352+
19353+ cmp $2*8, %ecx
19354+ jc 2f
19355+
19356+ mov $2*8, %ecx
19357+ repe scasq
19358+ jecxz 2f
19359+ jne 1b
19360+
19361+2: cld
19362+ mov %esp, %ecx
19363+ sub %edi, %ecx
19364+
19365+ cmp $THREAD_SIZE_asm, %rcx
19366+ jb 3f
19367+ ud2
19368+3:
19369+
19370+ shr $3, %ecx
19371+ rep stosq
19372+
19373+ mov TI_task_thread_sp0(%r11), %rdi
19374+ sub $256, %rdi
19375+ mov %rdi, TI_lowest_stack(%r11)
19376+
19377+ popq %r11
19378+ popq %rax
19379+ popq %rcx
19380+ popq %rdi
19381+ pax_force_retaddr
19382+ ret
19383+ENDPROC(pax_erase_kstack)
19384+#endif
19385
19386 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
19387 #ifdef CONFIG_TRACE_IRQFLAGS
19388@@ -375,8 +687,8 @@ ENDPROC(native_usergs_sysret64)
19389 .endm
19390
19391 .macro UNFAKE_STACK_FRAME
19392- addq $8*6, %rsp
19393- CFI_ADJUST_CFA_OFFSET -(6*8)
19394+ addq $8*6 + ARG_SKIP, %rsp
19395+ CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
19396 .endm
19397
19398 /*
19399@@ -463,7 +775,7 @@ ENDPROC(native_usergs_sysret64)
19400 movq %rsp, %rsi
19401
19402 leaq -RBP(%rsp),%rdi /* arg1 for handler */
19403- testl $3, CS-RBP(%rsi)
19404+ testb $3, CS-RBP(%rsi)
19405 je 1f
19406 SWAPGS
19407 /*
19408@@ -498,9 +810,10 @@ ENTRY(save_rest)
19409 movq_cfi r15, R15+16
19410 movq %r11, 8(%rsp) /* return address */
19411 FIXUP_TOP_OF_STACK %r11, 16
19412+ pax_force_retaddr
19413 ret
19414 CFI_ENDPROC
19415-END(save_rest)
19416+ENDPROC(save_rest)
19417
19418 /* save complete stack frame */
19419 .pushsection .kprobes.text, "ax"
19420@@ -529,9 +842,10 @@ ENTRY(save_paranoid)
19421 js 1f /* negative -> in kernel */
19422 SWAPGS
19423 xorl %ebx,%ebx
19424-1: ret
19425+1: pax_force_retaddr_bts
19426+ ret
19427 CFI_ENDPROC
19428-END(save_paranoid)
19429+ENDPROC(save_paranoid)
19430 .popsection
19431
19432 /*
19433@@ -553,7 +867,7 @@ ENTRY(ret_from_fork)
19434
19435 RESTORE_REST
19436
19437- testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19438+ testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
19439 jz 1f
19440
19441 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
19442@@ -571,7 +885,7 @@ ENTRY(ret_from_fork)
19443 RESTORE_REST
19444 jmp int_ret_from_sys_call
19445 CFI_ENDPROC
19446-END(ret_from_fork)
19447+ENDPROC(ret_from_fork)
19448
19449 /*
19450 * System call entry. Up to 6 arguments in registers are supported.
19451@@ -608,7 +922,7 @@ END(ret_from_fork)
19452 ENTRY(system_call)
19453 CFI_STARTPROC simple
19454 CFI_SIGNAL_FRAME
19455- CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
19456+ CFI_DEF_CFA rsp,0
19457 CFI_REGISTER rip,rcx
19458 /*CFI_REGISTER rflags,r11*/
19459 SWAPGS_UNSAFE_STACK
19460@@ -621,16 +935,23 @@ GLOBAL(system_call_after_swapgs)
19461
19462 movq %rsp,PER_CPU_VAR(old_rsp)
19463 movq PER_CPU_VAR(kernel_stack),%rsp
19464+ SAVE_ARGS 8*6,0
19465+ pax_enter_kernel_user
19466+
19467+#ifdef CONFIG_PAX_RANDKSTACK
19468+ pax_erase_kstack
19469+#endif
19470+
19471 /*
19472 * No need to follow this irqs off/on section - it's straight
19473 * and short:
19474 */
19475 ENABLE_INTERRUPTS(CLBR_NONE)
19476- SAVE_ARGS 8,0
19477 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
19478 movq %rcx,RIP-ARGOFFSET(%rsp)
19479 CFI_REL_OFFSET rip,RIP-ARGOFFSET
19480- testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19481+ GET_THREAD_INFO(%rcx)
19482+ testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
19483 jnz tracesys
19484 system_call_fastpath:
19485 #if __SYSCALL_MASK == ~0
19486@@ -640,7 +961,7 @@ system_call_fastpath:
19487 cmpl $__NR_syscall_max,%eax
19488 #endif
19489 ja badsys
19490- movq %r10,%rcx
19491+ movq R10-ARGOFFSET(%rsp),%rcx
19492 call *sys_call_table(,%rax,8) # XXX: rip relative
19493 movq %rax,RAX-ARGOFFSET(%rsp)
19494 /*
19495@@ -654,10 +975,13 @@ sysret_check:
19496 LOCKDEP_SYS_EXIT
19497 DISABLE_INTERRUPTS(CLBR_NONE)
19498 TRACE_IRQS_OFF
19499- movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
19500+ GET_THREAD_INFO(%rcx)
19501+ movl TI_flags(%rcx),%edx
19502 andl %edi,%edx
19503 jnz sysret_careful
19504 CFI_REMEMBER_STATE
19505+ pax_exit_kernel_user
19506+ pax_erase_kstack
19507 /*
19508 * sysretq will re-enable interrupts:
19509 */
19510@@ -709,14 +1033,18 @@ badsys:
19511 * jump back to the normal fast path.
19512 */
19513 auditsys:
19514- movq %r10,%r9 /* 6th arg: 4th syscall arg */
19515+ movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
19516 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
19517 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
19518 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
19519 movq %rax,%rsi /* 2nd arg: syscall number */
19520 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
19521 call __audit_syscall_entry
19522+
19523+ pax_erase_kstack
19524+
19525 LOAD_ARGS 0 /* reload call-clobbered registers */
19526+ pax_set_fptr_mask
19527 jmp system_call_fastpath
19528
19529 /*
19530@@ -737,7 +1065,7 @@ sysret_audit:
19531 /* Do syscall tracing */
19532 tracesys:
19533 #ifdef CONFIG_AUDITSYSCALL
19534- testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
19535+ testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
19536 jz auditsys
19537 #endif
19538 SAVE_REST
19539@@ -745,12 +1073,16 @@ tracesys:
19540 FIXUP_TOP_OF_STACK %rdi
19541 movq %rsp,%rdi
19542 call syscall_trace_enter
19543+
19544+ pax_erase_kstack
19545+
19546 /*
19547 * Reload arg registers from stack in case ptrace changed them.
19548 * We don't reload %rax because syscall_trace_enter() returned
19549 * the value it wants us to use in the table lookup.
19550 */
19551 LOAD_ARGS ARGOFFSET, 1
19552+ pax_set_fptr_mask
19553 RESTORE_REST
19554 #if __SYSCALL_MASK == ~0
19555 cmpq $__NR_syscall_max,%rax
19556@@ -759,7 +1091,7 @@ tracesys:
19557 cmpl $__NR_syscall_max,%eax
19558 #endif
19559 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
19560- movq %r10,%rcx /* fixup for C */
19561+ movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
19562 call *sys_call_table(,%rax,8)
19563 movq %rax,RAX-ARGOFFSET(%rsp)
19564 /* Use IRET because user could have changed frame */
19565@@ -780,7 +1112,9 @@ GLOBAL(int_with_check)
19566 andl %edi,%edx
19567 jnz int_careful
19568 andl $~TS_COMPAT,TI_status(%rcx)
19569- jmp retint_swapgs
19570+ pax_exit_kernel_user
19571+ pax_erase_kstack
19572+ jmp retint_swapgs_pax
19573
19574 /* Either reschedule or signal or syscall exit tracking needed. */
19575 /* First do a reschedule test. */
19576@@ -826,7 +1160,7 @@ int_restore_rest:
19577 TRACE_IRQS_OFF
19578 jmp int_with_check
19579 CFI_ENDPROC
19580-END(system_call)
19581+ENDPROC(system_call)
19582
19583 .macro FORK_LIKE func
19584 ENTRY(stub_\func)
19585@@ -839,9 +1173,10 @@ ENTRY(stub_\func)
19586 DEFAULT_FRAME 0 8 /* offset 8: return address */
19587 call sys_\func
19588 RESTORE_TOP_OF_STACK %r11, 8
19589+ pax_force_retaddr
19590 ret $REST_SKIP /* pop extended registers */
19591 CFI_ENDPROC
19592-END(stub_\func)
19593+ENDPROC(stub_\func)
19594 .endm
19595
19596 .macro FIXED_FRAME label,func
19597@@ -851,9 +1186,10 @@ ENTRY(\label)
19598 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
19599 call \func
19600 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
19601+ pax_force_retaddr
19602 ret
19603 CFI_ENDPROC
19604-END(\label)
19605+ENDPROC(\label)
19606 .endm
19607
19608 FORK_LIKE clone
19609@@ -870,9 +1206,10 @@ ENTRY(ptregscall_common)
19610 movq_cfi_restore R12+8, r12
19611 movq_cfi_restore RBP+8, rbp
19612 movq_cfi_restore RBX+8, rbx
19613+ pax_force_retaddr
19614 ret $REST_SKIP /* pop extended registers */
19615 CFI_ENDPROC
19616-END(ptregscall_common)
19617+ENDPROC(ptregscall_common)
19618
19619 ENTRY(stub_execve)
19620 CFI_STARTPROC
19621@@ -885,7 +1222,7 @@ ENTRY(stub_execve)
19622 RESTORE_REST
19623 jmp int_ret_from_sys_call
19624 CFI_ENDPROC
19625-END(stub_execve)
19626+ENDPROC(stub_execve)
19627
19628 /*
19629 * sigreturn is special because it needs to restore all registers on return.
19630@@ -902,7 +1239,7 @@ ENTRY(stub_rt_sigreturn)
19631 RESTORE_REST
19632 jmp int_ret_from_sys_call
19633 CFI_ENDPROC
19634-END(stub_rt_sigreturn)
19635+ENDPROC(stub_rt_sigreturn)
19636
19637 #ifdef CONFIG_X86_X32_ABI
19638 ENTRY(stub_x32_rt_sigreturn)
19639@@ -916,7 +1253,7 @@ ENTRY(stub_x32_rt_sigreturn)
19640 RESTORE_REST
19641 jmp int_ret_from_sys_call
19642 CFI_ENDPROC
19643-END(stub_x32_rt_sigreturn)
19644+ENDPROC(stub_x32_rt_sigreturn)
19645
19646 ENTRY(stub_x32_execve)
19647 CFI_STARTPROC
19648@@ -930,7 +1267,7 @@ ENTRY(stub_x32_execve)
19649 RESTORE_REST
19650 jmp int_ret_from_sys_call
19651 CFI_ENDPROC
19652-END(stub_x32_execve)
19653+ENDPROC(stub_x32_execve)
19654
19655 #endif
19656
19657@@ -967,7 +1304,7 @@ vector=vector+1
19658 2: jmp common_interrupt
19659 .endr
19660 CFI_ENDPROC
19661-END(irq_entries_start)
19662+ENDPROC(irq_entries_start)
19663
19664 .previous
19665 END(interrupt)
19666@@ -987,6 +1324,16 @@ END(interrupt)
19667 subq $ORIG_RAX-RBP, %rsp
19668 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
19669 SAVE_ARGS_IRQ
19670+#ifdef CONFIG_PAX_MEMORY_UDEREF
19671+ testb $3, CS(%rdi)
19672+ jnz 1f
19673+ pax_enter_kernel
19674+ jmp 2f
19675+1: pax_enter_kernel_user
19676+2:
19677+#else
19678+ pax_enter_kernel
19679+#endif
19680 call \func
19681 .endm
19682
19683@@ -1019,7 +1366,7 @@ ret_from_intr:
19684
19685 exit_intr:
19686 GET_THREAD_INFO(%rcx)
19687- testl $3,CS-ARGOFFSET(%rsp)
19688+ testb $3,CS-ARGOFFSET(%rsp)
19689 je retint_kernel
19690
19691 /* Interrupt came from user space */
19692@@ -1041,12 +1388,16 @@ retint_swapgs: /* return to user-space */
19693 * The iretq could re-enable interrupts:
19694 */
19695 DISABLE_INTERRUPTS(CLBR_ANY)
19696+ pax_exit_kernel_user
19697+retint_swapgs_pax:
19698 TRACE_IRQS_IRETQ
19699 SWAPGS
19700 jmp restore_args
19701
19702 retint_restore_args: /* return to kernel space */
19703 DISABLE_INTERRUPTS(CLBR_ANY)
19704+ pax_exit_kernel
19705+ pax_force_retaddr (RIP-ARGOFFSET)
19706 /*
19707 * The iretq could re-enable interrupts:
19708 */
19709@@ -1129,7 +1480,7 @@ ENTRY(retint_kernel)
19710 #endif
19711
19712 CFI_ENDPROC
19713-END(common_interrupt)
19714+ENDPROC(common_interrupt)
19715 /*
19716 * End of kprobes section
19717 */
19718@@ -1147,7 +1498,7 @@ ENTRY(\sym)
19719 interrupt \do_sym
19720 jmp ret_from_intr
19721 CFI_ENDPROC
19722-END(\sym)
19723+ENDPROC(\sym)
19724 .endm
19725
19726 #ifdef CONFIG_SMP
19727@@ -1203,12 +1554,22 @@ ENTRY(\sym)
19728 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19729 call error_entry
19730 DEFAULT_FRAME 0
19731+#ifdef CONFIG_PAX_MEMORY_UDEREF
19732+ testb $3, CS(%rsp)
19733+ jnz 1f
19734+ pax_enter_kernel
19735+ jmp 2f
19736+1: pax_enter_kernel_user
19737+2:
19738+#else
19739+ pax_enter_kernel
19740+#endif
19741 movq %rsp,%rdi /* pt_regs pointer */
19742 xorl %esi,%esi /* no error code */
19743 call \do_sym
19744 jmp error_exit /* %ebx: no swapgs flag */
19745 CFI_ENDPROC
19746-END(\sym)
19747+ENDPROC(\sym)
19748 .endm
19749
19750 .macro paranoidzeroentry sym do_sym
19751@@ -1221,15 +1582,25 @@ ENTRY(\sym)
19752 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19753 call save_paranoid
19754 TRACE_IRQS_OFF
19755+#ifdef CONFIG_PAX_MEMORY_UDEREF
19756+ testb $3, CS(%rsp)
19757+ jnz 1f
19758+ pax_enter_kernel
19759+ jmp 2f
19760+1: pax_enter_kernel_user
19761+2:
19762+#else
19763+ pax_enter_kernel
19764+#endif
19765 movq %rsp,%rdi /* pt_regs pointer */
19766 xorl %esi,%esi /* no error code */
19767 call \do_sym
19768 jmp paranoid_exit /* %ebx: no swapgs flag */
19769 CFI_ENDPROC
19770-END(\sym)
19771+ENDPROC(\sym)
19772 .endm
19773
19774-#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
19775+#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
19776 .macro paranoidzeroentry_ist sym do_sym ist
19777 ENTRY(\sym)
19778 INTR_FRAME
19779@@ -1240,14 +1611,30 @@ ENTRY(\sym)
19780 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19781 call save_paranoid
19782 TRACE_IRQS_OFF_DEBUG
19783+#ifdef CONFIG_PAX_MEMORY_UDEREF
19784+ testb $3, CS(%rsp)
19785+ jnz 1f
19786+ pax_enter_kernel
19787+ jmp 2f
19788+1: pax_enter_kernel_user
19789+2:
19790+#else
19791+ pax_enter_kernel
19792+#endif
19793 movq %rsp,%rdi /* pt_regs pointer */
19794 xorl %esi,%esi /* no error code */
19795+#ifdef CONFIG_SMP
19796+ imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
19797+ lea init_tss(%r12), %r12
19798+#else
19799+ lea init_tss(%rip), %r12
19800+#endif
19801 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19802 call \do_sym
19803 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
19804 jmp paranoid_exit /* %ebx: no swapgs flag */
19805 CFI_ENDPROC
19806-END(\sym)
19807+ENDPROC(\sym)
19808 .endm
19809
19810 .macro errorentry sym do_sym
19811@@ -1259,13 +1646,23 @@ ENTRY(\sym)
19812 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
19813 call error_entry
19814 DEFAULT_FRAME 0
19815+#ifdef CONFIG_PAX_MEMORY_UDEREF
19816+ testb $3, CS(%rsp)
19817+ jnz 1f
19818+ pax_enter_kernel
19819+ jmp 2f
19820+1: pax_enter_kernel_user
19821+2:
19822+#else
19823+ pax_enter_kernel
19824+#endif
19825 movq %rsp,%rdi /* pt_regs pointer */
19826 movq ORIG_RAX(%rsp),%rsi /* get error code */
19827 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19828 call \do_sym
19829 jmp error_exit /* %ebx: no swapgs flag */
19830 CFI_ENDPROC
19831-END(\sym)
19832+ENDPROC(\sym)
19833 .endm
19834
19835 /* error code is on the stack already */
19836@@ -1279,13 +1676,23 @@ ENTRY(\sym)
19837 call save_paranoid
19838 DEFAULT_FRAME 0
19839 TRACE_IRQS_OFF
19840+#ifdef CONFIG_PAX_MEMORY_UDEREF
19841+ testb $3, CS(%rsp)
19842+ jnz 1f
19843+ pax_enter_kernel
19844+ jmp 2f
19845+1: pax_enter_kernel_user
19846+2:
19847+#else
19848+ pax_enter_kernel
19849+#endif
19850 movq %rsp,%rdi /* pt_regs pointer */
19851 movq ORIG_RAX(%rsp),%rsi /* get error code */
19852 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
19853 call \do_sym
19854 jmp paranoid_exit /* %ebx: no swapgs flag */
19855 CFI_ENDPROC
19856-END(\sym)
19857+ENDPROC(\sym)
19858 .endm
19859
19860 zeroentry divide_error do_divide_error
19861@@ -1315,9 +1722,10 @@ gs_change:
19862 2: mfence /* workaround */
19863 SWAPGS
19864 popfq_cfi
19865+ pax_force_retaddr
19866 ret
19867 CFI_ENDPROC
19868-END(native_load_gs_index)
19869+ENDPROC(native_load_gs_index)
19870
19871 _ASM_EXTABLE(gs_change,bad_gs)
19872 .section .fixup,"ax"
19873@@ -1345,9 +1753,10 @@ ENTRY(call_softirq)
19874 CFI_DEF_CFA_REGISTER rsp
19875 CFI_ADJUST_CFA_OFFSET -8
19876 decl PER_CPU_VAR(irq_count)
19877+ pax_force_retaddr
19878 ret
19879 CFI_ENDPROC
19880-END(call_softirq)
19881+ENDPROC(call_softirq)
19882
19883 #ifdef CONFIG_XEN
19884 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
19885@@ -1385,7 +1794,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
19886 decl PER_CPU_VAR(irq_count)
19887 jmp error_exit
19888 CFI_ENDPROC
19889-END(xen_do_hypervisor_callback)
19890+ENDPROC(xen_do_hypervisor_callback)
19891
19892 /*
19893 * Hypervisor uses this for application faults while it executes.
19894@@ -1444,7 +1853,7 @@ ENTRY(xen_failsafe_callback)
19895 SAVE_ALL
19896 jmp error_exit
19897 CFI_ENDPROC
19898-END(xen_failsafe_callback)
19899+ENDPROC(xen_failsafe_callback)
19900
19901 apicinterrupt HYPERVISOR_CALLBACK_VECTOR \
19902 xen_hvm_callback_vector xen_evtchn_do_upcall
19903@@ -1498,16 +1907,31 @@ ENTRY(paranoid_exit)
19904 TRACE_IRQS_OFF_DEBUG
19905 testl %ebx,%ebx /* swapgs needed? */
19906 jnz paranoid_restore
19907- testl $3,CS(%rsp)
19908+ testb $3,CS(%rsp)
19909 jnz paranoid_userspace
19910+#ifdef CONFIG_PAX_MEMORY_UDEREF
19911+ pax_exit_kernel
19912+ TRACE_IRQS_IRETQ 0
19913+ SWAPGS_UNSAFE_STACK
19914+ RESTORE_ALL 8
19915+ pax_force_retaddr_bts
19916+ jmp irq_return
19917+#endif
19918 paranoid_swapgs:
19919+#ifdef CONFIG_PAX_MEMORY_UDEREF
19920+ pax_exit_kernel_user
19921+#else
19922+ pax_exit_kernel
19923+#endif
19924 TRACE_IRQS_IRETQ 0
19925 SWAPGS_UNSAFE_STACK
19926 RESTORE_ALL 8
19927 jmp irq_return
19928 paranoid_restore:
19929+ pax_exit_kernel
19930 TRACE_IRQS_IRETQ_DEBUG 0
19931 RESTORE_ALL 8
19932+ pax_force_retaddr_bts
19933 jmp irq_return
19934 paranoid_userspace:
19935 GET_THREAD_INFO(%rcx)
19936@@ -1536,7 +1960,7 @@ paranoid_schedule:
19937 TRACE_IRQS_OFF
19938 jmp paranoid_userspace
19939 CFI_ENDPROC
19940-END(paranoid_exit)
19941+ENDPROC(paranoid_exit)
19942
19943 /*
19944 * Exception entry point. This expects an error code/orig_rax on the stack.
19945@@ -1563,12 +1987,13 @@ ENTRY(error_entry)
19946 movq_cfi r14, R14+8
19947 movq_cfi r15, R15+8
19948 xorl %ebx,%ebx
19949- testl $3,CS+8(%rsp)
19950+ testb $3,CS+8(%rsp)
19951 je error_kernelspace
19952 error_swapgs:
19953 SWAPGS
19954 error_sti:
19955 TRACE_IRQS_OFF
19956+ pax_force_retaddr_bts
19957 ret
19958
19959 /*
19960@@ -1595,7 +2020,7 @@ bstep_iret:
19961 movq %rcx,RIP+8(%rsp)
19962 jmp error_swapgs
19963 CFI_ENDPROC
19964-END(error_entry)
19965+ENDPROC(error_entry)
19966
19967
19968 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
19969@@ -1615,7 +2040,7 @@ ENTRY(error_exit)
19970 jnz retint_careful
19971 jmp retint_swapgs
19972 CFI_ENDPROC
19973-END(error_exit)
19974+ENDPROC(error_exit)
19975
19976 /*
19977 * Test if a given stack is an NMI stack or not.
19978@@ -1673,9 +2098,11 @@ ENTRY(nmi)
19979 * If %cs was not the kernel segment, then the NMI triggered in user
19980 * space, which means it is definitely not nested.
19981 */
19982+ cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
19983+ je 1f
19984 cmpl $__KERNEL_CS, 16(%rsp)
19985 jne first_nmi
19986-
19987+1:
19988 /*
19989 * Check the special variable on the stack to see if NMIs are
19990 * executing.
19991@@ -1709,8 +2136,7 @@ nested_nmi:
19992
19993 1:
19994 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
19995- leaq -1*8(%rsp), %rdx
19996- movq %rdx, %rsp
19997+ subq $8, %rsp
19998 CFI_ADJUST_CFA_OFFSET 1*8
19999 leaq -10*8(%rsp), %rdx
20000 pushq_cfi $__KERNEL_DS
20001@@ -1728,6 +2154,7 @@ nested_nmi_out:
20002 CFI_RESTORE rdx
20003
20004 /* No need to check faults here */
20005+# pax_force_retaddr_bts
20006 INTERRUPT_RETURN
20007
20008 CFI_RESTORE_STATE
20009@@ -1844,6 +2271,8 @@ end_repeat_nmi:
20010 */
20011 movq %cr2, %r12
20012
20013+ pax_enter_kernel_nmi
20014+
20015 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
20016 movq %rsp,%rdi
20017 movq $-1,%rsi
20018@@ -1856,26 +2285,31 @@ end_repeat_nmi:
20019 movq %r12, %cr2
20020 1:
20021
20022- testl %ebx,%ebx /* swapgs needed? */
20023+ testl $1,%ebx /* swapgs needed? */
20024 jnz nmi_restore
20025 nmi_swapgs:
20026 SWAPGS_UNSAFE_STACK
20027 nmi_restore:
20028+ pax_exit_kernel_nmi
20029 /* Pop the extra iret frame at once */
20030 RESTORE_ALL 6*8
20031+ testb $3, 8(%rsp)
20032+ jnz 1f
20033+ pax_force_retaddr_bts
20034+1:
20035
20036 /* Clear the NMI executing stack variable */
20037 movq $0, 5*8(%rsp)
20038 jmp irq_return
20039 CFI_ENDPROC
20040-END(nmi)
20041+ENDPROC(nmi)
20042
20043 ENTRY(ignore_sysret)
20044 CFI_STARTPROC
20045 mov $-ENOSYS,%eax
20046 sysret
20047 CFI_ENDPROC
20048-END(ignore_sysret)
20049+ENDPROC(ignore_sysret)
20050
20051 /*
20052 * End of kprobes section
20053diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
20054index 42a392a..fbbd930 100644
20055--- a/arch/x86/kernel/ftrace.c
20056+++ b/arch/x86/kernel/ftrace.c
20057@@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
20058 {
20059 unsigned char replaced[MCOUNT_INSN_SIZE];
20060
20061+ ip = ktla_ktva(ip);
20062+
20063 /*
20064 * Note: Due to modules and __init, code can
20065 * disappear and change, we need to protect against faulting
20066@@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20067 unsigned char old[MCOUNT_INSN_SIZE], *new;
20068 int ret;
20069
20070- memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
20071+ memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
20072 new = ftrace_call_replace(ip, (unsigned long)func);
20073
20074 /* See comment above by declaration of modifying_ftrace_code */
20075@@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
20076 /* Also update the regs callback function */
20077 if (!ret) {
20078 ip = (unsigned long)(&ftrace_regs_call);
20079- memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
20080+ memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
20081 new = ftrace_call_replace(ip, (unsigned long)func);
20082 ret = ftrace_modify_code(ip, old, new);
20083 }
20084@@ -279,7 +281,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
20085 * kernel identity mapping to modify code.
20086 */
20087 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
20088- ip = (unsigned long)__va(__pa_symbol(ip));
20089+ ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
20090
20091 return probe_kernel_write((void *)ip, val, size);
20092 }
20093@@ -289,7 +291,7 @@ static int add_break(unsigned long ip, const char *old)
20094 unsigned char replaced[MCOUNT_INSN_SIZE];
20095 unsigned char brk = BREAKPOINT_INSTRUCTION;
20096
20097- if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
20098+ if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
20099 return -EFAULT;
20100
20101 /* Make sure it is what we expect it to be */
20102@@ -637,7 +639,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
20103 return ret;
20104
20105 fail_update:
20106- probe_kernel_write((void *)ip, &old_code[0], 1);
20107+ probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
20108 goto out;
20109 }
20110
20111@@ -670,6 +672,8 @@ static int ftrace_mod_jmp(unsigned long ip,
20112 {
20113 unsigned char code[MCOUNT_INSN_SIZE];
20114
20115+ ip = ktla_ktva(ip);
20116+
20117 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
20118 return -EFAULT;
20119
20120diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
20121index 8f3201d..aa860bf 100644
20122--- a/arch/x86/kernel/head64.c
20123+++ b/arch/x86/kernel/head64.c
20124@@ -175,7 +175,6 @@ void __init x86_64_start_kernel(char * real_mode_data)
20125 if (console_loglevel == 10)
20126 early_printk("Kernel alive\n");
20127
20128- clear_page(init_level4_pgt);
20129 /* set init_level4_pgt kernel high mapping*/
20130 init_level4_pgt[511] = early_level4_pgt[511];
20131
20132diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
20133index 73afd11..d1670f5 100644
20134--- a/arch/x86/kernel/head_32.S
20135+++ b/arch/x86/kernel/head_32.S
20136@@ -26,6 +26,12 @@
20137 /* Physical address */
20138 #define pa(X) ((X) - __PAGE_OFFSET)
20139
20140+#ifdef CONFIG_PAX_KERNEXEC
20141+#define ta(X) (X)
20142+#else
20143+#define ta(X) ((X) - __PAGE_OFFSET)
20144+#endif
20145+
20146 /*
20147 * References to members of the new_cpu_data structure.
20148 */
20149@@ -55,11 +61,7 @@
20150 * and small than max_low_pfn, otherwise will waste some page table entries
20151 */
20152
20153-#if PTRS_PER_PMD > 1
20154-#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
20155-#else
20156-#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
20157-#endif
20158+#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
20159
20160 /* Number of possible pages in the lowmem region */
20161 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
20162@@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
20163 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20164
20165 /*
20166+ * Real beginning of normal "text" segment
20167+ */
20168+ENTRY(stext)
20169+ENTRY(_stext)
20170+
20171+/*
20172 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
20173 * %esi points to the real-mode code as a 32-bit pointer.
20174 * CS and DS must be 4 GB flat segments, but we don't depend on
20175@@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
20176 * can.
20177 */
20178 __HEAD
20179+
20180+#ifdef CONFIG_PAX_KERNEXEC
20181+ jmp startup_32
20182+/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
20183+.fill PAGE_SIZE-5,1,0xcc
20184+#endif
20185+
20186 ENTRY(startup_32)
20187 movl pa(stack_start),%ecx
20188
20189@@ -106,6 +121,59 @@ ENTRY(startup_32)
20190 2:
20191 leal -__PAGE_OFFSET(%ecx),%esp
20192
20193+#ifdef CONFIG_SMP
20194+ movl $pa(cpu_gdt_table),%edi
20195+ movl $__per_cpu_load,%eax
20196+ movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
20197+ rorl $16,%eax
20198+ movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
20199+ movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
20200+ movl $__per_cpu_end - 1,%eax
20201+ subl $__per_cpu_start,%eax
20202+ movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
20203+#endif
20204+
20205+#ifdef CONFIG_PAX_MEMORY_UDEREF
20206+ movl $NR_CPUS,%ecx
20207+ movl $pa(cpu_gdt_table),%edi
20208+1:
20209+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
20210+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
20211+ movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
20212+ addl $PAGE_SIZE_asm,%edi
20213+ loop 1b
20214+#endif
20215+
20216+#ifdef CONFIG_PAX_KERNEXEC
20217+ movl $pa(boot_gdt),%edi
20218+ movl $__LOAD_PHYSICAL_ADDR,%eax
20219+ movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
20220+ rorl $16,%eax
20221+ movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
20222+ movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
20223+ rorl $16,%eax
20224+
20225+ ljmp $(__BOOT_CS),$1f
20226+1:
20227+
20228+ movl $NR_CPUS,%ecx
20229+ movl $pa(cpu_gdt_table),%edi
20230+ addl $__PAGE_OFFSET,%eax
20231+1:
20232+ movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
20233+ movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
20234+ movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
20235+ movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
20236+ rorl $16,%eax
20237+ movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
20238+ movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
20239+ movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
20240+ movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
20241+ rorl $16,%eax
20242+ addl $PAGE_SIZE_asm,%edi
20243+ loop 1b
20244+#endif
20245+
20246 /*
20247 * Clear BSS first so that there are no surprises...
20248 */
20249@@ -201,8 +269,11 @@ ENTRY(startup_32)
20250 movl %eax, pa(max_pfn_mapped)
20251
20252 /* Do early initialization of the fixmap area */
20253- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20254- movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
20255+#ifdef CONFIG_COMPAT_VDSO
20256+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
20257+#else
20258+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
20259+#endif
20260 #else /* Not PAE */
20261
20262 page_pde_offset = (__PAGE_OFFSET >> 20);
20263@@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20264 movl %eax, pa(max_pfn_mapped)
20265
20266 /* Do early initialization of the fixmap area */
20267- movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
20268- movl %eax,pa(initial_page_table+0xffc)
20269+#ifdef CONFIG_COMPAT_VDSO
20270+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
20271+#else
20272+ movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
20273+#endif
20274 #endif
20275
20276 #ifdef CONFIG_PARAVIRT
20277@@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
20278 cmpl $num_subarch_entries, %eax
20279 jae bad_subarch
20280
20281- movl pa(subarch_entries)(,%eax,4), %eax
20282- subl $__PAGE_OFFSET, %eax
20283- jmp *%eax
20284+ jmp *pa(subarch_entries)(,%eax,4)
20285
20286 bad_subarch:
20287 WEAK(lguest_entry)
20288@@ -261,10 +333,10 @@ WEAK(xen_entry)
20289 __INITDATA
20290
20291 subarch_entries:
20292- .long default_entry /* normal x86/PC */
20293- .long lguest_entry /* lguest hypervisor */
20294- .long xen_entry /* Xen hypervisor */
20295- .long default_entry /* Moorestown MID */
20296+ .long ta(default_entry) /* normal x86/PC */
20297+ .long ta(lguest_entry) /* lguest hypervisor */
20298+ .long ta(xen_entry) /* Xen hypervisor */
20299+ .long ta(default_entry) /* Moorestown MID */
20300 num_subarch_entries = (. - subarch_entries) / 4
20301 .previous
20302 #else
20303@@ -355,6 +427,7 @@ default_entry:
20304 movl pa(mmu_cr4_features),%eax
20305 movl %eax,%cr4
20306
20307+#ifdef CONFIG_X86_PAE
20308 testb $X86_CR4_PAE, %al # check if PAE is enabled
20309 jz enable_paging
20310
20311@@ -383,6 +456,9 @@ default_entry:
20312 /* Make changes effective */
20313 wrmsr
20314
20315+ btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
20316+#endif
20317+
20318 enable_paging:
20319
20320 /*
20321@@ -451,14 +527,20 @@ is486:
20322 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
20323 movl %eax,%ss # after changing gdt.
20324
20325- movl $(__USER_DS),%eax # DS/ES contains default USER segment
20326+# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
20327 movl %eax,%ds
20328 movl %eax,%es
20329
20330 movl $(__KERNEL_PERCPU), %eax
20331 movl %eax,%fs # set this cpu's percpu
20332
20333+#ifdef CONFIG_CC_STACKPROTECTOR
20334 movl $(__KERNEL_STACK_CANARY),%eax
20335+#elif defined(CONFIG_PAX_MEMORY_UDEREF)
20336+ movl $(__USER_DS),%eax
20337+#else
20338+ xorl %eax,%eax
20339+#endif
20340 movl %eax,%gs
20341
20342 xorl %eax,%eax # Clear LDT
20343@@ -534,8 +616,11 @@ setup_once:
20344 * relocation. Manually set base address in stack canary
20345 * segment descriptor.
20346 */
20347- movl $gdt_page,%eax
20348+ movl $cpu_gdt_table,%eax
20349 movl $stack_canary,%ecx
20350+#ifdef CONFIG_SMP
20351+ addl $__per_cpu_load,%ecx
20352+#endif
20353 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
20354 shrl $16, %ecx
20355 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
20356@@ -566,7 +651,7 @@ ENDPROC(early_idt_handlers)
20357 /* This is global to keep gas from relaxing the jumps */
20358 ENTRY(early_idt_handler)
20359 cld
20360- cmpl $2,%ss:early_recursion_flag
20361+ cmpl $1,%ss:early_recursion_flag
20362 je hlt_loop
20363 incl %ss:early_recursion_flag
20364
20365@@ -604,8 +689,8 @@ ENTRY(early_idt_handler)
20366 pushl (20+6*4)(%esp) /* trapno */
20367 pushl $fault_msg
20368 call printk
20369-#endif
20370 call dump_stack
20371+#endif
20372 hlt_loop:
20373 hlt
20374 jmp hlt_loop
20375@@ -624,8 +709,11 @@ ENDPROC(early_idt_handler)
20376 /* This is the default interrupt "handler" :-) */
20377 ALIGN
20378 ignore_int:
20379- cld
20380 #ifdef CONFIG_PRINTK
20381+ cmpl $2,%ss:early_recursion_flag
20382+ je hlt_loop
20383+ incl %ss:early_recursion_flag
20384+ cld
20385 pushl %eax
20386 pushl %ecx
20387 pushl %edx
20388@@ -634,9 +722,6 @@ ignore_int:
20389 movl $(__KERNEL_DS),%eax
20390 movl %eax,%ds
20391 movl %eax,%es
20392- cmpl $2,early_recursion_flag
20393- je hlt_loop
20394- incl early_recursion_flag
20395 pushl 16(%esp)
20396 pushl 24(%esp)
20397 pushl 32(%esp)
20398@@ -670,29 +755,43 @@ ENTRY(setup_once_ref)
20399 /*
20400 * BSS section
20401 */
20402-__PAGE_ALIGNED_BSS
20403- .align PAGE_SIZE
20404 #ifdef CONFIG_X86_PAE
20405+.section .initial_pg_pmd,"a",@progbits
20406 initial_pg_pmd:
20407 .fill 1024*KPMDS,4,0
20408 #else
20409+.section .initial_page_table,"a",@progbits
20410 ENTRY(initial_page_table)
20411 .fill 1024,4,0
20412 #endif
20413+.section .initial_pg_fixmap,"a",@progbits
20414 initial_pg_fixmap:
20415 .fill 1024,4,0
20416+.section .empty_zero_page,"a",@progbits
20417 ENTRY(empty_zero_page)
20418 .fill 4096,1,0
20419+.section .swapper_pg_dir,"a",@progbits
20420 ENTRY(swapper_pg_dir)
20421+#ifdef CONFIG_X86_PAE
20422+ .fill 4,8,0
20423+#else
20424 .fill 1024,4,0
20425+#endif
20426+
20427+/*
20428+ * The IDT has to be page-aligned to simplify the Pentium
20429+ * F0 0F bug workaround.. We have a special link segment
20430+ * for this.
20431+ */
20432+.section .idt,"a",@progbits
20433+ENTRY(idt_table)
20434+ .fill 256,8,0
20435
20436 /*
20437 * This starts the data section.
20438 */
20439 #ifdef CONFIG_X86_PAE
20440-__PAGE_ALIGNED_DATA
20441- /* Page-aligned for the benefit of paravirt? */
20442- .align PAGE_SIZE
20443+.section .initial_page_table,"a",@progbits
20444 ENTRY(initial_page_table)
20445 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
20446 # if KPMDS == 3
20447@@ -711,12 +810,20 @@ ENTRY(initial_page_table)
20448 # error "Kernel PMDs should be 1, 2 or 3"
20449 # endif
20450 .align PAGE_SIZE /* needs to be page-sized too */
20451+
20452+#ifdef CONFIG_PAX_PER_CPU_PGD
20453+ENTRY(cpu_pgd)
20454+ .rept NR_CPUS
20455+ .fill 4,8,0
20456+ .endr
20457+#endif
20458+
20459 #endif
20460
20461 .data
20462 .balign 4
20463 ENTRY(stack_start)
20464- .long init_thread_union+THREAD_SIZE
20465+ .long init_thread_union+THREAD_SIZE-8
20466
20467 __INITRODATA
20468 int_msg:
20469@@ -744,7 +851,7 @@ fault_msg:
20470 * segment size, and 32-bit linear address value:
20471 */
20472
20473- .data
20474+.section .rodata,"a",@progbits
20475 .globl boot_gdt_descr
20476 .globl idt_descr
20477
20478@@ -753,7 +860,7 @@ fault_msg:
20479 .word 0 # 32 bit align gdt_desc.address
20480 boot_gdt_descr:
20481 .word __BOOT_DS+7
20482- .long boot_gdt - __PAGE_OFFSET
20483+ .long pa(boot_gdt)
20484
20485 .word 0 # 32-bit align idt_desc.address
20486 idt_descr:
20487@@ -764,7 +871,7 @@ idt_descr:
20488 .word 0 # 32 bit align gdt_desc.address
20489 ENTRY(early_gdt_descr)
20490 .word GDT_ENTRIES*8-1
20491- .long gdt_page /* Overwritten for secondary CPUs */
20492+ .long cpu_gdt_table /* Overwritten for secondary CPUs */
20493
20494 /*
20495 * The boot_gdt must mirror the equivalent in setup.S and is
20496@@ -773,5 +880,65 @@ ENTRY(early_gdt_descr)
20497 .align L1_CACHE_BYTES
20498 ENTRY(boot_gdt)
20499 .fill GDT_ENTRY_BOOT_CS,8,0
20500- .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
20501- .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
20502+ .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
20503+ .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
20504+
20505+ .align PAGE_SIZE_asm
20506+ENTRY(cpu_gdt_table)
20507+ .rept NR_CPUS
20508+ .quad 0x0000000000000000 /* NULL descriptor */
20509+ .quad 0x0000000000000000 /* 0x0b reserved */
20510+ .quad 0x0000000000000000 /* 0x13 reserved */
20511+ .quad 0x0000000000000000 /* 0x1b reserved */
20512+
20513+#ifdef CONFIG_PAX_KERNEXEC
20514+ .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
20515+#else
20516+ .quad 0x0000000000000000 /* 0x20 unused */
20517+#endif
20518+
20519+ .quad 0x0000000000000000 /* 0x28 unused */
20520+ .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
20521+ .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
20522+ .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
20523+ .quad 0x0000000000000000 /* 0x4b reserved */
20524+ .quad 0x0000000000000000 /* 0x53 reserved */
20525+ .quad 0x0000000000000000 /* 0x5b reserved */
20526+
20527+ .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
20528+ .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
20529+ .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
20530+ .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
20531+
20532+ .quad 0x0000000000000000 /* 0x80 TSS descriptor */
20533+ .quad 0x0000000000000000 /* 0x88 LDT descriptor */
20534+
20535+ /*
20536+ * Segments used for calling PnP BIOS have byte granularity.
20537+ * The code segments and data segments have fixed 64k limits,
20538+ * the transfer segment sizes are set at run time.
20539+ */
20540+ .quad 0x00409b000000ffff /* 0x90 32-bit code */
20541+ .quad 0x00009b000000ffff /* 0x98 16-bit code */
20542+ .quad 0x000093000000ffff /* 0xa0 16-bit data */
20543+ .quad 0x0000930000000000 /* 0xa8 16-bit data */
20544+ .quad 0x0000930000000000 /* 0xb0 16-bit data */
20545+
20546+ /*
20547+ * The APM segments have byte granularity and their bases
20548+ * are set at run time. All have 64k limits.
20549+ */
20550+ .quad 0x00409b000000ffff /* 0xb8 APM CS code */
20551+ .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
20552+ .quad 0x004093000000ffff /* 0xc8 APM DS data */
20553+
20554+ .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
20555+ .quad 0x0040930000000000 /* 0xd8 - PERCPU */
20556+ .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
20557+ .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
20558+ .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
20559+ .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
20560+
20561+ /* Be sure this is zeroed to avoid false validations in Xen */
20562+ .fill PAGE_SIZE_asm - GDT_SIZE,1,0
20563+ .endr
20564diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
20565index 321d65e..7830f05 100644
20566--- a/arch/x86/kernel/head_64.S
20567+++ b/arch/x86/kernel/head_64.S
20568@@ -20,6 +20,8 @@
20569 #include <asm/processor-flags.h>
20570 #include <asm/percpu.h>
20571 #include <asm/nops.h>
20572+#include <asm/cpufeature.h>
20573+#include <asm/alternative-asm.h>
20574
20575 #ifdef CONFIG_PARAVIRT
20576 #include <asm/asm-offsets.h>
20577@@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
20578 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
20579 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
20580 L3_START_KERNEL = pud_index(__START_KERNEL_map)
20581+L4_VMALLOC_START = pgd_index(VMALLOC_START)
20582+L3_VMALLOC_START = pud_index(VMALLOC_START)
20583+L4_VMALLOC_END = pgd_index(VMALLOC_END)
20584+L3_VMALLOC_END = pud_index(VMALLOC_END)
20585+L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
20586+L3_VMEMMAP_START = pud_index(VMEMMAP_START)
20587
20588 .text
20589 __HEAD
20590@@ -89,11 +97,15 @@ startup_64:
20591 * Fixup the physical addresses in the page table
20592 */
20593 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
20594+ addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
20595+ addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
20596+ addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
20597
20598 addq %rbp, level3_kernel_pgt + (510*8)(%rip)
20599 addq %rbp, level3_kernel_pgt + (511*8)(%rip)
20600
20601 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
20602+ addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
20603
20604 /*
20605 * Set up the identity mapping for the switchover. These
20606@@ -177,8 +189,8 @@ ENTRY(secondary_startup_64)
20607 movq $(init_level4_pgt - __START_KERNEL_map), %rax
20608 1:
20609
20610- /* Enable PAE mode and PGE */
20611- movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
20612+ /* Enable PAE mode and PSE/PGE */
20613+ movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
20614 movq %rcx, %cr4
20615
20616 /* Setup early boot stage 4 level pagetables. */
20617@@ -199,10 +211,18 @@ ENTRY(secondary_startup_64)
20618 movl $MSR_EFER, %ecx
20619 rdmsr
20620 btsl $_EFER_SCE, %eax /* Enable System Call */
20621- btl $20,%edi /* No Execute supported? */
20622+ btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
20623 jnc 1f
20624 btsl $_EFER_NX, %eax
20625 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
20626+ leaq init_level4_pgt(%rip), %rdi
20627+#ifndef CONFIG_EFI
20628+ btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
20629+#endif
20630+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
20631+ btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
20632+ btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
20633+ btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
20634 1: wrmsr /* Make changes effective */
20635
20636 /* Setup cr0 */
20637@@ -282,6 +302,7 @@ ENTRY(secondary_startup_64)
20638 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
20639 * address given in m16:64.
20640 */
20641+ pax_set_fptr_mask
20642 movq initial_code(%rip),%rax
20643 pushq $0 # fake return address to stop unwinder
20644 pushq $__KERNEL_CS # set correct cs
20645@@ -388,7 +409,7 @@ ENTRY(early_idt_handler)
20646 call dump_stack
20647 #ifdef CONFIG_KALLSYMS
20648 leaq early_idt_ripmsg(%rip),%rdi
20649- movq 40(%rsp),%rsi # %rip again
20650+ movq 88(%rsp),%rsi # %rip again
20651 call __print_symbol
20652 #endif
20653 #endif /* EARLY_PRINTK */
20654@@ -416,6 +437,7 @@ ENDPROC(early_idt_handler)
20655 early_recursion_flag:
20656 .long 0
20657
20658+ .section .rodata,"a",@progbits
20659 #ifdef CONFIG_EARLY_PRINTK
20660 early_idt_msg:
20661 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
20662@@ -445,27 +467,50 @@ NEXT_PAGE(early_dynamic_pgts)
20663
20664 .data
20665
20666-#ifndef CONFIG_XEN
20667 NEXT_PAGE(init_level4_pgt)
20668- .fill 512,8,0
20669-#else
20670-NEXT_PAGE(init_level4_pgt)
20671- .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20672 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
20673 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20674+ .org init_level4_pgt + L4_VMALLOC_START*8, 0
20675+ .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
20676+ .org init_level4_pgt + L4_VMALLOC_END*8, 0
20677+ .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
20678+ .org init_level4_pgt + L4_VMEMMAP_START*8, 0
20679+ .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20680 .org init_level4_pgt + L4_START_KERNEL*8, 0
20681 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
20682 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
20683
20684+#ifdef CONFIG_PAX_PER_CPU_PGD
20685+NEXT_PAGE(cpu_pgd)
20686+ .rept NR_CPUS
20687+ .fill 512,8,0
20688+ .endr
20689+#endif
20690+
20691 NEXT_PAGE(level3_ident_pgt)
20692 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
20693+#ifdef CONFIG_XEN
20694 .fill 511, 8, 0
20695+#else
20696+ .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
20697+ .fill 510,8,0
20698+#endif
20699+
20700+NEXT_PAGE(level3_vmalloc_start_pgt)
20701+ .fill 512,8,0
20702+
20703+NEXT_PAGE(level3_vmalloc_end_pgt)
20704+ .fill 512,8,0
20705+
20706+NEXT_PAGE(level3_vmemmap_pgt)
20707+ .fill L3_VMEMMAP_START,8,0
20708+ .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
20709+
20710 NEXT_PAGE(level2_ident_pgt)
20711- /* Since I easily can, map the first 1G.
20712+ /* Since I easily can, map the first 2G.
20713 * Don't set NX because code runs from these pages.
20714 */
20715- PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
20716-#endif
20717+ PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
20718
20719 NEXT_PAGE(level3_kernel_pgt)
20720 .fill L3_START_KERNEL,8,0
20721@@ -473,6 +518,9 @@ NEXT_PAGE(level3_kernel_pgt)
20722 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
20723 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20724
20725+NEXT_PAGE(level2_vmemmap_pgt)
20726+ .fill 512,8,0
20727+
20728 NEXT_PAGE(level2_kernel_pgt)
20729 /*
20730 * 512 MB kernel mapping. We spend a full page on this pagetable
20731@@ -488,39 +536,64 @@ NEXT_PAGE(level2_kernel_pgt)
20732 KERNEL_IMAGE_SIZE/PMD_SIZE)
20733
20734 NEXT_PAGE(level2_fixmap_pgt)
20735- .fill 506,8,0
20736- .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
20737- /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
20738- .fill 5,8,0
20739+ .fill 507,8,0
20740+ .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
20741+ /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
20742+ .fill 4,8,0
20743
20744-NEXT_PAGE(level1_fixmap_pgt)
20745+NEXT_PAGE(level1_vsyscall_pgt)
20746 .fill 512,8,0
20747
20748 #undef PMDS
20749
20750- .data
20751+ .align PAGE_SIZE
20752+ENTRY(cpu_gdt_table)
20753+ .rept NR_CPUS
20754+ .quad 0x0000000000000000 /* NULL descriptor */
20755+ .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
20756+ .quad 0x00af9b000000ffff /* __KERNEL_CS */
20757+ .quad 0x00cf93000000ffff /* __KERNEL_DS */
20758+ .quad 0x00cffb000000ffff /* __USER32_CS */
20759+ .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
20760+ .quad 0x00affb000000ffff /* __USER_CS */
20761+
20762+#ifdef CONFIG_PAX_KERNEXEC
20763+ .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
20764+#else
20765+ .quad 0x0 /* unused */
20766+#endif
20767+
20768+ .quad 0,0 /* TSS */
20769+ .quad 0,0 /* LDT */
20770+ .quad 0,0,0 /* three TLS descriptors */
20771+ .quad 0x0000f40000000000 /* node/CPU stored in limit */
20772+ /* asm/segment.h:GDT_ENTRIES must match this */
20773+
20774+ /* zero the remaining page */
20775+ .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
20776+ .endr
20777+
20778 .align 16
20779 .globl early_gdt_descr
20780 early_gdt_descr:
20781 .word GDT_ENTRIES*8-1
20782 early_gdt_descr_base:
20783- .quad INIT_PER_CPU_VAR(gdt_page)
20784+ .quad cpu_gdt_table
20785
20786 ENTRY(phys_base)
20787 /* This must match the first entry in level2_kernel_pgt */
20788 .quad 0x0000000000000000
20789
20790 #include "../../x86/xen/xen-head.S"
20791-
20792- .section .bss, "aw", @nobits
20793+
20794+ .section .rodata,"a",@progbits
20795 .align L1_CACHE_BYTES
20796 ENTRY(idt_table)
20797- .skip IDT_ENTRIES * 16
20798+ .fill 512,8,0
20799
20800 .align L1_CACHE_BYTES
20801 ENTRY(nmi_idt_table)
20802- .skip IDT_ENTRIES * 16
20803+ .fill 512,8,0
20804
20805- __PAGE_ALIGNED_BSS
20806 NEXT_PAGE(empty_zero_page)
20807 .skip PAGE_SIZE
20808diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
20809index 0fa6912..37fce70 100644
20810--- a/arch/x86/kernel/i386_ksyms_32.c
20811+++ b/arch/x86/kernel/i386_ksyms_32.c
20812@@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
20813 EXPORT_SYMBOL(cmpxchg8b_emu);
20814 #endif
20815
20816+EXPORT_SYMBOL_GPL(cpu_gdt_table);
20817+
20818 /* Networking helper routines. */
20819 EXPORT_SYMBOL(csum_partial_copy_generic);
20820+EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
20821+EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
20822
20823 EXPORT_SYMBOL(__get_user_1);
20824 EXPORT_SYMBOL(__get_user_2);
20825@@ -37,3 +41,7 @@ EXPORT_SYMBOL(strstr);
20826
20827 EXPORT_SYMBOL(csum_partial);
20828 EXPORT_SYMBOL(empty_zero_page);
20829+
20830+#ifdef CONFIG_PAX_KERNEXEC
20831+EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
20832+#endif
20833diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
20834index cb33909..1163b40 100644
20835--- a/arch/x86/kernel/i387.c
20836+++ b/arch/x86/kernel/i387.c
20837@@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
20838 static inline bool interrupted_user_mode(void)
20839 {
20840 struct pt_regs *regs = get_irq_regs();
20841- return regs && user_mode_vm(regs);
20842+ return regs && user_mode(regs);
20843 }
20844
20845 /*
20846diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
20847index 9a5c460..84868423 100644
20848--- a/arch/x86/kernel/i8259.c
20849+++ b/arch/x86/kernel/i8259.c
20850@@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
20851 static void make_8259A_irq(unsigned int irq)
20852 {
20853 disable_irq_nosync(irq);
20854- io_apic_irqs &= ~(1<<irq);
20855+ io_apic_irqs &= ~(1UL<<irq);
20856 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
20857 i8259A_chip.name);
20858 enable_irq(irq);
20859@@ -209,7 +209,7 @@ spurious_8259A_irq:
20860 "spurious 8259A interrupt: IRQ%d.\n", irq);
20861 spurious_irq_mask |= irqmask;
20862 }
20863- atomic_inc(&irq_err_count);
20864+ atomic_inc_unchecked(&irq_err_count);
20865 /*
20866 * Theoretically we do not have to handle this IRQ,
20867 * but in Linux this does not cause problems and is
20868@@ -333,14 +333,16 @@ static void init_8259A(int auto_eoi)
20869 /* (slave's support for AEOI in flat mode is to be investigated) */
20870 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
20871
20872+ pax_open_kernel();
20873 if (auto_eoi)
20874 /*
20875 * In AEOI mode we just have to mask the interrupt
20876 * when acking.
20877 */
20878- i8259A_chip.irq_mask_ack = disable_8259A_irq;
20879+ *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
20880 else
20881- i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20882+ *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
20883+ pax_close_kernel();
20884
20885 udelay(100); /* wait for 8259A to initialize */
20886
20887diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
20888index a979b5b..1d6db75 100644
20889--- a/arch/x86/kernel/io_delay.c
20890+++ b/arch/x86/kernel/io_delay.c
20891@@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
20892 * Quirk table for systems that misbehave (lock up, etc.) if port
20893 * 0x80 is used:
20894 */
20895-static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
20896+static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
20897 {
20898 .callback = dmi_io_delay_0xed_port,
20899 .ident = "Compaq Presario V6000",
20900diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
20901index 4ddaf66..6292f4e 100644
20902--- a/arch/x86/kernel/ioport.c
20903+++ b/arch/x86/kernel/ioport.c
20904@@ -6,6 +6,7 @@
20905 #include <linux/sched.h>
20906 #include <linux/kernel.h>
20907 #include <linux/capability.h>
20908+#include <linux/security.h>
20909 #include <linux/errno.h>
20910 #include <linux/types.h>
20911 #include <linux/ioport.h>
20912@@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20913
20914 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
20915 return -EINVAL;
20916+#ifdef CONFIG_GRKERNSEC_IO
20917+ if (turn_on && grsec_disable_privio) {
20918+ gr_handle_ioperm();
20919+ return -EPERM;
20920+ }
20921+#endif
20922 if (turn_on && !capable(CAP_SYS_RAWIO))
20923 return -EPERM;
20924
20925@@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
20926 * because the ->io_bitmap_max value must match the bitmap
20927 * contents:
20928 */
20929- tss = &per_cpu(init_tss, get_cpu());
20930+ tss = init_tss + get_cpu();
20931
20932 if (turn_on)
20933 bitmap_clear(t->io_bitmap_ptr, from, num);
20934@@ -103,6 +110,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
20935 return -EINVAL;
20936 /* Trying to gain more privileges? */
20937 if (level > old) {
20938+#ifdef CONFIG_GRKERNSEC_IO
20939+ if (grsec_disable_privio) {
20940+ gr_handle_iopl();
20941+ return -EPERM;
20942+ }
20943+#endif
20944 if (!capable(CAP_SYS_RAWIO))
20945 return -EPERM;
20946 }
20947diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
20948index 84b7789..e65e8be 100644
20949--- a/arch/x86/kernel/irq.c
20950+++ b/arch/x86/kernel/irq.c
20951@@ -18,7 +18,7 @@
20952 #include <asm/mce.h>
20953 #include <asm/hw_irq.h>
20954
20955-atomic_t irq_err_count;
20956+atomic_unchecked_t irq_err_count;
20957
20958 /* Function pointer for generic interrupt vector handling */
20959 void (*x86_platform_ipi_callback)(void) = NULL;
20960@@ -122,9 +122,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
20961 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
20962 seq_printf(p, " Machine check polls\n");
20963 #endif
20964- seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
20965+ seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
20966 #if defined(CONFIG_X86_IO_APIC)
20967- seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
20968+ seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
20969 #endif
20970 return 0;
20971 }
20972@@ -164,7 +164,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
20973
20974 u64 arch_irq_stat(void)
20975 {
20976- u64 sum = atomic_read(&irq_err_count);
20977+ u64 sum = atomic_read_unchecked(&irq_err_count);
20978 return sum;
20979 }
20980
20981diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
20982index 344faf8..355f60d 100644
20983--- a/arch/x86/kernel/irq_32.c
20984+++ b/arch/x86/kernel/irq_32.c
20985@@ -39,7 +39,7 @@ static int check_stack_overflow(void)
20986 __asm__ __volatile__("andl %%esp,%0" :
20987 "=r" (sp) : "0" (THREAD_SIZE - 1));
20988
20989- return sp < (sizeof(struct thread_info) + STACK_WARN);
20990+ return sp < STACK_WARN;
20991 }
20992
20993 static void print_stack_overflow(void)
20994@@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
20995 * per-CPU IRQ handling contexts (thread information and stack)
20996 */
20997 union irq_ctx {
20998- struct thread_info tinfo;
20999- u32 stack[THREAD_SIZE/sizeof(u32)];
21000+ unsigned long previous_esp;
21001+ u32 stack[THREAD_SIZE/sizeof(u32)];
21002 } __attribute__((aligned(THREAD_SIZE)));
21003
21004 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
21005@@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
21006 static inline int
21007 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21008 {
21009- union irq_ctx *curctx, *irqctx;
21010+ union irq_ctx *irqctx;
21011 u32 *isp, arg1, arg2;
21012
21013- curctx = (union irq_ctx *) current_thread_info();
21014 irqctx = __this_cpu_read(hardirq_ctx);
21015
21016 /*
21017@@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21018 * handler) we can't do that and just have to keep using the
21019 * current stack (which is the irq stack already after all)
21020 */
21021- if (unlikely(curctx == irqctx))
21022+ if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
21023 return 0;
21024
21025 /* build the stack frame on the IRQ stack */
21026- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21027- irqctx->tinfo.task = curctx->tinfo.task;
21028- irqctx->tinfo.previous_esp = current_stack_pointer;
21029+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21030+ irqctx->previous_esp = current_stack_pointer;
21031
21032- /* Copy the preempt_count so that the [soft]irq checks work. */
21033- irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
21034+#ifdef CONFIG_PAX_MEMORY_UDEREF
21035+ __set_fs(MAKE_MM_SEG(0));
21036+#endif
21037
21038 if (unlikely(overflow))
21039 call_on_stack(print_stack_overflow, isp);
21040@@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21041 : "0" (irq), "1" (desc), "2" (isp),
21042 "D" (desc->handle_irq)
21043 : "memory", "cc", "ecx");
21044+
21045+#ifdef CONFIG_PAX_MEMORY_UDEREF
21046+ __set_fs(current_thread_info()->addr_limit);
21047+#endif
21048+
21049 return 1;
21050 }
21051
21052@@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
21053 */
21054 void __cpuinit irq_ctx_init(int cpu)
21055 {
21056- union irq_ctx *irqctx;
21057-
21058 if (per_cpu(hardirq_ctx, cpu))
21059 return;
21060
21061- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21062- THREADINFO_GFP,
21063- THREAD_SIZE_ORDER));
21064- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21065- irqctx->tinfo.cpu = cpu;
21066- irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
21067- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21068-
21069- per_cpu(hardirq_ctx, cpu) = irqctx;
21070-
21071- irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
21072- THREADINFO_GFP,
21073- THREAD_SIZE_ORDER));
21074- memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
21075- irqctx->tinfo.cpu = cpu;
21076- irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
21077-
21078- per_cpu(softirq_ctx, cpu) = irqctx;
21079+ per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21080+ per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
21081+
21082+ printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21083+ cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21084
21085 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
21086 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
21087@@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
21088 asmlinkage void do_softirq(void)
21089 {
21090 unsigned long flags;
21091- struct thread_info *curctx;
21092 union irq_ctx *irqctx;
21093 u32 *isp;
21094
21095@@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
21096 local_irq_save(flags);
21097
21098 if (local_softirq_pending()) {
21099- curctx = current_thread_info();
21100 irqctx = __this_cpu_read(softirq_ctx);
21101- irqctx->tinfo.task = curctx->task;
21102- irqctx->tinfo.previous_esp = current_stack_pointer;
21103+ irqctx->previous_esp = current_stack_pointer;
21104
21105 /* build the stack frame on the softirq stack */
21106- isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
21107+ isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
21108+
21109+#ifdef CONFIG_PAX_MEMORY_UDEREF
21110+ __set_fs(MAKE_MM_SEG(0));
21111+#endif
21112
21113 call_on_stack(__do_softirq, isp);
21114+
21115+#ifdef CONFIG_PAX_MEMORY_UDEREF
21116+ __set_fs(current_thread_info()->addr_limit);
21117+#endif
21118+
21119 /*
21120 * Shouldn't happen, we returned above if in_interrupt():
21121 */
21122@@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
21123 if (unlikely(!desc))
21124 return false;
21125
21126- if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21127+ if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
21128 if (unlikely(overflow))
21129 print_stack_overflow();
21130 desc->handle_irq(irq, desc);
21131diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
21132index d04d3ec..ea4b374 100644
21133--- a/arch/x86/kernel/irq_64.c
21134+++ b/arch/x86/kernel/irq_64.c
21135@@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
21136 u64 estack_top, estack_bottom;
21137 u64 curbase = (u64)task_stack_page(current);
21138
21139- if (user_mode_vm(regs))
21140+ if (user_mode(regs))
21141 return;
21142
21143 if (regs->sp >= curbase + sizeof(struct thread_info) +
21144diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
21145index dc1404b..bbc43e7 100644
21146--- a/arch/x86/kernel/kdebugfs.c
21147+++ b/arch/x86/kernel/kdebugfs.c
21148@@ -27,7 +27,7 @@ struct setup_data_node {
21149 u32 len;
21150 };
21151
21152-static ssize_t setup_data_read(struct file *file, char __user *user_buf,
21153+static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
21154 size_t count, loff_t *ppos)
21155 {
21156 struct setup_data_node *node = file->private_data;
21157diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
21158index 836f832..a8bda67 100644
21159--- a/arch/x86/kernel/kgdb.c
21160+++ b/arch/x86/kernel/kgdb.c
21161@@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
21162 #ifdef CONFIG_X86_32
21163 switch (regno) {
21164 case GDB_SS:
21165- if (!user_mode_vm(regs))
21166+ if (!user_mode(regs))
21167 *(unsigned long *)mem = __KERNEL_DS;
21168 break;
21169 case GDB_SP:
21170- if (!user_mode_vm(regs))
21171+ if (!user_mode(regs))
21172 *(unsigned long *)mem = kernel_stack_pointer(regs);
21173 break;
21174 case GDB_GS:
21175@@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
21176 bp->attr.bp_addr = breakinfo[breakno].addr;
21177 bp->attr.bp_len = breakinfo[breakno].len;
21178 bp->attr.bp_type = breakinfo[breakno].type;
21179- info->address = breakinfo[breakno].addr;
21180+ if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
21181+ info->address = ktla_ktva(breakinfo[breakno].addr);
21182+ else
21183+ info->address = breakinfo[breakno].addr;
21184 info->len = breakinfo[breakno].len;
21185 info->type = breakinfo[breakno].type;
21186 val = arch_install_hw_breakpoint(bp);
21187@@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
21188 case 'k':
21189 /* clear the trace bit */
21190 linux_regs->flags &= ~X86_EFLAGS_TF;
21191- atomic_set(&kgdb_cpu_doing_single_step, -1);
21192+ atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
21193
21194 /* set the trace bit if we're stepping */
21195 if (remcomInBuffer[0] == 's') {
21196 linux_regs->flags |= X86_EFLAGS_TF;
21197- atomic_set(&kgdb_cpu_doing_single_step,
21198+ atomic_set_unchecked(&kgdb_cpu_doing_single_step,
21199 raw_smp_processor_id());
21200 }
21201
21202@@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
21203
21204 switch (cmd) {
21205 case DIE_DEBUG:
21206- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
21207+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
21208 if (user_mode(regs))
21209 return single_step_cont(regs, args);
21210 break;
21211@@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21212 #endif /* CONFIG_DEBUG_RODATA */
21213
21214 bpt->type = BP_BREAKPOINT;
21215- err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
21216+ err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
21217 BREAK_INSTR_SIZE);
21218 if (err)
21219 return err;
21220- err = probe_kernel_write((char *)bpt->bpt_addr,
21221+ err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21222 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
21223 #ifdef CONFIG_DEBUG_RODATA
21224 if (!err)
21225@@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
21226 return -EBUSY;
21227 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
21228 BREAK_INSTR_SIZE);
21229- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21230+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21231 if (err)
21232 return err;
21233 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
21234@@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
21235 if (mutex_is_locked(&text_mutex))
21236 goto knl_write;
21237 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
21238- err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
21239+ err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
21240 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
21241 goto knl_write;
21242 return err;
21243 knl_write:
21244 #endif /* CONFIG_DEBUG_RODATA */
21245- return probe_kernel_write((char *)bpt->bpt_addr,
21246+ return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
21247 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
21248 }
21249
21250diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
21251index 7bfe318..383d238 100644
21252--- a/arch/x86/kernel/kprobes/core.c
21253+++ b/arch/x86/kernel/kprobes/core.c
21254@@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
21255 s32 raddr;
21256 } __packed *insn;
21257
21258- insn = (struct __arch_relative_insn *)from;
21259+ insn = (struct __arch_relative_insn *)ktla_ktva(from);
21260+
21261+ pax_open_kernel();
21262 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
21263 insn->op = op;
21264+ pax_close_kernel();
21265 }
21266
21267 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
21268@@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
21269 kprobe_opcode_t opcode;
21270 kprobe_opcode_t *orig_opcodes = opcodes;
21271
21272- if (search_exception_tables((unsigned long)opcodes))
21273+ if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
21274 return 0; /* Page fault may occur on this address. */
21275
21276 retry:
21277@@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
21278 * for the first byte, we can recover the original instruction
21279 * from it and kp->opcode.
21280 */
21281- memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21282+ memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
21283 buf[0] = kp->opcode;
21284- return (unsigned long)buf;
21285+ return ktva_ktla((unsigned long)buf);
21286 }
21287
21288 /*
21289@@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21290 /* Another subsystem puts a breakpoint, failed to recover */
21291 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
21292 return 0;
21293+ pax_open_kernel();
21294 memcpy(dest, insn.kaddr, insn.length);
21295+ pax_close_kernel();
21296
21297 #ifdef CONFIG_X86_64
21298 if (insn_rip_relative(&insn)) {
21299@@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
21300 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
21301 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
21302 disp = (u8 *) dest + insn_offset_displacement(&insn);
21303+ pax_open_kernel();
21304 *(s32 *) disp = (s32) newdisp;
21305+ pax_close_kernel();
21306 }
21307 #endif
21308 return insn.length;
21309@@ -488,7 +495,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21310 * nor set current_kprobe, because it doesn't use single
21311 * stepping.
21312 */
21313- regs->ip = (unsigned long)p->ainsn.insn;
21314+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21315 preempt_enable_no_resched();
21316 return;
21317 }
21318@@ -505,9 +512,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
21319 regs->flags &= ~X86_EFLAGS_IF;
21320 /* single step inline if the instruction is an int3 */
21321 if (p->opcode == BREAKPOINT_INSTRUCTION)
21322- regs->ip = (unsigned long)p->addr;
21323+ regs->ip = ktla_ktva((unsigned long)p->addr);
21324 else
21325- regs->ip = (unsigned long)p->ainsn.insn;
21326+ regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
21327 }
21328
21329 /*
21330@@ -586,7 +593,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
21331 setup_singlestep(p, regs, kcb, 0);
21332 return 1;
21333 }
21334- } else if (*addr != BREAKPOINT_INSTRUCTION) {
21335+ } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
21336 /*
21337 * The breakpoint instruction was removed right
21338 * after we hit it. Another cpu has removed
21339@@ -632,6 +639,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
21340 " movq %rax, 152(%rsp)\n"
21341 RESTORE_REGS_STRING
21342 " popfq\n"
21343+#ifdef KERNEXEC_PLUGIN
21344+ " btsq $63,(%rsp)\n"
21345+#endif
21346 #else
21347 " pushf\n"
21348 SAVE_REGS_STRING
21349@@ -769,7 +779,7 @@ static void __kprobes
21350 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
21351 {
21352 unsigned long *tos = stack_addr(regs);
21353- unsigned long copy_ip = (unsigned long)p->ainsn.insn;
21354+ unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
21355 unsigned long orig_ip = (unsigned long)p->addr;
21356 kprobe_opcode_t *insn = p->ainsn.insn;
21357
21358@@ -951,7 +961,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
21359 struct die_args *args = data;
21360 int ret = NOTIFY_DONE;
21361
21362- if (args->regs && user_mode_vm(args->regs))
21363+ if (args->regs && user_mode(args->regs))
21364 return ret;
21365
21366 switch (val) {
21367diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
21368index 76dc6f0..66bdfc3 100644
21369--- a/arch/x86/kernel/kprobes/opt.c
21370+++ b/arch/x86/kernel/kprobes/opt.c
21371@@ -79,6 +79,7 @@ found:
21372 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
21373 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
21374 {
21375+ pax_open_kernel();
21376 #ifdef CONFIG_X86_64
21377 *addr++ = 0x48;
21378 *addr++ = 0xbf;
21379@@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
21380 *addr++ = 0xb8;
21381 #endif
21382 *(unsigned long *)addr = val;
21383+ pax_close_kernel();
21384 }
21385
21386 static void __used __kprobes kprobes_optinsn_template_holder(void)
21387@@ -338,7 +340,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21388 * Verify if the address gap is in 2GB range, because this uses
21389 * a relative jump.
21390 */
21391- rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
21392+ rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
21393 if (abs(rel) > 0x7fffffff)
21394 return -ERANGE;
21395
21396@@ -353,16 +355,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
21397 op->optinsn.size = ret;
21398
21399 /* Copy arch-dep-instance from template */
21400- memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
21401+ pax_open_kernel();
21402+ memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
21403+ pax_close_kernel();
21404
21405 /* Set probe information */
21406 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
21407
21408 /* Set probe function call */
21409- synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
21410+ synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
21411
21412 /* Set returning jmp instruction at the tail of out-of-line buffer */
21413- synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
21414+ synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
21415 (u8 *)op->kp.addr + op->optinsn.size);
21416
21417 flush_icache_range((unsigned long) buf,
21418@@ -385,7 +389,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
21419 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
21420
21421 /* Backup instructions which will be replaced by jump address */
21422- memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
21423+ memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
21424 RELATIVE_ADDR_SIZE);
21425
21426 insn_buf[0] = RELATIVEJUMP_OPCODE;
21427@@ -483,7 +487,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
21428 /* This kprobe is really able to run optimized path. */
21429 op = container_of(p, struct optimized_kprobe, kp);
21430 /* Detour through copied instructions */
21431- regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
21432+ regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
21433 if (!reenter)
21434 reset_current_kprobe();
21435 preempt_enable_no_resched();
21436diff --git a/arch/x86/kernel/kvm.c b/arch/x86/kernel/kvm.c
21437index b686a90..60d36fb 100644
21438--- a/arch/x86/kernel/kvm.c
21439+++ b/arch/x86/kernel/kvm.c
21440@@ -453,7 +453,7 @@ static int __cpuinit kvm_cpu_notify(struct notifier_block *self,
21441 return NOTIFY_OK;
21442 }
21443
21444-static struct notifier_block __cpuinitdata kvm_cpu_notifier = {
21445+static struct notifier_block kvm_cpu_notifier = {
21446 .notifier_call = kvm_cpu_notify,
21447 };
21448 #endif
21449diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
21450index ebc9873..1b9724b 100644
21451--- a/arch/x86/kernel/ldt.c
21452+++ b/arch/x86/kernel/ldt.c
21453@@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
21454 if (reload) {
21455 #ifdef CONFIG_SMP
21456 preempt_disable();
21457- load_LDT(pc);
21458+ load_LDT_nolock(pc);
21459 if (!cpumask_equal(mm_cpumask(current->mm),
21460 cpumask_of(smp_processor_id())))
21461 smp_call_function(flush_ldt, current->mm, 1);
21462 preempt_enable();
21463 #else
21464- load_LDT(pc);
21465+ load_LDT_nolock(pc);
21466 #endif
21467 }
21468 if (oldsize) {
21469@@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
21470 return err;
21471
21472 for (i = 0; i < old->size; i++)
21473- write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
21474+ write_ldt_entry(new->ldt, i, old->ldt + i);
21475 return 0;
21476 }
21477
21478@@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
21479 retval = copy_ldt(&mm->context, &old_mm->context);
21480 mutex_unlock(&old_mm->context.lock);
21481 }
21482+
21483+ if (tsk == current) {
21484+ mm->context.vdso = 0;
21485+
21486+#ifdef CONFIG_X86_32
21487+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
21488+ mm->context.user_cs_base = 0UL;
21489+ mm->context.user_cs_limit = ~0UL;
21490+
21491+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
21492+ cpus_clear(mm->context.cpu_user_cs_mask);
21493+#endif
21494+
21495+#endif
21496+#endif
21497+
21498+ }
21499+
21500 return retval;
21501 }
21502
21503@@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
21504 }
21505 }
21506
21507+#ifdef CONFIG_PAX_SEGMEXEC
21508+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
21509+ error = -EINVAL;
21510+ goto out_unlock;
21511+ }
21512+#endif
21513+
21514 fill_ldt(&ldt, &ldt_info);
21515 if (oldmode)
21516 ldt.avl = 0;
21517diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
21518index 5b19e4d..6476a76 100644
21519--- a/arch/x86/kernel/machine_kexec_32.c
21520+++ b/arch/x86/kernel/machine_kexec_32.c
21521@@ -26,7 +26,7 @@
21522 #include <asm/cacheflush.h>
21523 #include <asm/debugreg.h>
21524
21525-static void set_idt(void *newidt, __u16 limit)
21526+static void set_idt(struct desc_struct *newidt, __u16 limit)
21527 {
21528 struct desc_ptr curidt;
21529
21530@@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
21531 }
21532
21533
21534-static void set_gdt(void *newgdt, __u16 limit)
21535+static void set_gdt(struct desc_struct *newgdt, __u16 limit)
21536 {
21537 struct desc_ptr curgdt;
21538
21539@@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
21540 }
21541
21542 control_page = page_address(image->control_code_page);
21543- memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
21544+ memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
21545
21546 relocate_kernel_ptr = control_page;
21547 page_list[PA_CONTROL_PAGE] = __pa(control_page);
21548diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
21549index 22db92b..d546bec 100644
21550--- a/arch/x86/kernel/microcode_core.c
21551+++ b/arch/x86/kernel/microcode_core.c
21552@@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21553 return NOTIFY_OK;
21554 }
21555
21556-static struct notifier_block __refdata mc_cpu_notifier = {
21557+static struct notifier_block mc_cpu_notifier = {
21558 .notifier_call = mc_cpu_callback,
21559 };
21560
21561diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
21562index 5fb2ceb..3ae90bb 100644
21563--- a/arch/x86/kernel/microcode_intel.c
21564+++ b/arch/x86/kernel/microcode_intel.c
21565@@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21566
21567 static int get_ucode_user(void *to, const void *from, size_t n)
21568 {
21569- return copy_from_user(to, from, n);
21570+ return copy_from_user(to, (const void __force_user *)from, n);
21571 }
21572
21573 static enum ucode_state
21574 request_microcode_user(int cpu, const void __user *buf, size_t size)
21575 {
21576- return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21577+ return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21578 }
21579
21580 static void microcode_fini_cpu(int cpu)
21581diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
21582index 216a4d7..228255a 100644
21583--- a/arch/x86/kernel/module.c
21584+++ b/arch/x86/kernel/module.c
21585@@ -43,15 +43,60 @@ do { \
21586 } while (0)
21587 #endif
21588
21589-void *module_alloc(unsigned long size)
21590+static inline void *__module_alloc(unsigned long size, pgprot_t prot)
21591 {
21592- if (PAGE_ALIGN(size) > MODULES_LEN)
21593+ if (!size || PAGE_ALIGN(size) > MODULES_LEN)
21594 return NULL;
21595 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
21596- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
21597+ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
21598 -1, __builtin_return_address(0));
21599 }
21600
21601+void *module_alloc(unsigned long size)
21602+{
21603+
21604+#ifdef CONFIG_PAX_KERNEXEC
21605+ return __module_alloc(size, PAGE_KERNEL);
21606+#else
21607+ return __module_alloc(size, PAGE_KERNEL_EXEC);
21608+#endif
21609+
21610+}
21611+
21612+#ifdef CONFIG_PAX_KERNEXEC
21613+#ifdef CONFIG_X86_32
21614+void *module_alloc_exec(unsigned long size)
21615+{
21616+ struct vm_struct *area;
21617+
21618+ if (size == 0)
21619+ return NULL;
21620+
21621+ area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
21622+ return area ? area->addr : NULL;
21623+}
21624+EXPORT_SYMBOL(module_alloc_exec);
21625+
21626+void module_free_exec(struct module *mod, void *module_region)
21627+{
21628+ vunmap(module_region);
21629+}
21630+EXPORT_SYMBOL(module_free_exec);
21631+#else
21632+void module_free_exec(struct module *mod, void *module_region)
21633+{
21634+ module_free(mod, module_region);
21635+}
21636+EXPORT_SYMBOL(module_free_exec);
21637+
21638+void *module_alloc_exec(unsigned long size)
21639+{
21640+ return __module_alloc(size, PAGE_KERNEL_RX);
21641+}
21642+EXPORT_SYMBOL(module_alloc_exec);
21643+#endif
21644+#endif
21645+
21646 #ifdef CONFIG_X86_32
21647 int apply_relocate(Elf32_Shdr *sechdrs,
21648 const char *strtab,
21649@@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21650 unsigned int i;
21651 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
21652 Elf32_Sym *sym;
21653- uint32_t *location;
21654+ uint32_t *plocation, location;
21655
21656 DEBUGP("Applying relocate section %u to %u\n",
21657 relsec, sechdrs[relsec].sh_info);
21658 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
21659 /* This is where to make the change */
21660- location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
21661- + rel[i].r_offset;
21662+ plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
21663+ location = (uint32_t)plocation;
21664+ if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
21665+ plocation = ktla_ktva((void *)plocation);
21666 /* This is the symbol it is referring to. Note that all
21667 undefined symbols have been resolved. */
21668 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
21669@@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
21670 switch (ELF32_R_TYPE(rel[i].r_info)) {
21671 case R_386_32:
21672 /* We add the value into the location given */
21673- *location += sym->st_value;
21674+ pax_open_kernel();
21675+ *plocation += sym->st_value;
21676+ pax_close_kernel();
21677 break;
21678 case R_386_PC32:
21679 /* Add the value, subtract its position */
21680- *location += sym->st_value - (uint32_t)location;
21681+ pax_open_kernel();
21682+ *plocation += sym->st_value - location;
21683+ pax_close_kernel();
21684 break;
21685 default:
21686 pr_err("%s: Unknown relocation: %u\n",
21687@@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
21688 case R_X86_64_NONE:
21689 break;
21690 case R_X86_64_64:
21691+ pax_open_kernel();
21692 *(u64 *)loc = val;
21693+ pax_close_kernel();
21694 break;
21695 case R_X86_64_32:
21696+ pax_open_kernel();
21697 *(u32 *)loc = val;
21698+ pax_close_kernel();
21699 if (val != *(u32 *)loc)
21700 goto overflow;
21701 break;
21702 case R_X86_64_32S:
21703+ pax_open_kernel();
21704 *(s32 *)loc = val;
21705+ pax_close_kernel();
21706 if ((s64)val != *(s32 *)loc)
21707 goto overflow;
21708 break;
21709 case R_X86_64_PC32:
21710 val -= (u64)loc;
21711+ pax_open_kernel();
21712 *(u32 *)loc = val;
21713+ pax_close_kernel();
21714+
21715 #if 0
21716 if ((s64)val != *(s32 *)loc)
21717 goto overflow;
21718diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
21719index ce13049..e2e9c3c 100644
21720--- a/arch/x86/kernel/msr.c
21721+++ b/arch/x86/kernel/msr.c
21722@@ -233,7 +233,7 @@ static int __cpuinit msr_class_cpu_callback(struct notifier_block *nfb,
21723 return notifier_from_errno(err);
21724 }
21725
21726-static struct notifier_block __refdata msr_class_cpu_notifier = {
21727+static struct notifier_block msr_class_cpu_notifier = {
21728 .notifier_call = msr_class_cpu_callback,
21729 };
21730
21731diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
21732index 6030805..2d33f21 100644
21733--- a/arch/x86/kernel/nmi.c
21734+++ b/arch/x86/kernel/nmi.c
21735@@ -105,7 +105,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
21736 return handled;
21737 }
21738
21739-int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21740+int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
21741 {
21742 struct nmi_desc *desc = nmi_to_desc(type);
21743 unsigned long flags;
21744@@ -129,9 +129,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
21745 * event confuses some handlers (kdump uses this flag)
21746 */
21747 if (action->flags & NMI_FLAG_FIRST)
21748- list_add_rcu(&action->list, &desc->head);
21749+ pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
21750 else
21751- list_add_tail_rcu(&action->list, &desc->head);
21752+ pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
21753
21754 spin_unlock_irqrestore(&desc->lock, flags);
21755 return 0;
21756@@ -154,7 +154,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
21757 if (!strcmp(n->name, name)) {
21758 WARN(in_nmi(),
21759 "Trying to free NMI (%s) from NMI context!\n", n->name);
21760- list_del_rcu(&n->list);
21761+ pax_list_del_rcu((struct list_head *)&n->list);
21762 break;
21763 }
21764 }
21765@@ -479,6 +479,17 @@ static inline void nmi_nesting_postprocess(void)
21766 dotraplinkage notrace __kprobes void
21767 do_nmi(struct pt_regs *regs, long error_code)
21768 {
21769+
21770+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
21771+ if (!user_mode(regs)) {
21772+ unsigned long cs = regs->cs & 0xFFFF;
21773+ unsigned long ip = ktva_ktla(regs->ip);
21774+
21775+ if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
21776+ regs->ip = ip;
21777+ }
21778+#endif
21779+
21780 nmi_nesting_preprocess(regs);
21781
21782 nmi_enter();
21783diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
21784index 6d9582e..f746287 100644
21785--- a/arch/x86/kernel/nmi_selftest.c
21786+++ b/arch/x86/kernel/nmi_selftest.c
21787@@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
21788 {
21789 /* trap all the unknown NMIs we may generate */
21790 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
21791- __initdata);
21792+ __initconst);
21793 }
21794
21795 static void __init cleanup_nmi_testsuite(void)
21796@@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
21797 unsigned long timeout;
21798
21799 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
21800- NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
21801+ NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
21802 nmi_fail = FAILURE;
21803 return;
21804 }
21805diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
21806index 676b8c7..870ba04 100644
21807--- a/arch/x86/kernel/paravirt-spinlocks.c
21808+++ b/arch/x86/kernel/paravirt-spinlocks.c
21809@@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
21810 arch_spin_lock(lock);
21811 }
21812
21813-struct pv_lock_ops pv_lock_ops = {
21814+struct pv_lock_ops pv_lock_ops __read_only = {
21815 #ifdef CONFIG_SMP
21816 .spin_is_locked = __ticket_spin_is_locked,
21817 .spin_is_contended = __ticket_spin_is_contended,
21818diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
21819index 8bfb335..c1463c6 100644
21820--- a/arch/x86/kernel/paravirt.c
21821+++ b/arch/x86/kernel/paravirt.c
21822@@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
21823 {
21824 return x;
21825 }
21826+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21827+PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
21828+#endif
21829
21830 void __init default_banner(void)
21831 {
21832@@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
21833 if (opfunc == NULL)
21834 /* If there's no function, patch it with a ud2a (BUG) */
21835 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
21836- else if (opfunc == _paravirt_nop)
21837+ else if (opfunc == (void *)_paravirt_nop)
21838 /* If the operation is a nop, then nop the callsite */
21839 ret = paravirt_patch_nop();
21840
21841 /* identity functions just return their single argument */
21842- else if (opfunc == _paravirt_ident_32)
21843+ else if (opfunc == (void *)_paravirt_ident_32)
21844 ret = paravirt_patch_ident_32(insnbuf, len);
21845- else if (opfunc == _paravirt_ident_64)
21846+ else if (opfunc == (void *)_paravirt_ident_64)
21847 ret = paravirt_patch_ident_64(insnbuf, len);
21848+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
21849+ else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
21850+ ret = paravirt_patch_ident_64(insnbuf, len);
21851+#endif
21852
21853 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
21854 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
21855@@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
21856 if (insn_len > len || start == NULL)
21857 insn_len = len;
21858 else
21859- memcpy(insnbuf, start, insn_len);
21860+ memcpy(insnbuf, ktla_ktva(start), insn_len);
21861
21862 return insn_len;
21863 }
21864@@ -304,7 +311,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
21865 return this_cpu_read(paravirt_lazy_mode);
21866 }
21867
21868-struct pv_info pv_info = {
21869+struct pv_info pv_info __read_only = {
21870 .name = "bare hardware",
21871 .paravirt_enabled = 0,
21872 .kernel_rpl = 0,
21873@@ -315,16 +322,16 @@ struct pv_info pv_info = {
21874 #endif
21875 };
21876
21877-struct pv_init_ops pv_init_ops = {
21878+struct pv_init_ops pv_init_ops __read_only = {
21879 .patch = native_patch,
21880 };
21881
21882-struct pv_time_ops pv_time_ops = {
21883+struct pv_time_ops pv_time_ops __read_only = {
21884 .sched_clock = native_sched_clock,
21885 .steal_clock = native_steal_clock,
21886 };
21887
21888-struct pv_irq_ops pv_irq_ops = {
21889+struct pv_irq_ops pv_irq_ops __read_only = {
21890 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
21891 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
21892 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
21893@@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
21894 #endif
21895 };
21896
21897-struct pv_cpu_ops pv_cpu_ops = {
21898+struct pv_cpu_ops pv_cpu_ops __read_only = {
21899 .cpuid = native_cpuid,
21900 .get_debugreg = native_get_debugreg,
21901 .set_debugreg = native_set_debugreg,
21902@@ -395,21 +402,26 @@ struct pv_cpu_ops pv_cpu_ops = {
21903 .end_context_switch = paravirt_nop,
21904 };
21905
21906-struct pv_apic_ops pv_apic_ops = {
21907+struct pv_apic_ops pv_apic_ops __read_only= {
21908 #ifdef CONFIG_X86_LOCAL_APIC
21909 .startup_ipi_hook = paravirt_nop,
21910 #endif
21911 };
21912
21913-#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
21914+#ifdef CONFIG_X86_32
21915+#ifdef CONFIG_X86_PAE
21916+/* 64-bit pagetable entries */
21917+#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
21918+#else
21919 /* 32-bit pagetable entries */
21920 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
21921+#endif
21922 #else
21923 /* 64-bit pagetable entries */
21924 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
21925 #endif
21926
21927-struct pv_mmu_ops pv_mmu_ops = {
21928+struct pv_mmu_ops pv_mmu_ops __read_only = {
21929
21930 .read_cr2 = native_read_cr2,
21931 .write_cr2 = native_write_cr2,
21932@@ -459,6 +471,7 @@ struct pv_mmu_ops pv_mmu_ops = {
21933 .make_pud = PTE_IDENT,
21934
21935 .set_pgd = native_set_pgd,
21936+ .set_pgd_batched = native_set_pgd_batched,
21937 #endif
21938 #endif /* PAGETABLE_LEVELS >= 3 */
21939
21940@@ -479,6 +492,12 @@ struct pv_mmu_ops pv_mmu_ops = {
21941 },
21942
21943 .set_fixmap = native_set_fixmap,
21944+
21945+#ifdef CONFIG_PAX_KERNEXEC
21946+ .pax_open_kernel = native_pax_open_kernel,
21947+ .pax_close_kernel = native_pax_close_kernel,
21948+#endif
21949+
21950 };
21951
21952 EXPORT_SYMBOL_GPL(pv_time_ops);
21953diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
21954index 299d493..2ccb0ee 100644
21955--- a/arch/x86/kernel/pci-calgary_64.c
21956+++ b/arch/x86/kernel/pci-calgary_64.c
21957@@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
21958 tce_space = be64_to_cpu(readq(target));
21959 tce_space = tce_space & TAR_SW_BITS;
21960
21961- tce_space = tce_space & (~specified_table_size);
21962+ tce_space = tce_space & (~(unsigned long)specified_table_size);
21963 info->tce_space = (u64 *)__va(tce_space);
21964 }
21965 }
21966diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
21967index 35ccf75..7a15747 100644
21968--- a/arch/x86/kernel/pci-iommu_table.c
21969+++ b/arch/x86/kernel/pci-iommu_table.c
21970@@ -2,7 +2,7 @@
21971 #include <asm/iommu_table.h>
21972 #include <linux/string.h>
21973 #include <linux/kallsyms.h>
21974-
21975+#include <linux/sched.h>
21976
21977 #define DEBUG 1
21978
21979diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
21980index 6c483ba..d10ce2f 100644
21981--- a/arch/x86/kernel/pci-swiotlb.c
21982+++ b/arch/x86/kernel/pci-swiotlb.c
21983@@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
21984 void *vaddr, dma_addr_t dma_addr,
21985 struct dma_attrs *attrs)
21986 {
21987- swiotlb_free_coherent(dev, size, vaddr, dma_addr);
21988+ swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
21989 }
21990
21991 static struct dma_map_ops swiotlb_dma_ops = {
21992diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
21993index 14ae100..752a4f6 100644
21994--- a/arch/x86/kernel/process.c
21995+++ b/arch/x86/kernel/process.c
21996@@ -36,7 +36,8 @@
21997 * section. Since TSS's are completely CPU-local, we want them
21998 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
21999 */
22000-DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
22001+struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
22002+EXPORT_SYMBOL(init_tss);
22003
22004 #ifdef CONFIG_X86_64
22005 static DEFINE_PER_CPU(unsigned char, is_idle);
22006@@ -92,7 +93,7 @@ void arch_task_cache_init(void)
22007 task_xstate_cachep =
22008 kmem_cache_create("task_xstate", xstate_size,
22009 __alignof__(union thread_xstate),
22010- SLAB_PANIC | SLAB_NOTRACK, NULL);
22011+ SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
22012 }
22013
22014 /*
22015@@ -105,7 +106,7 @@ void exit_thread(void)
22016 unsigned long *bp = t->io_bitmap_ptr;
22017
22018 if (bp) {
22019- struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
22020+ struct tss_struct *tss = init_tss + get_cpu();
22021
22022 t->io_bitmap_ptr = NULL;
22023 clear_thread_flag(TIF_IO_BITMAP);
22024@@ -136,7 +137,7 @@ void show_regs_common(void)
22025 board = dmi_get_system_info(DMI_BOARD_NAME);
22026
22027 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s %s %s%s%s\n",
22028- current->pid, current->comm, print_tainted(),
22029+ task_pid_nr(current), current->comm, print_tainted(),
22030 init_utsname()->release,
22031 (int)strcspn(init_utsname()->version, " "),
22032 init_utsname()->version,
22033@@ -149,6 +150,9 @@ void flush_thread(void)
22034 {
22035 struct task_struct *tsk = current;
22036
22037+#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
22038+ loadsegment(gs, 0);
22039+#endif
22040 flush_ptrace_hw_breakpoint(tsk);
22041 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
22042 drop_init_fpu(tsk);
22043@@ -295,7 +299,7 @@ static void __exit_idle(void)
22044 void exit_idle(void)
22045 {
22046 /* idle loop has pid 0 */
22047- if (current->pid)
22048+ if (task_pid_nr(current))
22049 return;
22050 __exit_idle();
22051 }
22052@@ -398,7 +402,7 @@ bool xen_set_default_idle(void)
22053 return ret;
22054 }
22055 #endif
22056-void stop_this_cpu(void *dummy)
22057+__noreturn void stop_this_cpu(void *dummy)
22058 {
22059 local_irq_disable();
22060 /*
22061@@ -544,16 +548,37 @@ static int __init idle_setup(char *str)
22062 }
22063 early_param("idle", idle_setup);
22064
22065-unsigned long arch_align_stack(unsigned long sp)
22066+#ifdef CONFIG_PAX_RANDKSTACK
22067+void pax_randomize_kstack(struct pt_regs *regs)
22068 {
22069- if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
22070- sp -= get_random_int() % 8192;
22071- return sp & ~0xf;
22072-}
22073+ struct thread_struct *thread = &current->thread;
22074+ unsigned long time;
22075
22076-unsigned long arch_randomize_brk(struct mm_struct *mm)
22077-{
22078- unsigned long range_end = mm->brk + 0x02000000;
22079- return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
22080-}
22081+ if (!randomize_va_space)
22082+ return;
22083+
22084+ if (v8086_mode(regs))
22085+ return;
22086
22087+ rdtscl(time);
22088+
22089+ /* P4 seems to return a 0 LSB, ignore it */
22090+#ifdef CONFIG_MPENTIUM4
22091+ time &= 0x3EUL;
22092+ time <<= 2;
22093+#elif defined(CONFIG_X86_64)
22094+ time &= 0xFUL;
22095+ time <<= 4;
22096+#else
22097+ time &= 0x1FUL;
22098+ time <<= 3;
22099+#endif
22100+
22101+ thread->sp0 ^= time;
22102+ load_sp0(init_tss + smp_processor_id(), thread);
22103+
22104+#ifdef CONFIG_X86_64
22105+ this_cpu_write(kernel_stack, thread->sp0);
22106+#endif
22107+}
22108+#endif
22109diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
22110index b5a8905..d9cacac 100644
22111--- a/arch/x86/kernel/process_32.c
22112+++ b/arch/x86/kernel/process_32.c
22113@@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
22114 unsigned long thread_saved_pc(struct task_struct *tsk)
22115 {
22116 return ((unsigned long *)tsk->thread.sp)[3];
22117+//XXX return tsk->thread.eip;
22118 }
22119
22120 void __show_regs(struct pt_regs *regs, int all)
22121@@ -74,21 +75,20 @@ void __show_regs(struct pt_regs *regs, int all)
22122 unsigned long sp;
22123 unsigned short ss, gs;
22124
22125- if (user_mode_vm(regs)) {
22126+ if (user_mode(regs)) {
22127 sp = regs->sp;
22128 ss = regs->ss & 0xffff;
22129- gs = get_user_gs(regs);
22130 } else {
22131 sp = kernel_stack_pointer(regs);
22132 savesegment(ss, ss);
22133- savesegment(gs, gs);
22134 }
22135+ gs = get_user_gs(regs);
22136
22137 show_regs_common();
22138
22139 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
22140 (u16)regs->cs, regs->ip, regs->flags,
22141- smp_processor_id());
22142+ raw_smp_processor_id());
22143 print_symbol("EIP is at %s\n", regs->ip);
22144
22145 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
22146@@ -130,20 +130,21 @@ void release_thread(struct task_struct *dead_task)
22147 int copy_thread(unsigned long clone_flags, unsigned long sp,
22148 unsigned long arg, struct task_struct *p)
22149 {
22150- struct pt_regs *childregs = task_pt_regs(p);
22151+ struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
22152 struct task_struct *tsk;
22153 int err;
22154
22155 p->thread.sp = (unsigned long) childregs;
22156 p->thread.sp0 = (unsigned long) (childregs+1);
22157+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22158
22159 if (unlikely(p->flags & PF_KTHREAD)) {
22160 /* kernel thread */
22161 memset(childregs, 0, sizeof(struct pt_regs));
22162 p->thread.ip = (unsigned long) ret_from_kernel_thread;
22163- task_user_gs(p) = __KERNEL_STACK_CANARY;
22164- childregs->ds = __USER_DS;
22165- childregs->es = __USER_DS;
22166+ savesegment(gs, childregs->gs);
22167+ childregs->ds = __KERNEL_DS;
22168+ childregs->es = __KERNEL_DS;
22169 childregs->fs = __KERNEL_PERCPU;
22170 childregs->bx = sp; /* function */
22171 childregs->bp = arg;
22172@@ -250,7 +251,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22173 struct thread_struct *prev = &prev_p->thread,
22174 *next = &next_p->thread;
22175 int cpu = smp_processor_id();
22176- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22177+ struct tss_struct *tss = init_tss + cpu;
22178 fpu_switch_t fpu;
22179
22180 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
22181@@ -274,6 +275,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22182 */
22183 lazy_save_gs(prev->gs);
22184
22185+#ifdef CONFIG_PAX_MEMORY_UDEREF
22186+ __set_fs(task_thread_info(next_p)->addr_limit);
22187+#endif
22188+
22189 /*
22190 * Load the per-thread Thread-Local Storage descriptor.
22191 */
22192@@ -304,6 +309,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22193 */
22194 arch_end_context_switch(next_p);
22195
22196+ this_cpu_write(current_task, next_p);
22197+ this_cpu_write(current_tinfo, &next_p->tinfo);
22198+
22199 /*
22200 * Restore %gs if needed (which is common)
22201 */
22202@@ -312,8 +320,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22203
22204 switch_fpu_finish(next_p, fpu);
22205
22206- this_cpu_write(current_task, next_p);
22207-
22208 return prev_p;
22209 }
22210
22211@@ -343,4 +349,3 @@ unsigned long get_wchan(struct task_struct *p)
22212 } while (count++ < 16);
22213 return 0;
22214 }
22215-
22216diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
22217index 0f49677..fcbf88c 100644
22218--- a/arch/x86/kernel/process_64.c
22219+++ b/arch/x86/kernel/process_64.c
22220@@ -152,10 +152,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
22221 struct pt_regs *childregs;
22222 struct task_struct *me = current;
22223
22224- p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
22225+ p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
22226 childregs = task_pt_regs(p);
22227 p->thread.sp = (unsigned long) childregs;
22228 p->thread.usersp = me->thread.usersp;
22229+ p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
22230 set_tsk_thread_flag(p, TIF_FORK);
22231 p->fpu_counter = 0;
22232 p->thread.io_bitmap_ptr = NULL;
22233@@ -274,7 +275,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22234 struct thread_struct *prev = &prev_p->thread;
22235 struct thread_struct *next = &next_p->thread;
22236 int cpu = smp_processor_id();
22237- struct tss_struct *tss = &per_cpu(init_tss, cpu);
22238+ struct tss_struct *tss = init_tss + cpu;
22239 unsigned fsindex, gsindex;
22240 fpu_switch_t fpu;
22241
22242@@ -356,10 +357,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
22243 prev->usersp = this_cpu_read(old_rsp);
22244 this_cpu_write(old_rsp, next->usersp);
22245 this_cpu_write(current_task, next_p);
22246+ this_cpu_write(current_tinfo, &next_p->tinfo);
22247
22248- this_cpu_write(kernel_stack,
22249- (unsigned long)task_stack_page(next_p) +
22250- THREAD_SIZE - KERNEL_STACK_OFFSET);
22251+ this_cpu_write(kernel_stack, next->sp0);
22252
22253 /*
22254 * Now maybe reload the debug registers and handle I/O bitmaps
22255@@ -428,12 +428,11 @@ unsigned long get_wchan(struct task_struct *p)
22256 if (!p || p == current || p->state == TASK_RUNNING)
22257 return 0;
22258 stack = (unsigned long)task_stack_page(p);
22259- if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
22260+ if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
22261 return 0;
22262 fp = *(u64 *)(p->thread.sp);
22263 do {
22264- if (fp < (unsigned long)stack ||
22265- fp >= (unsigned long)stack+THREAD_SIZE)
22266+ if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
22267 return 0;
22268 ip = *(u64 *)(fp+8);
22269 if (!in_sched_functions(ip))
22270diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
22271index 29a8120..a50b5ee 100644
22272--- a/arch/x86/kernel/ptrace.c
22273+++ b/arch/x86/kernel/ptrace.c
22274@@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
22275 {
22276 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
22277 unsigned long sp = (unsigned long)&regs->sp;
22278- struct thread_info *tinfo;
22279
22280- if (context == (sp & ~(THREAD_SIZE - 1)))
22281+ if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
22282 return sp;
22283
22284- tinfo = (struct thread_info *)context;
22285- if (tinfo->previous_esp)
22286- return tinfo->previous_esp;
22287+ sp = *(unsigned long *)context;
22288+ if (sp)
22289+ return sp;
22290
22291 return (unsigned long)regs;
22292 }
22293@@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
22294 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
22295 {
22296 int i;
22297- int dr7 = 0;
22298+ unsigned long dr7 = 0;
22299 struct arch_hw_breakpoint *info;
22300
22301 for (i = 0; i < HBP_NUM; i++) {
22302@@ -856,7 +855,7 @@ long arch_ptrace(struct task_struct *child, long request,
22303 unsigned long addr, unsigned long data)
22304 {
22305 int ret;
22306- unsigned long __user *datap = (unsigned long __user *)data;
22307+ unsigned long __user *datap = (__force unsigned long __user *)data;
22308
22309 switch (request) {
22310 /* read the word at location addr in the USER area. */
22311@@ -941,14 +940,14 @@ long arch_ptrace(struct task_struct *child, long request,
22312 if ((int) addr < 0)
22313 return -EIO;
22314 ret = do_get_thread_area(child, addr,
22315- (struct user_desc __user *)data);
22316+ (__force struct user_desc __user *) data);
22317 break;
22318
22319 case PTRACE_SET_THREAD_AREA:
22320 if ((int) addr < 0)
22321 return -EIO;
22322 ret = do_set_thread_area(child, addr,
22323- (struct user_desc __user *)data, 0);
22324+ (__force struct user_desc __user *) data, 0);
22325 break;
22326 #endif
22327
22328@@ -1326,7 +1325,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
22329
22330 #ifdef CONFIG_X86_64
22331
22332-static struct user_regset x86_64_regsets[] __read_mostly = {
22333+static user_regset_no_const x86_64_regsets[] __read_only = {
22334 [REGSET_GENERAL] = {
22335 .core_note_type = NT_PRSTATUS,
22336 .n = sizeof(struct user_regs_struct) / sizeof(long),
22337@@ -1367,7 +1366,7 @@ static const struct user_regset_view user_x86_64_view = {
22338 #endif /* CONFIG_X86_64 */
22339
22340 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
22341-static struct user_regset x86_32_regsets[] __read_mostly = {
22342+static user_regset_no_const x86_32_regsets[] __read_only = {
22343 [REGSET_GENERAL] = {
22344 .core_note_type = NT_PRSTATUS,
22345 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
22346@@ -1420,7 +1419,7 @@ static const struct user_regset_view user_x86_32_view = {
22347 */
22348 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
22349
22350-void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22351+void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
22352 {
22353 #ifdef CONFIG_X86_64
22354 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
22355@@ -1455,7 +1454,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
22356 memset(info, 0, sizeof(*info));
22357 info->si_signo = SIGTRAP;
22358 info->si_code = si_code;
22359- info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
22360+ info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
22361 }
22362
22363 void user_single_step_siginfo(struct task_struct *tsk,
22364@@ -1484,6 +1483,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
22365 # define IS_IA32 0
22366 #endif
22367
22368+#ifdef CONFIG_GRKERNSEC_SETXID
22369+extern void gr_delayed_cred_worker(void);
22370+#endif
22371+
22372 /*
22373 * We must return the syscall number to actually look up in the table.
22374 * This can be -1L to skip running any syscall at all.
22375@@ -1494,6 +1497,11 @@ long syscall_trace_enter(struct pt_regs *regs)
22376
22377 user_exit();
22378
22379+#ifdef CONFIG_GRKERNSEC_SETXID
22380+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22381+ gr_delayed_cred_worker();
22382+#endif
22383+
22384 /*
22385 * If we stepped into a sysenter/syscall insn, it trapped in
22386 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
22387@@ -1549,6 +1557,11 @@ void syscall_trace_leave(struct pt_regs *regs)
22388 */
22389 user_exit();
22390
22391+#ifdef CONFIG_GRKERNSEC_SETXID
22392+ if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
22393+ gr_delayed_cred_worker();
22394+#endif
22395+
22396 audit_syscall_exit(regs);
22397
22398 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
22399diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
22400index 2cb9470..ff1fd80 100644
22401--- a/arch/x86/kernel/pvclock.c
22402+++ b/arch/x86/kernel/pvclock.c
22403@@ -43,11 +43,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
22404 return pv_tsc_khz;
22405 }
22406
22407-static atomic64_t last_value = ATOMIC64_INIT(0);
22408+static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
22409
22410 void pvclock_resume(void)
22411 {
22412- atomic64_set(&last_value, 0);
22413+ atomic64_set_unchecked(&last_value, 0);
22414 }
22415
22416 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
22417@@ -92,11 +92,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
22418 * updating at the same time, and one of them could be slightly behind,
22419 * making the assumption that last_value always go forward fail to hold.
22420 */
22421- last = atomic64_read(&last_value);
22422+ last = atomic64_read_unchecked(&last_value);
22423 do {
22424 if (ret < last)
22425 return last;
22426- last = atomic64_cmpxchg(&last_value, last, ret);
22427+ last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
22428 } while (unlikely(last != ret));
22429
22430 return ret;
22431diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
22432index 76fa1e9..abf09ea 100644
22433--- a/arch/x86/kernel/reboot.c
22434+++ b/arch/x86/kernel/reboot.c
22435@@ -36,7 +36,7 @@ void (*pm_power_off)(void);
22436 EXPORT_SYMBOL(pm_power_off);
22437
22438 static const struct desc_ptr no_idt = {};
22439-static int reboot_mode;
22440+static unsigned short reboot_mode;
22441 enum reboot_type reboot_type = BOOT_ACPI;
22442 int reboot_force;
22443
22444@@ -157,6 +157,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
22445
22446 void __noreturn machine_real_restart(unsigned int type)
22447 {
22448+
22449+#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
22450+ struct desc_struct *gdt;
22451+#endif
22452+
22453 local_irq_disable();
22454
22455 /*
22456@@ -184,7 +189,29 @@ void __noreturn machine_real_restart(unsigned int type)
22457
22458 /* Jump to the identity-mapped low memory code */
22459 #ifdef CONFIG_X86_32
22460- asm volatile("jmpl *%0" : :
22461+
22462+#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22463+ gdt = get_cpu_gdt_table(smp_processor_id());
22464+ pax_open_kernel();
22465+#ifdef CONFIG_PAX_MEMORY_UDEREF
22466+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
22467+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
22468+ loadsegment(ds, __KERNEL_DS);
22469+ loadsegment(es, __KERNEL_DS);
22470+ loadsegment(ss, __KERNEL_DS);
22471+#endif
22472+#ifdef CONFIG_PAX_KERNEXEC
22473+ gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
22474+ gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
22475+ gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
22476+ gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
22477+ gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
22478+ gdt[GDT_ENTRY_KERNEL_CS].g = 1;
22479+#endif
22480+ pax_close_kernel();
22481+#endif
22482+
22483+ asm volatile("ljmpl *%0" : :
22484 "rm" (real_mode_header->machine_real_restart_asm),
22485 "a" (type));
22486 #else
22487@@ -531,7 +558,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
22488 * try to force a triple fault and then cycle between hitting the keyboard
22489 * controller and doing that
22490 */
22491-static void native_machine_emergency_restart(void)
22492+static void __noreturn native_machine_emergency_restart(void)
22493 {
22494 int i;
22495 int attempt = 0;
22496@@ -654,13 +681,13 @@ void native_machine_shutdown(void)
22497 #endif
22498 }
22499
22500-static void __machine_emergency_restart(int emergency)
22501+static void __noreturn __machine_emergency_restart(int emergency)
22502 {
22503 reboot_emergency = emergency;
22504 machine_ops.emergency_restart();
22505 }
22506
22507-static void native_machine_restart(char *__unused)
22508+static void __noreturn native_machine_restart(char *__unused)
22509 {
22510 pr_notice("machine restart\n");
22511
22512@@ -669,7 +696,7 @@ static void native_machine_restart(char *__unused)
22513 __machine_emergency_restart(0);
22514 }
22515
22516-static void native_machine_halt(void)
22517+static void __noreturn native_machine_halt(void)
22518 {
22519 /* Stop other cpus and apics */
22520 machine_shutdown();
22521@@ -679,7 +706,7 @@ static void native_machine_halt(void)
22522 stop_this_cpu(NULL);
22523 }
22524
22525-static void native_machine_power_off(void)
22526+static void __noreturn native_machine_power_off(void)
22527 {
22528 if (pm_power_off) {
22529 if (!reboot_force)
22530@@ -688,9 +715,10 @@ static void native_machine_power_off(void)
22531 }
22532 /* A fallback in case there is no PM info available */
22533 tboot_shutdown(TB_SHUTDOWN_HALT);
22534+ unreachable();
22535 }
22536
22537-struct machine_ops machine_ops = {
22538+struct machine_ops machine_ops __read_only = {
22539 .power_off = native_machine_power_off,
22540 .shutdown = native_machine_shutdown,
22541 .emergency_restart = native_machine_emergency_restart,
22542diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
22543index f2bb9c9..bed145d7 100644
22544--- a/arch/x86/kernel/relocate_kernel_64.S
22545+++ b/arch/x86/kernel/relocate_kernel_64.S
22546@@ -11,6 +11,7 @@
22547 #include <asm/kexec.h>
22548 #include <asm/processor-flags.h>
22549 #include <asm/pgtable_types.h>
22550+#include <asm/alternative-asm.h>
22551
22552 /*
22553 * Must be relocatable PIC code callable as a C function
22554@@ -167,6 +168,7 @@ identity_mapped:
22555 xorq %r14, %r14
22556 xorq %r15, %r15
22557
22558+ pax_force_retaddr 0, 1
22559 ret
22560
22561 1:
22562diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
22563index fae9134..8fcd87c 100644
22564--- a/arch/x86/kernel/setup.c
22565+++ b/arch/x86/kernel/setup.c
22566@@ -111,6 +111,7 @@
22567 #include <asm/mce.h>
22568 #include <asm/alternative.h>
22569 #include <asm/prom.h>
22570+#include <asm/boot.h>
22571
22572 /*
22573 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
22574@@ -447,7 +448,7 @@ static void __init parse_setup_data(void)
22575
22576 switch (data->type) {
22577 case SETUP_E820_EXT:
22578- parse_e820_ext(data);
22579+ parse_e820_ext((struct setup_data __force_kernel *)data);
22580 break;
22581 case SETUP_DTB:
22582 add_dtb(pa_data);
22583@@ -774,7 +775,7 @@ static void __init trim_bios_range(void)
22584 * area (640->1Mb) as ram even though it is not.
22585 * take them out.
22586 */
22587- e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
22588+ e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
22589
22590 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
22591 }
22592@@ -782,7 +783,7 @@ static void __init trim_bios_range(void)
22593 /* called before trim_bios_range() to spare extra sanitize */
22594 static void __init e820_add_kernel_range(void)
22595 {
22596- u64 start = __pa_symbol(_text);
22597+ u64 start = __pa_symbol(ktla_ktva(_text));
22598 u64 size = __pa_symbol(_end) - start;
22599
22600 /*
22601@@ -844,8 +845,12 @@ static void __init trim_low_memory_range(void)
22602
22603 void __init setup_arch(char **cmdline_p)
22604 {
22605+#ifdef CONFIG_X86_32
22606+ memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
22607+#else
22608 memblock_reserve(__pa_symbol(_text),
22609 (unsigned long)__bss_stop - (unsigned long)_text);
22610+#endif
22611
22612 early_reserve_initrd();
22613
22614@@ -937,14 +942,14 @@ void __init setup_arch(char **cmdline_p)
22615
22616 if (!boot_params.hdr.root_flags)
22617 root_mountflags &= ~MS_RDONLY;
22618- init_mm.start_code = (unsigned long) _text;
22619- init_mm.end_code = (unsigned long) _etext;
22620+ init_mm.start_code = ktla_ktva((unsigned long) _text);
22621+ init_mm.end_code = ktla_ktva((unsigned long) _etext);
22622 init_mm.end_data = (unsigned long) _edata;
22623 init_mm.brk = _brk_end;
22624
22625- code_resource.start = __pa_symbol(_text);
22626- code_resource.end = __pa_symbol(_etext)-1;
22627- data_resource.start = __pa_symbol(_etext);
22628+ code_resource.start = __pa_symbol(ktla_ktva(_text));
22629+ code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
22630+ data_resource.start = __pa_symbol(_sdata);
22631 data_resource.end = __pa_symbol(_edata)-1;
22632 bss_resource.start = __pa_symbol(__bss_start);
22633 bss_resource.end = __pa_symbol(__bss_stop)-1;
22634diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
22635index 5cdff03..80fa283 100644
22636--- a/arch/x86/kernel/setup_percpu.c
22637+++ b/arch/x86/kernel/setup_percpu.c
22638@@ -21,19 +21,17 @@
22639 #include <asm/cpu.h>
22640 #include <asm/stackprotector.h>
22641
22642-DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
22643+#ifdef CONFIG_SMP
22644+DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
22645 EXPORT_PER_CPU_SYMBOL(cpu_number);
22646+#endif
22647
22648-#ifdef CONFIG_X86_64
22649 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
22650-#else
22651-#define BOOT_PERCPU_OFFSET 0
22652-#endif
22653
22654 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
22655 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
22656
22657-unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
22658+unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
22659 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
22660 };
22661 EXPORT_SYMBOL(__per_cpu_offset);
22662@@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
22663 {
22664 #ifdef CONFIG_NEED_MULTIPLE_NODES
22665 pg_data_t *last = NULL;
22666- unsigned int cpu;
22667+ int cpu;
22668
22669 for_each_possible_cpu(cpu) {
22670 int node = early_cpu_to_node(cpu);
22671@@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
22672 {
22673 #ifdef CONFIG_X86_32
22674 struct desc_struct gdt;
22675+ unsigned long base = per_cpu_offset(cpu);
22676
22677- pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
22678- 0x2 | DESCTYPE_S, 0x8);
22679- gdt.s = 1;
22680+ pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
22681+ 0x83 | DESCTYPE_S, 0xC);
22682 write_gdt_entry(get_cpu_gdt_table(cpu),
22683 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
22684 #endif
22685@@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
22686 /* alrighty, percpu areas up and running */
22687 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
22688 for_each_possible_cpu(cpu) {
22689+#ifdef CONFIG_CC_STACKPROTECTOR
22690+#ifdef CONFIG_X86_32
22691+ unsigned long canary = per_cpu(stack_canary.canary, cpu);
22692+#endif
22693+#endif
22694 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
22695 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
22696 per_cpu(cpu_number, cpu) = cpu;
22697@@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
22698 */
22699 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
22700 #endif
22701+#ifdef CONFIG_CC_STACKPROTECTOR
22702+#ifdef CONFIG_X86_32
22703+ if (!cpu)
22704+ per_cpu(stack_canary.canary, cpu) = canary;
22705+#endif
22706+#endif
22707 /*
22708 * Up to this point, the boot CPU has been using .init.data
22709 * area. Reload any changed state for the boot CPU.
22710diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
22711index 6956299..f20beae 100644
22712--- a/arch/x86/kernel/signal.c
22713+++ b/arch/x86/kernel/signal.c
22714@@ -196,7 +196,7 @@ static unsigned long align_sigframe(unsigned long sp)
22715 * Align the stack pointer according to the i386 ABI,
22716 * i.e. so that on function entry ((sp + 4) & 15) == 0.
22717 */
22718- sp = ((sp + 4) & -16ul) - 4;
22719+ sp = ((sp - 12) & -16ul) - 4;
22720 #else /* !CONFIG_X86_32 */
22721 sp = round_down(sp, 16) - 8;
22722 #endif
22723@@ -304,9 +304,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22724 }
22725
22726 if (current->mm->context.vdso)
22727- restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22728+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
22729 else
22730- restorer = &frame->retcode;
22731+ restorer = (void __user *)&frame->retcode;
22732 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22733 restorer = ksig->ka.sa.sa_restorer;
22734
22735@@ -320,7 +320,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
22736 * reasons and because gdb uses it as a signature to notice
22737 * signal handler stack frames.
22738 */
22739- err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
22740+ err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
22741
22742 if (err)
22743 return -EFAULT;
22744@@ -367,7 +367,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22745 err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
22746
22747 /* Set up to return from userspace. */
22748- restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22749+ if (current->mm->context.vdso)
22750+ restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
22751+ else
22752+ restorer = (void __user *)&frame->retcode;
22753 if (ksig->ka.sa.sa_flags & SA_RESTORER)
22754 restorer = ksig->ka.sa.sa_restorer;
22755 put_user_ex(restorer, &frame->pretcode);
22756@@ -379,7 +382,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
22757 * reasons and because gdb uses it as a signature to notice
22758 * signal handler stack frames.
22759 */
22760- put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
22761+ put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
22762 } put_user_catch(err);
22763
22764 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
22765@@ -615,7 +618,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22766 {
22767 int usig = signr_convert(ksig->sig);
22768 sigset_t *set = sigmask_to_save();
22769- compat_sigset_t *cset = (compat_sigset_t *) set;
22770+ sigset_t sigcopy;
22771+ compat_sigset_t *cset;
22772+
22773+ sigcopy = *set;
22774+
22775+ cset = (compat_sigset_t *) &sigcopy;
22776
22777 /* Set up the stack frame */
22778 if (is_ia32_frame()) {
22779@@ -626,7 +634,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
22780 } else if (is_x32_frame()) {
22781 return x32_setup_rt_frame(ksig, cset, regs);
22782 } else {
22783- return __setup_rt_frame(ksig->sig, ksig, set, regs);
22784+ return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
22785 }
22786 }
22787
22788diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
22789index 48d2b7d..90d328a 100644
22790--- a/arch/x86/kernel/smp.c
22791+++ b/arch/x86/kernel/smp.c
22792@@ -285,7 +285,7 @@ static int __init nonmi_ipi_setup(char *str)
22793
22794 __setup("nonmi_ipi", nonmi_ipi_setup);
22795
22796-struct smp_ops smp_ops = {
22797+struct smp_ops smp_ops __read_only = {
22798 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
22799 .smp_prepare_cpus = native_smp_prepare_cpus,
22800 .smp_cpus_done = native_smp_cpus_done,
22801diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
22802index 9f190a2..90a0688 100644
22803--- a/arch/x86/kernel/smpboot.c
22804+++ b/arch/x86/kernel/smpboot.c
22805@@ -748,6 +748,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22806 idle->thread.sp = (unsigned long) (((struct pt_regs *)
22807 (THREAD_SIZE + task_stack_page(idle))) - 1);
22808 per_cpu(current_task, cpu) = idle;
22809+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
22810
22811 #ifdef CONFIG_X86_32
22812 /* Stack for startup_32 can be just as for start_secondary onwards */
22813@@ -755,11 +756,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
22814 #else
22815 clear_tsk_thread_flag(idle, TIF_FORK);
22816 initial_gs = per_cpu_offset(cpu);
22817- per_cpu(kernel_stack, cpu) =
22818- (unsigned long)task_stack_page(idle) -
22819- KERNEL_STACK_OFFSET + THREAD_SIZE;
22820+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
22821 #endif
22822+
22823+ pax_open_kernel();
22824 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
22825+ pax_close_kernel();
22826+
22827 initial_code = (unsigned long)start_secondary;
22828 stack_start = idle->thread.sp;
22829
22830@@ -908,6 +911,15 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
22831 /* the FPU context is blank, nobody can own it */
22832 __cpu_disable_lazy_restore(cpu);
22833
22834+#ifdef CONFIG_PAX_PER_CPU_PGD
22835+ clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
22836+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
22837+ KERNEL_PGD_PTRS);
22838+#endif
22839+
22840+ /* the FPU context is blank, nobody can own it */
22841+ __cpu_disable_lazy_restore(cpu);
22842+
22843 err = do_boot_cpu(apicid, cpu, tidle);
22844 if (err) {
22845 pr_debug("do_boot_cpu failed %d\n", err);
22846diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
22847index 9b4d51d..5d28b58 100644
22848--- a/arch/x86/kernel/step.c
22849+++ b/arch/x86/kernel/step.c
22850@@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22851 struct desc_struct *desc;
22852 unsigned long base;
22853
22854- seg &= ~7UL;
22855+ seg >>= 3;
22856
22857 mutex_lock(&child->mm->context.lock);
22858- if (unlikely((seg >> 3) >= child->mm->context.size))
22859+ if (unlikely(seg >= child->mm->context.size))
22860 addr = -1L; /* bogus selector, access would fault */
22861 else {
22862 desc = child->mm->context.ldt + seg;
22863@@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
22864 addr += base;
22865 }
22866 mutex_unlock(&child->mm->context.lock);
22867- }
22868+ } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
22869+ addr = ktla_ktva(addr);
22870
22871 return addr;
22872 }
22873@@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
22874 unsigned char opcode[15];
22875 unsigned long addr = convert_ip_to_linear(child, regs);
22876
22877+ if (addr == -EINVAL)
22878+ return 0;
22879+
22880 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
22881 for (i = 0; i < copied; i++) {
22882 switch (opcode[i]) {
22883diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
22884new file mode 100644
22885index 0000000..5877189
22886--- /dev/null
22887+++ b/arch/x86/kernel/sys_i386_32.c
22888@@ -0,0 +1,189 @@
22889+/*
22890+ * This file contains various random system calls that
22891+ * have a non-standard calling sequence on the Linux/i386
22892+ * platform.
22893+ */
22894+
22895+#include <linux/errno.h>
22896+#include <linux/sched.h>
22897+#include <linux/mm.h>
22898+#include <linux/fs.h>
22899+#include <linux/smp.h>
22900+#include <linux/sem.h>
22901+#include <linux/msg.h>
22902+#include <linux/shm.h>
22903+#include <linux/stat.h>
22904+#include <linux/syscalls.h>
22905+#include <linux/mman.h>
22906+#include <linux/file.h>
22907+#include <linux/utsname.h>
22908+#include <linux/ipc.h>
22909+#include <linux/elf.h>
22910+
22911+#include <linux/uaccess.h>
22912+#include <linux/unistd.h>
22913+
22914+#include <asm/syscalls.h>
22915+
22916+int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
22917+{
22918+ unsigned long pax_task_size = TASK_SIZE;
22919+
22920+#ifdef CONFIG_PAX_SEGMEXEC
22921+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
22922+ pax_task_size = SEGMEXEC_TASK_SIZE;
22923+#endif
22924+
22925+ if (flags & MAP_FIXED)
22926+ if (len > pax_task_size || addr > pax_task_size - len)
22927+ return -EINVAL;
22928+
22929+ return 0;
22930+}
22931+
22932+/*
22933+ * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
22934+ */
22935+static unsigned long get_align_mask(void)
22936+{
22937+ if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
22938+ return 0;
22939+
22940+ if (!(current->flags & PF_RANDOMIZE))
22941+ return 0;
22942+
22943+ return va_align.mask;
22944+}
22945+
22946+unsigned long
22947+arch_get_unmapped_area(struct file *filp, unsigned long addr,
22948+ unsigned long len, unsigned long pgoff, unsigned long flags)
22949+{
22950+ struct mm_struct *mm = current->mm;
22951+ struct vm_area_struct *vma;
22952+ unsigned long pax_task_size = TASK_SIZE;
22953+ struct vm_unmapped_area_info info;
22954+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
22955+
22956+#ifdef CONFIG_PAX_SEGMEXEC
22957+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
22958+ pax_task_size = SEGMEXEC_TASK_SIZE;
22959+#endif
22960+
22961+ pax_task_size -= PAGE_SIZE;
22962+
22963+ if (len > pax_task_size)
22964+ return -ENOMEM;
22965+
22966+ if (flags & MAP_FIXED)
22967+ return addr;
22968+
22969+#ifdef CONFIG_PAX_RANDMMAP
22970+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
22971+#endif
22972+
22973+ if (addr) {
22974+ addr = PAGE_ALIGN(addr);
22975+ if (pax_task_size - len >= addr) {
22976+ vma = find_vma(mm, addr);
22977+ if (check_heap_stack_gap(vma, addr, len, offset))
22978+ return addr;
22979+ }
22980+ }
22981+
22982+ info.flags = 0;
22983+ info.length = len;
22984+ info.align_mask = filp ? get_align_mask() : 0;
22985+ info.align_offset = pgoff << PAGE_SHIFT;
22986+ info.threadstack_offset = offset;
22987+
22988+#ifdef CONFIG_PAX_PAGEEXEC
22989+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
22990+ info.low_limit = 0x00110000UL;
22991+ info.high_limit = mm->start_code;
22992+
22993+#ifdef CONFIG_PAX_RANDMMAP
22994+ if (mm->pax_flags & MF_PAX_RANDMMAP)
22995+ info.low_limit += mm->delta_mmap & 0x03FFF000UL;
22996+#endif
22997+
22998+ if (info.low_limit < info.high_limit) {
22999+ addr = vm_unmapped_area(&info);
23000+ if (!IS_ERR_VALUE(addr))
23001+ return addr;
23002+ }
23003+ } else
23004+#endif
23005+
23006+ info.low_limit = mm->mmap_base;
23007+ info.high_limit = pax_task_size;
23008+
23009+ return vm_unmapped_area(&info);
23010+}
23011+
23012+unsigned long
23013+arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23014+ const unsigned long len, const unsigned long pgoff,
23015+ const unsigned long flags)
23016+{
23017+ struct vm_area_struct *vma;
23018+ struct mm_struct *mm = current->mm;
23019+ unsigned long addr = addr0, pax_task_size = TASK_SIZE;
23020+ struct vm_unmapped_area_info info;
23021+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23022+
23023+#ifdef CONFIG_PAX_SEGMEXEC
23024+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
23025+ pax_task_size = SEGMEXEC_TASK_SIZE;
23026+#endif
23027+
23028+ pax_task_size -= PAGE_SIZE;
23029+
23030+ /* requested length too big for entire address space */
23031+ if (len > pax_task_size)
23032+ return -ENOMEM;
23033+
23034+ if (flags & MAP_FIXED)
23035+ return addr;
23036+
23037+#ifdef CONFIG_PAX_PAGEEXEC
23038+ if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
23039+ goto bottomup;
23040+#endif
23041+
23042+#ifdef CONFIG_PAX_RANDMMAP
23043+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23044+#endif
23045+
23046+ /* requesting a specific address */
23047+ if (addr) {
23048+ addr = PAGE_ALIGN(addr);
23049+ if (pax_task_size - len >= addr) {
23050+ vma = find_vma(mm, addr);
23051+ if (check_heap_stack_gap(vma, addr, len, offset))
23052+ return addr;
23053+ }
23054+ }
23055+
23056+ info.flags = VM_UNMAPPED_AREA_TOPDOWN;
23057+ info.length = len;
23058+ info.low_limit = PAGE_SIZE;
23059+ info.high_limit = mm->mmap_base;
23060+ info.align_mask = filp ? get_align_mask() : 0;
23061+ info.align_offset = pgoff << PAGE_SHIFT;
23062+ info.threadstack_offset = offset;
23063+
23064+ addr = vm_unmapped_area(&info);
23065+ if (!(addr & ~PAGE_MASK))
23066+ return addr;
23067+ VM_BUG_ON(addr != -ENOMEM);
23068+
23069+bottomup:
23070+ /*
23071+ * A failed mmap() very likely causes application failure,
23072+ * so fall back to the bottom-up function here. This scenario
23073+ * can happen with large stack limits and large mmap()
23074+ * allocations.
23075+ */
23076+ return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
23077+}
23078diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
23079index dbded5a..ace2781 100644
23080--- a/arch/x86/kernel/sys_x86_64.c
23081+++ b/arch/x86/kernel/sys_x86_64.c
23082@@ -81,8 +81,8 @@ out:
23083 return error;
23084 }
23085
23086-static void find_start_end(unsigned long flags, unsigned long *begin,
23087- unsigned long *end)
23088+static void find_start_end(struct mm_struct *mm, unsigned long flags,
23089+ unsigned long *begin, unsigned long *end)
23090 {
23091 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
23092 unsigned long new_begin;
23093@@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
23094 *begin = new_begin;
23095 }
23096 } else {
23097- *begin = TASK_UNMAPPED_BASE;
23098+ *begin = mm->mmap_base;
23099 *end = TASK_SIZE;
23100 }
23101 }
23102@@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23103 struct vm_area_struct *vma;
23104 struct vm_unmapped_area_info info;
23105 unsigned long begin, end;
23106+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23107
23108 if (flags & MAP_FIXED)
23109 return addr;
23110
23111- find_start_end(flags, &begin, &end);
23112+ find_start_end(mm, flags, &begin, &end);
23113
23114 if (len > end)
23115 return -ENOMEM;
23116
23117+#ifdef CONFIG_PAX_RANDMMAP
23118+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23119+#endif
23120+
23121 if (addr) {
23122 addr = PAGE_ALIGN(addr);
23123 vma = find_vma(mm, addr);
23124- if (end - len >= addr &&
23125- (!vma || addr + len <= vma->vm_start))
23126+ if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23127 return addr;
23128 }
23129
23130@@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
23131 info.high_limit = end;
23132 info.align_mask = filp ? get_align_mask() : 0;
23133 info.align_offset = pgoff << PAGE_SHIFT;
23134+ info.threadstack_offset = offset;
23135 return vm_unmapped_area(&info);
23136 }
23137
23138@@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23139 struct mm_struct *mm = current->mm;
23140 unsigned long addr = addr0;
23141 struct vm_unmapped_area_info info;
23142+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
23143
23144 /* requested length too big for entire address space */
23145 if (len > TASK_SIZE)
23146@@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23147 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
23148 goto bottomup;
23149
23150+#ifdef CONFIG_PAX_RANDMMAP
23151+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
23152+#endif
23153+
23154 /* requesting a specific address */
23155 if (addr) {
23156 addr = PAGE_ALIGN(addr);
23157 vma = find_vma(mm, addr);
23158- if (TASK_SIZE - len >= addr &&
23159- (!vma || addr + len <= vma->vm_start))
23160+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
23161 return addr;
23162 }
23163
23164@@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
23165 info.high_limit = mm->mmap_base;
23166 info.align_mask = filp ? get_align_mask() : 0;
23167 info.align_offset = pgoff << PAGE_SHIFT;
23168+ info.threadstack_offset = offset;
23169 addr = vm_unmapped_area(&info);
23170 if (!(addr & ~PAGE_MASK))
23171 return addr;
23172diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
23173index f84fe00..f41d9f1 100644
23174--- a/arch/x86/kernel/tboot.c
23175+++ b/arch/x86/kernel/tboot.c
23176@@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
23177
23178 void tboot_shutdown(u32 shutdown_type)
23179 {
23180- void (*shutdown)(void);
23181+ void (* __noreturn shutdown)(void);
23182
23183 if (!tboot_enabled())
23184 return;
23185@@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
23186
23187 switch_to_tboot_pt();
23188
23189- shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
23190+ shutdown = (void *)tboot->shutdown_entry;
23191 shutdown();
23192
23193 /* should not reach here */
23194@@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
23195 return 0;
23196 }
23197
23198-static atomic_t ap_wfs_count;
23199+static atomic_unchecked_t ap_wfs_count;
23200
23201 static int tboot_wait_for_aps(int num_aps)
23202 {
23203@@ -324,16 +324,16 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
23204 {
23205 switch (action) {
23206 case CPU_DYING:
23207- atomic_inc(&ap_wfs_count);
23208+ atomic_inc_unchecked(&ap_wfs_count);
23209 if (num_online_cpus() == 1)
23210- if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
23211+ if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
23212 return NOTIFY_BAD;
23213 break;
23214 }
23215 return NOTIFY_OK;
23216 }
23217
23218-static struct notifier_block tboot_cpu_notifier __cpuinitdata =
23219+static struct notifier_block tboot_cpu_notifier =
23220 {
23221 .notifier_call = tboot_cpu_callback,
23222 };
23223@@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
23224
23225 tboot_create_trampoline();
23226
23227- atomic_set(&ap_wfs_count, 0);
23228+ atomic_set_unchecked(&ap_wfs_count, 0);
23229 register_hotcpu_notifier(&tboot_cpu_notifier);
23230
23231 acpi_os_set_prepare_sleep(&tboot_sleep);
23232diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
23233index 24d3c91..d06b473 100644
23234--- a/arch/x86/kernel/time.c
23235+++ b/arch/x86/kernel/time.c
23236@@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
23237 {
23238 unsigned long pc = instruction_pointer(regs);
23239
23240- if (!user_mode_vm(regs) && in_lock_functions(pc)) {
23241+ if (!user_mode(regs) && in_lock_functions(pc)) {
23242 #ifdef CONFIG_FRAME_POINTER
23243- return *(unsigned long *)(regs->bp + sizeof(long));
23244+ return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
23245 #else
23246 unsigned long *sp =
23247 (unsigned long *)kernel_stack_pointer(regs);
23248@@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
23249 * or above a saved flags. Eflags has bits 22-31 zero,
23250 * kernel addresses don't.
23251 */
23252+
23253+#ifdef CONFIG_PAX_KERNEXEC
23254+ return ktla_ktva(sp[0]);
23255+#else
23256 if (sp[0] >> 22)
23257 return sp[0];
23258 if (sp[1] >> 22)
23259 return sp[1];
23260 #endif
23261+
23262+#endif
23263 }
23264 return pc;
23265 }
23266diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
23267index 9d9d2f9..cad418a 100644
23268--- a/arch/x86/kernel/tls.c
23269+++ b/arch/x86/kernel/tls.c
23270@@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
23271 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
23272 return -EINVAL;
23273
23274+#ifdef CONFIG_PAX_SEGMEXEC
23275+ if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
23276+ return -EINVAL;
23277+#endif
23278+
23279 set_tls_desc(p, idx, &info, 1);
23280
23281 return 0;
23282@@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
23283
23284 if (kbuf)
23285 info = kbuf;
23286- else if (__copy_from_user(infobuf, ubuf, count))
23287+ else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
23288 return -EFAULT;
23289 else
23290 info = infobuf;
23291diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
23292index 68bda7a..3ec7bb7 100644
23293--- a/arch/x86/kernel/traps.c
23294+++ b/arch/x86/kernel/traps.c
23295@@ -68,12 +68,6 @@
23296 #include <asm/setup.h>
23297
23298 asmlinkage int system_call(void);
23299-
23300-/*
23301- * The IDT has to be page-aligned to simplify the Pentium
23302- * F0 0F bug workaround.
23303- */
23304-gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
23305 #endif
23306
23307 DECLARE_BITMAP(used_vectors, NR_VECTORS);
23308@@ -106,11 +100,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
23309 }
23310
23311 static int __kprobes
23312-do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23313+do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
23314 struct pt_regs *regs, long error_code)
23315 {
23316 #ifdef CONFIG_X86_32
23317- if (regs->flags & X86_VM_MASK) {
23318+ if (v8086_mode(regs)) {
23319 /*
23320 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
23321 * On nmi (interrupt 2), do_trap should not be called.
23322@@ -123,12 +117,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23323 return -1;
23324 }
23325 #endif
23326- if (!user_mode(regs)) {
23327+ if (!user_mode_novm(regs)) {
23328 if (!fixup_exception(regs)) {
23329 tsk->thread.error_code = error_code;
23330 tsk->thread.trap_nr = trapnr;
23331+
23332+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23333+ if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
23334+ str = "PAX: suspicious stack segment fault";
23335+#endif
23336+
23337 die(str, regs, error_code);
23338 }
23339+
23340+#ifdef CONFIG_PAX_REFCOUNT
23341+ if (trapnr == 4)
23342+ pax_report_refcount_overflow(regs);
23343+#endif
23344+
23345 return 0;
23346 }
23347
23348@@ -136,7 +142,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
23349 }
23350
23351 static void __kprobes
23352-do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23353+do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
23354 long error_code, siginfo_t *info)
23355 {
23356 struct task_struct *tsk = current;
23357@@ -160,7 +166,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
23358 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
23359 printk_ratelimit()) {
23360 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
23361- tsk->comm, tsk->pid, str,
23362+ tsk->comm, task_pid_nr(tsk), str,
23363 regs->ip, regs->sp, error_code);
23364 print_vma_addr(" in ", regs->ip);
23365 pr_cont("\n");
23366@@ -266,7 +272,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
23367 conditional_sti(regs);
23368
23369 #ifdef CONFIG_X86_32
23370- if (regs->flags & X86_VM_MASK) {
23371+ if (v8086_mode(regs)) {
23372 local_irq_enable();
23373 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
23374 goto exit;
23375@@ -274,18 +280,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
23376 #endif
23377
23378 tsk = current;
23379- if (!user_mode(regs)) {
23380+ if (!user_mode_novm(regs)) {
23381 if (fixup_exception(regs))
23382 goto exit;
23383
23384 tsk->thread.error_code = error_code;
23385 tsk->thread.trap_nr = X86_TRAP_GP;
23386 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
23387- X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
23388+ X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
23389+
23390+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23391+ if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
23392+ die("PAX: suspicious general protection fault", regs, error_code);
23393+ else
23394+#endif
23395+
23396 die("general protection fault", regs, error_code);
23397+ }
23398 goto exit;
23399 }
23400
23401+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23402+ if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
23403+ struct mm_struct *mm = tsk->mm;
23404+ unsigned long limit;
23405+
23406+ down_write(&mm->mmap_sem);
23407+ limit = mm->context.user_cs_limit;
23408+ if (limit < TASK_SIZE) {
23409+ track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
23410+ up_write(&mm->mmap_sem);
23411+ return;
23412+ }
23413+ up_write(&mm->mmap_sem);
23414+ }
23415+#endif
23416+
23417 tsk->thread.error_code = error_code;
23418 tsk->thread.trap_nr = X86_TRAP_GP;
23419
23420@@ -440,7 +470,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23421 /* It's safe to allow irq's after DR6 has been saved */
23422 preempt_conditional_sti(regs);
23423
23424- if (regs->flags & X86_VM_MASK) {
23425+ if (v8086_mode(regs)) {
23426 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
23427 X86_TRAP_DB);
23428 preempt_conditional_cli(regs);
23429@@ -455,7 +485,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
23430 * We already checked v86 mode above, so we can check for kernel mode
23431 * by just checking the CPL of CS.
23432 */
23433- if ((dr6 & DR_STEP) && !user_mode(regs)) {
23434+ if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
23435 tsk->thread.debugreg6 &= ~DR_STEP;
23436 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
23437 regs->flags &= ~X86_EFLAGS_TF;
23438@@ -487,7 +517,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
23439 return;
23440 conditional_sti(regs);
23441
23442- if (!user_mode_vm(regs))
23443+ if (!user_mode(regs))
23444 {
23445 if (!fixup_exception(regs)) {
23446 task->thread.error_code = error_code;
23447diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
23448index 0ba4cfb..4596bec 100644
23449--- a/arch/x86/kernel/uprobes.c
23450+++ b/arch/x86/kernel/uprobes.c
23451@@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
23452 int ret = NOTIFY_DONE;
23453
23454 /* We are only interested in userspace traps */
23455- if (regs && !user_mode_vm(regs))
23456+ if (regs && !user_mode(regs))
23457 return NOTIFY_DONE;
23458
23459 switch (val) {
23460diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
23461index b9242ba..50c5edd 100644
23462--- a/arch/x86/kernel/verify_cpu.S
23463+++ b/arch/x86/kernel/verify_cpu.S
23464@@ -20,6 +20,7 @@
23465 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
23466 * arch/x86/kernel/trampoline_64.S: secondary processor verification
23467 * arch/x86/kernel/head_32.S: processor startup
23468+ * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
23469 *
23470 * verify_cpu, returns the status of longmode and SSE in register %eax.
23471 * 0: Success 1: Failure
23472diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
23473index 3dbdd9c..888b14e 100644
23474--- a/arch/x86/kernel/vm86_32.c
23475+++ b/arch/x86/kernel/vm86_32.c
23476@@ -44,6 +44,7 @@
23477 #include <linux/ptrace.h>
23478 #include <linux/audit.h>
23479 #include <linux/stddef.h>
23480+#include <linux/grsecurity.h>
23481
23482 #include <asm/uaccess.h>
23483 #include <asm/io.h>
23484@@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
23485 do_exit(SIGSEGV);
23486 }
23487
23488- tss = &per_cpu(init_tss, get_cpu());
23489+ tss = init_tss + get_cpu();
23490 current->thread.sp0 = current->thread.saved_sp0;
23491 current->thread.sysenter_cs = __KERNEL_CS;
23492 load_sp0(tss, &current->thread);
23493@@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
23494
23495 if (tsk->thread.saved_sp0)
23496 goto out;
23497+
23498+#ifdef CONFIG_GRKERNSEC_VM86
23499+ if (!capable(CAP_SYS_RAWIO)) {
23500+ gr_handle_vm86();
23501+ goto out;
23502+ }
23503+#endif
23504+
23505 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
23506 offsetof(struct kernel_vm86_struct, vm86plus) -
23507 sizeof(info.regs));
23508@@ -242,6 +251,14 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
23509 int tmp, ret;
23510 struct vm86plus_struct __user *v86;
23511
23512+#ifdef CONFIG_GRKERNSEC_VM86
23513+ if (!capable(CAP_SYS_RAWIO)) {
23514+ gr_handle_vm86();
23515+ ret = -EPERM;
23516+ goto out;
23517+ }
23518+#endif
23519+
23520 tsk = current;
23521 switch (cmd) {
23522 case VM86_REQUEST_IRQ:
23523@@ -329,7 +346,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
23524 tsk->thread.saved_fs = info->regs32->fs;
23525 tsk->thread.saved_gs = get_user_gs(info->regs32);
23526
23527- tss = &per_cpu(init_tss, get_cpu());
23528+ tss = init_tss + get_cpu();
23529 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
23530 if (cpu_has_sep)
23531 tsk->thread.sysenter_cs = 0;
23532@@ -536,7 +553,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
23533 goto cannot_handle;
23534 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
23535 goto cannot_handle;
23536- intr_ptr = (unsigned long __user *) (i << 2);
23537+ intr_ptr = (__force unsigned long __user *) (i << 2);
23538 if (get_user(segoffs, intr_ptr))
23539 goto cannot_handle;
23540 if ((segoffs >> 16) == BIOSSEG)
23541diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
23542index 22a1530..5efafbf 100644
23543--- a/arch/x86/kernel/vmlinux.lds.S
23544+++ b/arch/x86/kernel/vmlinux.lds.S
23545@@ -26,6 +26,13 @@
23546 #include <asm/page_types.h>
23547 #include <asm/cache.h>
23548 #include <asm/boot.h>
23549+#include <asm/segment.h>
23550+
23551+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23552+#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
23553+#else
23554+#define __KERNEL_TEXT_OFFSET 0
23555+#endif
23556
23557 #undef i386 /* in case the preprocessor is a 32bit one */
23558
23559@@ -69,30 +76,43 @@ jiffies_64 = jiffies;
23560
23561 PHDRS {
23562 text PT_LOAD FLAGS(5); /* R_E */
23563+#ifdef CONFIG_X86_32
23564+ module PT_LOAD FLAGS(5); /* R_E */
23565+#endif
23566+#ifdef CONFIG_XEN
23567+ rodata PT_LOAD FLAGS(5); /* R_E */
23568+#else
23569+ rodata PT_LOAD FLAGS(4); /* R__ */
23570+#endif
23571 data PT_LOAD FLAGS(6); /* RW_ */
23572-#ifdef CONFIG_X86_64
23573+ init.begin PT_LOAD FLAGS(6); /* RW_ */
23574 #ifdef CONFIG_SMP
23575 percpu PT_LOAD FLAGS(6); /* RW_ */
23576 #endif
23577+ text.init PT_LOAD FLAGS(5); /* R_E */
23578+ text.exit PT_LOAD FLAGS(5); /* R_E */
23579 init PT_LOAD FLAGS(7); /* RWE */
23580-#endif
23581 note PT_NOTE FLAGS(0); /* ___ */
23582 }
23583
23584 SECTIONS
23585 {
23586 #ifdef CONFIG_X86_32
23587- . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
23588- phys_startup_32 = startup_32 - LOAD_OFFSET;
23589+ . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
23590 #else
23591- . = __START_KERNEL;
23592- phys_startup_64 = startup_64 - LOAD_OFFSET;
23593+ . = __START_KERNEL;
23594 #endif
23595
23596 /* Text and read-only data */
23597- .text : AT(ADDR(.text) - LOAD_OFFSET) {
23598- _text = .;
23599+ .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23600 /* bootstrapping code */
23601+#ifdef CONFIG_X86_32
23602+ phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23603+#else
23604+ phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23605+#endif
23606+ __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
23607+ _text = .;
23608 HEAD_TEXT
23609 #ifdef CONFIG_X86_32
23610 . = ALIGN(PAGE_SIZE);
23611@@ -108,13 +128,48 @@ SECTIONS
23612 IRQENTRY_TEXT
23613 *(.fixup)
23614 *(.gnu.warning)
23615- /* End of text section */
23616- _etext = .;
23617 } :text = 0x9090
23618
23619- NOTES :text :note
23620+ . += __KERNEL_TEXT_OFFSET;
23621
23622- EXCEPTION_TABLE(16) :text = 0x9090
23623+#ifdef CONFIG_X86_32
23624+ . = ALIGN(PAGE_SIZE);
23625+ .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
23626+
23627+#ifdef CONFIG_PAX_KERNEXEC
23628+ MODULES_EXEC_VADDR = .;
23629+ BYTE(0)
23630+ . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
23631+ . = ALIGN(HPAGE_SIZE) - 1;
23632+ MODULES_EXEC_END = .;
23633+#endif
23634+
23635+ } :module
23636+#endif
23637+
23638+ .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
23639+ /* End of text section */
23640+ BYTE(0)
23641+ _etext = . - __KERNEL_TEXT_OFFSET;
23642+ }
23643+
23644+#ifdef CONFIG_X86_32
23645+ . = ALIGN(PAGE_SIZE);
23646+ .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
23647+ *(.idt)
23648+ . = ALIGN(PAGE_SIZE);
23649+ *(.empty_zero_page)
23650+ *(.initial_pg_fixmap)
23651+ *(.initial_pg_pmd)
23652+ *(.initial_page_table)
23653+ *(.swapper_pg_dir)
23654+ } :rodata
23655+#endif
23656+
23657+ . = ALIGN(PAGE_SIZE);
23658+ NOTES :rodata :note
23659+
23660+ EXCEPTION_TABLE(16) :rodata
23661
23662 #if defined(CONFIG_DEBUG_RODATA)
23663 /* .text should occupy whole number of pages */
23664@@ -126,16 +181,20 @@ SECTIONS
23665
23666 /* Data */
23667 .data : AT(ADDR(.data) - LOAD_OFFSET) {
23668+
23669+#ifdef CONFIG_PAX_KERNEXEC
23670+ . = ALIGN(HPAGE_SIZE);
23671+#else
23672+ . = ALIGN(PAGE_SIZE);
23673+#endif
23674+
23675 /* Start of data section */
23676 _sdata = .;
23677
23678 /* init_task */
23679 INIT_TASK_DATA(THREAD_SIZE)
23680
23681-#ifdef CONFIG_X86_32
23682- /* 32 bit has nosave before _edata */
23683 NOSAVE_DATA
23684-#endif
23685
23686 PAGE_ALIGNED_DATA(PAGE_SIZE)
23687
23688@@ -176,12 +235,19 @@ SECTIONS
23689 #endif /* CONFIG_X86_64 */
23690
23691 /* Init code and data - will be freed after init */
23692- . = ALIGN(PAGE_SIZE);
23693 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
23694+ BYTE(0)
23695+
23696+#ifdef CONFIG_PAX_KERNEXEC
23697+ . = ALIGN(HPAGE_SIZE);
23698+#else
23699+ . = ALIGN(PAGE_SIZE);
23700+#endif
23701+
23702 __init_begin = .; /* paired with __init_end */
23703- }
23704+ } :init.begin
23705
23706-#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
23707+#ifdef CONFIG_SMP
23708 /*
23709 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
23710 * output PHDR, so the next output section - .init.text - should
23711@@ -190,12 +256,27 @@ SECTIONS
23712 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
23713 #endif
23714
23715- INIT_TEXT_SECTION(PAGE_SIZE)
23716-#ifdef CONFIG_X86_64
23717- :init
23718-#endif
23719+ . = ALIGN(PAGE_SIZE);
23720+ init_begin = .;
23721+ .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
23722+ VMLINUX_SYMBOL(_sinittext) = .;
23723+ INIT_TEXT
23724+ VMLINUX_SYMBOL(_einittext) = .;
23725+ . = ALIGN(PAGE_SIZE);
23726+ } :text.init
23727
23728- INIT_DATA_SECTION(16)
23729+ /*
23730+ * .exit.text is discard at runtime, not link time, to deal with
23731+ * references from .altinstructions and .eh_frame
23732+ */
23733+ .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
23734+ EXIT_TEXT
23735+ . = ALIGN(16);
23736+ } :text.exit
23737+ . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
23738+
23739+ . = ALIGN(PAGE_SIZE);
23740+ INIT_DATA_SECTION(16) :init
23741
23742 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
23743 __x86_cpu_dev_start = .;
23744@@ -257,19 +338,12 @@ SECTIONS
23745 }
23746
23747 . = ALIGN(8);
23748- /*
23749- * .exit.text is discard at runtime, not link time, to deal with
23750- * references from .altinstructions and .eh_frame
23751- */
23752- .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
23753- EXIT_TEXT
23754- }
23755
23756 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
23757 EXIT_DATA
23758 }
23759
23760-#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
23761+#ifndef CONFIG_SMP
23762 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
23763 #endif
23764
23765@@ -288,16 +362,10 @@ SECTIONS
23766 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
23767 __smp_locks = .;
23768 *(.smp_locks)
23769- . = ALIGN(PAGE_SIZE);
23770 __smp_locks_end = .;
23771+ . = ALIGN(PAGE_SIZE);
23772 }
23773
23774-#ifdef CONFIG_X86_64
23775- .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
23776- NOSAVE_DATA
23777- }
23778-#endif
23779-
23780 /* BSS */
23781 . = ALIGN(PAGE_SIZE);
23782 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
23783@@ -313,6 +381,7 @@ SECTIONS
23784 __brk_base = .;
23785 . += 64 * 1024; /* 64k alignment slop space */
23786 *(.brk_reservation) /* areas brk users have reserved */
23787+ . = ALIGN(HPAGE_SIZE);
23788 __brk_limit = .;
23789 }
23790
23791@@ -339,13 +408,12 @@ SECTIONS
23792 * for the boot processor.
23793 */
23794 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
23795-INIT_PER_CPU(gdt_page);
23796 INIT_PER_CPU(irq_stack_union);
23797
23798 /*
23799 * Build-time check on the image size:
23800 */
23801-. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
23802+. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
23803 "kernel image bigger than KERNEL_IMAGE_SIZE");
23804
23805 #ifdef CONFIG_SMP
23806diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
23807index 9a907a6..f83f921 100644
23808--- a/arch/x86/kernel/vsyscall_64.c
23809+++ b/arch/x86/kernel/vsyscall_64.c
23810@@ -56,15 +56,13 @@
23811 DEFINE_VVAR(int, vgetcpu_mode);
23812 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
23813
23814-static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
23815+static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
23816
23817 static int __init vsyscall_setup(char *str)
23818 {
23819 if (str) {
23820 if (!strcmp("emulate", str))
23821 vsyscall_mode = EMULATE;
23822- else if (!strcmp("native", str))
23823- vsyscall_mode = NATIVE;
23824 else if (!strcmp("none", str))
23825 vsyscall_mode = NONE;
23826 else
23827@@ -323,8 +321,7 @@ do_ret:
23828 return true;
23829
23830 sigsegv:
23831- force_sig(SIGSEGV, current);
23832- return true;
23833+ do_group_exit(SIGKILL);
23834 }
23835
23836 /*
23837@@ -377,10 +374,7 @@ void __init map_vsyscall(void)
23838 extern char __vvar_page;
23839 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
23840
23841- __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
23842- vsyscall_mode == NATIVE
23843- ? PAGE_KERNEL_VSYSCALL
23844- : PAGE_KERNEL_VVAR);
23845+ __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
23846 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
23847 (unsigned long)VSYSCALL_START);
23848
23849diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
23850index b014d94..6d6ca7b 100644
23851--- a/arch/x86/kernel/x8664_ksyms_64.c
23852+++ b/arch/x86/kernel/x8664_ksyms_64.c
23853@@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
23854 EXPORT_SYMBOL(copy_user_generic_unrolled);
23855 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
23856 EXPORT_SYMBOL(__copy_user_nocache);
23857-EXPORT_SYMBOL(_copy_from_user);
23858-EXPORT_SYMBOL(_copy_to_user);
23859
23860 EXPORT_SYMBOL(copy_page);
23861 EXPORT_SYMBOL(clear_page);
23862diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
23863index 45a14db..075bb9b 100644
23864--- a/arch/x86/kernel/x86_init.c
23865+++ b/arch/x86/kernel/x86_init.c
23866@@ -85,7 +85,7 @@ struct x86_init_ops x86_init __initdata = {
23867 },
23868 };
23869
23870-struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23871+struct x86_cpuinit_ops x86_cpuinit __cpuinitconst = {
23872 .early_percpu_clock_init = x86_init_noop,
23873 .setup_percpu_clockev = setup_secondary_APIC_clock,
23874 };
23875@@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit __cpuinitdata = {
23876 static void default_nmi_init(void) { };
23877 static int default_i8042_detect(void) { return 1; };
23878
23879-struct x86_platform_ops x86_platform = {
23880+struct x86_platform_ops x86_platform __read_only = {
23881 .calibrate_tsc = native_calibrate_tsc,
23882 .get_wallclock = mach_get_cmos_time,
23883 .set_wallclock = mach_set_rtc_mmss,
23884@@ -107,7 +107,7 @@ struct x86_platform_ops x86_platform = {
23885 };
23886
23887 EXPORT_SYMBOL_GPL(x86_platform);
23888-struct x86_msi_ops x86_msi = {
23889+struct x86_msi_ops x86_msi __read_only = {
23890 .setup_msi_irqs = native_setup_msi_irqs,
23891 .compose_msi_msg = native_compose_msi_msg,
23892 .teardown_msi_irq = native_teardown_msi_irq,
23893@@ -116,7 +116,7 @@ struct x86_msi_ops x86_msi = {
23894 .setup_hpet_msi = default_setup_hpet_msi,
23895 };
23896
23897-struct x86_io_apic_ops x86_io_apic_ops = {
23898+struct x86_io_apic_ops x86_io_apic_ops __read_only = {
23899 .init = native_io_apic_init_mappings,
23900 .read = native_io_apic_read,
23901 .write = native_io_apic_write,
23902diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
23903index ada87a3..afea76d 100644
23904--- a/arch/x86/kernel/xsave.c
23905+++ b/arch/x86/kernel/xsave.c
23906@@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
23907 {
23908 int err;
23909
23910+ buf = (struct xsave_struct __user *)____m(buf);
23911 if (use_xsave())
23912 err = xsave_user(buf);
23913 else if (use_fxsr())
23914@@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
23915 */
23916 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
23917 {
23918+ buf = (void __user *)____m(buf);
23919 if (use_xsave()) {
23920 if ((unsigned long)buf % 64 || fx_only) {
23921 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
23922diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
23923index a20ecb5..d0e2194 100644
23924--- a/arch/x86/kvm/cpuid.c
23925+++ b/arch/x86/kvm/cpuid.c
23926@@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
23927 struct kvm_cpuid2 *cpuid,
23928 struct kvm_cpuid_entry2 __user *entries)
23929 {
23930- int r;
23931+ int r, i;
23932
23933 r = -E2BIG;
23934 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
23935 goto out;
23936 r = -EFAULT;
23937- if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
23938- cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23939+ if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
23940 goto out;
23941+ for (i = 0; i < cpuid->nent; ++i) {
23942+ struct kvm_cpuid_entry2 cpuid_entry;
23943+ if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
23944+ goto out;
23945+ vcpu->arch.cpuid_entries[i] = cpuid_entry;
23946+ }
23947 vcpu->arch.cpuid_nent = cpuid->nent;
23948 kvm_apic_set_version(vcpu);
23949 kvm_x86_ops->cpuid_update(vcpu);
23950@@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
23951 struct kvm_cpuid2 *cpuid,
23952 struct kvm_cpuid_entry2 __user *entries)
23953 {
23954- int r;
23955+ int r, i;
23956
23957 r = -E2BIG;
23958 if (cpuid->nent < vcpu->arch.cpuid_nent)
23959 goto out;
23960 r = -EFAULT;
23961- if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
23962- vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23963+ if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
23964 goto out;
23965+ for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
23966+ struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
23967+ if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
23968+ goto out;
23969+ }
23970 return 0;
23971
23972 out:
23973diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
23974index 698eece..776b682 100644
23975--- a/arch/x86/kvm/emulate.c
23976+++ b/arch/x86/kvm/emulate.c
23977@@ -328,6 +328,7 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23978
23979 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
23980 do { \
23981+ unsigned long _tmp; \
23982 __asm__ __volatile__ ( \
23983 _PRE_EFLAGS("0", "4", "2") \
23984 _op _suffix " %"_x"3,%1; " \
23985@@ -342,8 +343,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23986 /* Raw emulation: instruction has two explicit operands. */
23987 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
23988 do { \
23989- unsigned long _tmp; \
23990- \
23991 switch ((ctxt)->dst.bytes) { \
23992 case 2: \
23993 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
23994@@ -359,7 +358,6 @@ static void invalidate_registers(struct x86_emulate_ctxt *ctxt)
23995
23996 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
23997 do { \
23998- unsigned long _tmp; \
23999 switch ((ctxt)->dst.bytes) { \
24000 case 1: \
24001 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
24002diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
24003index f77df1c..6f20690 100644
24004--- a/arch/x86/kvm/lapic.c
24005+++ b/arch/x86/kvm/lapic.c
24006@@ -55,7 +55,7 @@
24007 #define APIC_BUS_CYCLE_NS 1
24008
24009 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
24010-#define apic_debug(fmt, arg...)
24011+#define apic_debug(fmt, arg...) do {} while (0)
24012
24013 #define APIC_LVT_NUM 6
24014 /* 14 is the version for Xeon and Pentium 8.4.8*/
24015diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
24016index 105dd5b..1b0ccc2 100644
24017--- a/arch/x86/kvm/paging_tmpl.h
24018+++ b/arch/x86/kvm/paging_tmpl.h
24019@@ -208,7 +208,7 @@ retry_walk:
24020 if (unlikely(kvm_is_error_hva(host_addr)))
24021 goto error;
24022
24023- ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
24024+ ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
24025 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
24026 goto error;
24027 walker->ptep_user[walker->level - 1] = ptep_user;
24028diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
24029index e1b1ce2..f7b4b43 100644
24030--- a/arch/x86/kvm/svm.c
24031+++ b/arch/x86/kvm/svm.c
24032@@ -3507,7 +3507,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
24033 int cpu = raw_smp_processor_id();
24034
24035 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
24036+
24037+ pax_open_kernel();
24038 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
24039+ pax_close_kernel();
24040+
24041 load_TR_desc();
24042 }
24043
24044@@ -3901,6 +3905,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
24045 #endif
24046 #endif
24047
24048+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
24049+ __set_fs(current_thread_info()->addr_limit);
24050+#endif
24051+
24052 reload_tss(vcpu);
24053
24054 local_irq_disable();
24055diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
24056index 0af1807..06912bb 100644
24057--- a/arch/x86/kvm/vmx.c
24058+++ b/arch/x86/kvm/vmx.c
24059@@ -1184,12 +1184,12 @@ static void vmcs_write64(unsigned long field, u64 value)
24060 #endif
24061 }
24062
24063-static void vmcs_clear_bits(unsigned long field, u32 mask)
24064+static void vmcs_clear_bits(unsigned long field, unsigned long mask)
24065 {
24066 vmcs_writel(field, vmcs_readl(field) & ~mask);
24067 }
24068
24069-static void vmcs_set_bits(unsigned long field, u32 mask)
24070+static void vmcs_set_bits(unsigned long field, unsigned long mask)
24071 {
24072 vmcs_writel(field, vmcs_readl(field) | mask);
24073 }
24074@@ -1390,7 +1390,11 @@ static void reload_tss(void)
24075 struct desc_struct *descs;
24076
24077 descs = (void *)gdt->address;
24078+
24079+ pax_open_kernel();
24080 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
24081+ pax_close_kernel();
24082+
24083 load_TR_desc();
24084 }
24085
24086@@ -1614,6 +1618,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
24087 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
24088 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
24089
24090+#ifdef CONFIG_PAX_PER_CPU_PGD
24091+ vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24092+#endif
24093+
24094 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
24095 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
24096 vmx->loaded_vmcs->cpu = cpu;
24097@@ -2779,8 +2787,11 @@ static __init int hardware_setup(void)
24098 if (!cpu_has_vmx_flexpriority())
24099 flexpriority_enabled = 0;
24100
24101- if (!cpu_has_vmx_tpr_shadow())
24102- kvm_x86_ops->update_cr8_intercept = NULL;
24103+ if (!cpu_has_vmx_tpr_shadow()) {
24104+ pax_open_kernel();
24105+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24106+ pax_close_kernel();
24107+ }
24108
24109 if (enable_ept && !cpu_has_vmx_ept_2m_page())
24110 kvm_disable_largepages();
24111@@ -2792,10 +2803,12 @@ static __init int hardware_setup(void)
24112 !cpu_has_vmx_virtual_intr_delivery())
24113 enable_apicv_reg_vid = 0;
24114
24115+ pax_open_kernel();
24116 if (enable_apicv_reg_vid)
24117- kvm_x86_ops->update_cr8_intercept = NULL;
24118+ *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
24119 else
24120- kvm_x86_ops->hwapic_irr_update = NULL;
24121+ *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
24122+ pax_close_kernel();
24123
24124 if (nested)
24125 nested_vmx_setup_ctls_msrs();
24126@@ -3883,7 +3896,10 @@ static void vmx_set_constant_host_state(void)
24127
24128 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
24129 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
24130+
24131+#ifndef CONFIG_PAX_PER_CPU_PGD
24132 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
24133+#endif
24134
24135 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
24136 #ifdef CONFIG_X86_64
24137@@ -3904,7 +3920,7 @@ static void vmx_set_constant_host_state(void)
24138 native_store_idt(&dt);
24139 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
24140
24141- vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
24142+ vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
24143
24144 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
24145 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
24146@@ -6580,6 +6596,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24147 "jmp 2f \n\t"
24148 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
24149 "2: "
24150+
24151+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24152+ "ljmp %[cs],$3f\n\t"
24153+ "3: "
24154+#endif
24155+
24156 /* Save guest registers, load host registers, keep flags */
24157 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
24158 "pop %0 \n\t"
24159@@ -6632,6 +6654,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24160 #endif
24161 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
24162 [wordsize]"i"(sizeof(ulong))
24163+
24164+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
24165+ ,[cs]"i"(__KERNEL_CS)
24166+#endif
24167+
24168 : "cc", "memory"
24169 #ifdef CONFIG_X86_64
24170 , "rax", "rbx", "rdi", "rsi"
24171@@ -6645,7 +6672,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24172 if (debugctlmsr)
24173 update_debugctlmsr(debugctlmsr);
24174
24175-#ifndef CONFIG_X86_64
24176+#ifdef CONFIG_X86_32
24177 /*
24178 * The sysexit path does not restore ds/es, so we must set them to
24179 * a reasonable value ourselves.
24180@@ -6654,8 +6681,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
24181 * may be executed in interrupt context, which saves and restore segments
24182 * around it, nullifying its effect.
24183 */
24184- loadsegment(ds, __USER_DS);
24185- loadsegment(es, __USER_DS);
24186+ loadsegment(ds, __KERNEL_DS);
24187+ loadsegment(es, __KERNEL_DS);
24188+ loadsegment(ss, __KERNEL_DS);
24189+
24190+#ifdef CONFIG_PAX_KERNEXEC
24191+ loadsegment(fs, __KERNEL_PERCPU);
24192+#endif
24193+
24194+#ifdef CONFIG_PAX_MEMORY_UDEREF
24195+ __set_fs(current_thread_info()->addr_limit);
24196+#endif
24197+
24198 #endif
24199
24200 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
24201diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
24202index 8563b45..272f1fe 100644
24203--- a/arch/x86/kvm/x86.c
24204+++ b/arch/x86/kvm/x86.c
24205@@ -1685,8 +1685,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
24206 {
24207 struct kvm *kvm = vcpu->kvm;
24208 int lm = is_long_mode(vcpu);
24209- u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24210- : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24211+ u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
24212+ : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
24213 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
24214 : kvm->arch.xen_hvm_config.blob_size_32;
24215 u32 page_num = data & ~PAGE_MASK;
24216@@ -2566,6 +2566,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
24217 if (n < msr_list.nmsrs)
24218 goto out;
24219 r = -EFAULT;
24220+ if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
24221+ goto out;
24222 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
24223 num_msrs_to_save * sizeof(u32)))
24224 goto out;
24225@@ -2695,7 +2697,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
24226 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
24227 struct kvm_interrupt *irq)
24228 {
24229- if (irq->irq < 0 || irq->irq >= KVM_NR_INTERRUPTS)
24230+ if (irq->irq >= KVM_NR_INTERRUPTS)
24231 return -EINVAL;
24232 if (irqchip_in_kernel(vcpu->kvm))
24233 return -ENXIO;
24234@@ -5246,7 +5248,7 @@ static struct notifier_block pvclock_gtod_notifier = {
24235 };
24236 #endif
24237
24238-int kvm_arch_init(void *opaque)
24239+int kvm_arch_init(const void *opaque)
24240 {
24241 int r;
24242 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
24243diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
24244index 7114c63..a1018fc 100644
24245--- a/arch/x86/lguest/boot.c
24246+++ b/arch/x86/lguest/boot.c
24247@@ -1201,9 +1201,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
24248 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
24249 * Launcher to reboot us.
24250 */
24251-static void lguest_restart(char *reason)
24252+static __noreturn void lguest_restart(char *reason)
24253 {
24254 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
24255+ BUG();
24256 }
24257
24258 /*G:050
24259diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
24260index 00933d5..3a64af9 100644
24261--- a/arch/x86/lib/atomic64_386_32.S
24262+++ b/arch/x86/lib/atomic64_386_32.S
24263@@ -48,6 +48,10 @@ BEGIN(read)
24264 movl (v), %eax
24265 movl 4(v), %edx
24266 RET_ENDP
24267+BEGIN(read_unchecked)
24268+ movl (v), %eax
24269+ movl 4(v), %edx
24270+RET_ENDP
24271 #undef v
24272
24273 #define v %esi
24274@@ -55,6 +59,10 @@ BEGIN(set)
24275 movl %ebx, (v)
24276 movl %ecx, 4(v)
24277 RET_ENDP
24278+BEGIN(set_unchecked)
24279+ movl %ebx, (v)
24280+ movl %ecx, 4(v)
24281+RET_ENDP
24282 #undef v
24283
24284 #define v %esi
24285@@ -70,6 +78,20 @@ RET_ENDP
24286 BEGIN(add)
24287 addl %eax, (v)
24288 adcl %edx, 4(v)
24289+
24290+#ifdef CONFIG_PAX_REFCOUNT
24291+ jno 0f
24292+ subl %eax, (v)
24293+ sbbl %edx, 4(v)
24294+ int $4
24295+0:
24296+ _ASM_EXTABLE(0b, 0b)
24297+#endif
24298+
24299+RET_ENDP
24300+BEGIN(add_unchecked)
24301+ addl %eax, (v)
24302+ adcl %edx, 4(v)
24303 RET_ENDP
24304 #undef v
24305
24306@@ -77,6 +99,24 @@ RET_ENDP
24307 BEGIN(add_return)
24308 addl (v), %eax
24309 adcl 4(v), %edx
24310+
24311+#ifdef CONFIG_PAX_REFCOUNT
24312+ into
24313+1234:
24314+ _ASM_EXTABLE(1234b, 2f)
24315+#endif
24316+
24317+ movl %eax, (v)
24318+ movl %edx, 4(v)
24319+
24320+#ifdef CONFIG_PAX_REFCOUNT
24321+2:
24322+#endif
24323+
24324+RET_ENDP
24325+BEGIN(add_return_unchecked)
24326+ addl (v), %eax
24327+ adcl 4(v), %edx
24328 movl %eax, (v)
24329 movl %edx, 4(v)
24330 RET_ENDP
24331@@ -86,6 +126,20 @@ RET_ENDP
24332 BEGIN(sub)
24333 subl %eax, (v)
24334 sbbl %edx, 4(v)
24335+
24336+#ifdef CONFIG_PAX_REFCOUNT
24337+ jno 0f
24338+ addl %eax, (v)
24339+ adcl %edx, 4(v)
24340+ int $4
24341+0:
24342+ _ASM_EXTABLE(0b, 0b)
24343+#endif
24344+
24345+RET_ENDP
24346+BEGIN(sub_unchecked)
24347+ subl %eax, (v)
24348+ sbbl %edx, 4(v)
24349 RET_ENDP
24350 #undef v
24351
24352@@ -96,6 +150,27 @@ BEGIN(sub_return)
24353 sbbl $0, %edx
24354 addl (v), %eax
24355 adcl 4(v), %edx
24356+
24357+#ifdef CONFIG_PAX_REFCOUNT
24358+ into
24359+1234:
24360+ _ASM_EXTABLE(1234b, 2f)
24361+#endif
24362+
24363+ movl %eax, (v)
24364+ movl %edx, 4(v)
24365+
24366+#ifdef CONFIG_PAX_REFCOUNT
24367+2:
24368+#endif
24369+
24370+RET_ENDP
24371+BEGIN(sub_return_unchecked)
24372+ negl %edx
24373+ negl %eax
24374+ sbbl $0, %edx
24375+ addl (v), %eax
24376+ adcl 4(v), %edx
24377 movl %eax, (v)
24378 movl %edx, 4(v)
24379 RET_ENDP
24380@@ -105,6 +180,20 @@ RET_ENDP
24381 BEGIN(inc)
24382 addl $1, (v)
24383 adcl $0, 4(v)
24384+
24385+#ifdef CONFIG_PAX_REFCOUNT
24386+ jno 0f
24387+ subl $1, (v)
24388+ sbbl $0, 4(v)
24389+ int $4
24390+0:
24391+ _ASM_EXTABLE(0b, 0b)
24392+#endif
24393+
24394+RET_ENDP
24395+BEGIN(inc_unchecked)
24396+ addl $1, (v)
24397+ adcl $0, 4(v)
24398 RET_ENDP
24399 #undef v
24400
24401@@ -114,6 +203,26 @@ BEGIN(inc_return)
24402 movl 4(v), %edx
24403 addl $1, %eax
24404 adcl $0, %edx
24405+
24406+#ifdef CONFIG_PAX_REFCOUNT
24407+ into
24408+1234:
24409+ _ASM_EXTABLE(1234b, 2f)
24410+#endif
24411+
24412+ movl %eax, (v)
24413+ movl %edx, 4(v)
24414+
24415+#ifdef CONFIG_PAX_REFCOUNT
24416+2:
24417+#endif
24418+
24419+RET_ENDP
24420+BEGIN(inc_return_unchecked)
24421+ movl (v), %eax
24422+ movl 4(v), %edx
24423+ addl $1, %eax
24424+ adcl $0, %edx
24425 movl %eax, (v)
24426 movl %edx, 4(v)
24427 RET_ENDP
24428@@ -123,6 +232,20 @@ RET_ENDP
24429 BEGIN(dec)
24430 subl $1, (v)
24431 sbbl $0, 4(v)
24432+
24433+#ifdef CONFIG_PAX_REFCOUNT
24434+ jno 0f
24435+ addl $1, (v)
24436+ adcl $0, 4(v)
24437+ int $4
24438+0:
24439+ _ASM_EXTABLE(0b, 0b)
24440+#endif
24441+
24442+RET_ENDP
24443+BEGIN(dec_unchecked)
24444+ subl $1, (v)
24445+ sbbl $0, 4(v)
24446 RET_ENDP
24447 #undef v
24448
24449@@ -132,6 +255,26 @@ BEGIN(dec_return)
24450 movl 4(v), %edx
24451 subl $1, %eax
24452 sbbl $0, %edx
24453+
24454+#ifdef CONFIG_PAX_REFCOUNT
24455+ into
24456+1234:
24457+ _ASM_EXTABLE(1234b, 2f)
24458+#endif
24459+
24460+ movl %eax, (v)
24461+ movl %edx, 4(v)
24462+
24463+#ifdef CONFIG_PAX_REFCOUNT
24464+2:
24465+#endif
24466+
24467+RET_ENDP
24468+BEGIN(dec_return_unchecked)
24469+ movl (v), %eax
24470+ movl 4(v), %edx
24471+ subl $1, %eax
24472+ sbbl $0, %edx
24473 movl %eax, (v)
24474 movl %edx, 4(v)
24475 RET_ENDP
24476@@ -143,6 +286,13 @@ BEGIN(add_unless)
24477 adcl %edx, %edi
24478 addl (v), %eax
24479 adcl 4(v), %edx
24480+
24481+#ifdef CONFIG_PAX_REFCOUNT
24482+ into
24483+1234:
24484+ _ASM_EXTABLE(1234b, 2f)
24485+#endif
24486+
24487 cmpl %eax, %ecx
24488 je 3f
24489 1:
24490@@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
24491 1:
24492 addl $1, %eax
24493 adcl $0, %edx
24494+
24495+#ifdef CONFIG_PAX_REFCOUNT
24496+ into
24497+1234:
24498+ _ASM_EXTABLE(1234b, 2f)
24499+#endif
24500+
24501 movl %eax, (v)
24502 movl %edx, 4(v)
24503 movl $1, %eax
24504@@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
24505 movl 4(v), %edx
24506 subl $1, %eax
24507 sbbl $0, %edx
24508+
24509+#ifdef CONFIG_PAX_REFCOUNT
24510+ into
24511+1234:
24512+ _ASM_EXTABLE(1234b, 1f)
24513+#endif
24514+
24515 js 1f
24516 movl %eax, (v)
24517 movl %edx, 4(v)
24518diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
24519index f5cc9eb..51fa319 100644
24520--- a/arch/x86/lib/atomic64_cx8_32.S
24521+++ b/arch/x86/lib/atomic64_cx8_32.S
24522@@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
24523 CFI_STARTPROC
24524
24525 read64 %ecx
24526+ pax_force_retaddr
24527 ret
24528 CFI_ENDPROC
24529 ENDPROC(atomic64_read_cx8)
24530
24531+ENTRY(atomic64_read_unchecked_cx8)
24532+ CFI_STARTPROC
24533+
24534+ read64 %ecx
24535+ pax_force_retaddr
24536+ ret
24537+ CFI_ENDPROC
24538+ENDPROC(atomic64_read_unchecked_cx8)
24539+
24540 ENTRY(atomic64_set_cx8)
24541 CFI_STARTPROC
24542
24543@@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
24544 cmpxchg8b (%esi)
24545 jne 1b
24546
24547+ pax_force_retaddr
24548 ret
24549 CFI_ENDPROC
24550 ENDPROC(atomic64_set_cx8)
24551
24552+ENTRY(atomic64_set_unchecked_cx8)
24553+ CFI_STARTPROC
24554+
24555+1:
24556+/* we don't need LOCK_PREFIX since aligned 64-bit writes
24557+ * are atomic on 586 and newer */
24558+ cmpxchg8b (%esi)
24559+ jne 1b
24560+
24561+ pax_force_retaddr
24562+ ret
24563+ CFI_ENDPROC
24564+ENDPROC(atomic64_set_unchecked_cx8)
24565+
24566 ENTRY(atomic64_xchg_cx8)
24567 CFI_STARTPROC
24568
24569@@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
24570 cmpxchg8b (%esi)
24571 jne 1b
24572
24573+ pax_force_retaddr
24574 ret
24575 CFI_ENDPROC
24576 ENDPROC(atomic64_xchg_cx8)
24577
24578-.macro addsub_return func ins insc
24579-ENTRY(atomic64_\func\()_return_cx8)
24580+.macro addsub_return func ins insc unchecked=""
24581+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24582 CFI_STARTPROC
24583 SAVE ebp
24584 SAVE ebx
24585@@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
24586 movl %edx, %ecx
24587 \ins\()l %esi, %ebx
24588 \insc\()l %edi, %ecx
24589+
24590+.ifb \unchecked
24591+#ifdef CONFIG_PAX_REFCOUNT
24592+ into
24593+2:
24594+ _ASM_EXTABLE(2b, 3f)
24595+#endif
24596+.endif
24597+
24598 LOCK_PREFIX
24599 cmpxchg8b (%ebp)
24600 jne 1b
24601-
24602-10:
24603 movl %ebx, %eax
24604 movl %ecx, %edx
24605+
24606+.ifb \unchecked
24607+#ifdef CONFIG_PAX_REFCOUNT
24608+3:
24609+#endif
24610+.endif
24611+
24612 RESTORE edi
24613 RESTORE esi
24614 RESTORE ebx
24615 RESTORE ebp
24616+ pax_force_retaddr
24617 ret
24618 CFI_ENDPROC
24619-ENDPROC(atomic64_\func\()_return_cx8)
24620+ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
24621 .endm
24622
24623 addsub_return add add adc
24624 addsub_return sub sub sbb
24625+addsub_return add add adc _unchecked
24626+addsub_return sub sub sbb _unchecked
24627
24628-.macro incdec_return func ins insc
24629-ENTRY(atomic64_\func\()_return_cx8)
24630+.macro incdec_return func ins insc unchecked=""
24631+ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
24632 CFI_STARTPROC
24633 SAVE ebx
24634
24635@@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
24636 movl %edx, %ecx
24637 \ins\()l $1, %ebx
24638 \insc\()l $0, %ecx
24639+
24640+.ifb \unchecked
24641+#ifdef CONFIG_PAX_REFCOUNT
24642+ into
24643+2:
24644+ _ASM_EXTABLE(2b, 3f)
24645+#endif
24646+.endif
24647+
24648 LOCK_PREFIX
24649 cmpxchg8b (%esi)
24650 jne 1b
24651
24652-10:
24653 movl %ebx, %eax
24654 movl %ecx, %edx
24655+
24656+.ifb \unchecked
24657+#ifdef CONFIG_PAX_REFCOUNT
24658+3:
24659+#endif
24660+.endif
24661+
24662 RESTORE ebx
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 incdec_return inc add adc
24671 incdec_return dec sub sbb
24672+incdec_return inc add adc _unchecked
24673+incdec_return dec sub sbb _unchecked
24674
24675 ENTRY(atomic64_dec_if_positive_cx8)
24676 CFI_STARTPROC
24677@@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
24678 movl %edx, %ecx
24679 subl $1, %ebx
24680 sbb $0, %ecx
24681+
24682+#ifdef CONFIG_PAX_REFCOUNT
24683+ into
24684+1234:
24685+ _ASM_EXTABLE(1234b, 2f)
24686+#endif
24687+
24688 js 2f
24689 LOCK_PREFIX
24690 cmpxchg8b (%esi)
24691@@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
24692 movl %ebx, %eax
24693 movl %ecx, %edx
24694 RESTORE ebx
24695+ pax_force_retaddr
24696 ret
24697 CFI_ENDPROC
24698 ENDPROC(atomic64_dec_if_positive_cx8)
24699@@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
24700 movl %edx, %ecx
24701 addl %ebp, %ebx
24702 adcl %edi, %ecx
24703+
24704+#ifdef CONFIG_PAX_REFCOUNT
24705+ into
24706+1234:
24707+ _ASM_EXTABLE(1234b, 3f)
24708+#endif
24709+
24710 LOCK_PREFIX
24711 cmpxchg8b (%esi)
24712 jne 1b
24713@@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
24714 CFI_ADJUST_CFA_OFFSET -8
24715 RESTORE ebx
24716 RESTORE ebp
24717+ pax_force_retaddr
24718 ret
24719 4:
24720 cmpl %edx, 4(%esp)
24721@@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
24722 xorl %ecx, %ecx
24723 addl $1, %ebx
24724 adcl %edx, %ecx
24725+
24726+#ifdef CONFIG_PAX_REFCOUNT
24727+ into
24728+1234:
24729+ _ASM_EXTABLE(1234b, 3f)
24730+#endif
24731+
24732 LOCK_PREFIX
24733 cmpxchg8b (%esi)
24734 jne 1b
24735@@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
24736 movl $1, %eax
24737 3:
24738 RESTORE ebx
24739+ pax_force_retaddr
24740 ret
24741 CFI_ENDPROC
24742 ENDPROC(atomic64_inc_not_zero_cx8)
24743diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
24744index 2af5df3..62b1a5a 100644
24745--- a/arch/x86/lib/checksum_32.S
24746+++ b/arch/x86/lib/checksum_32.S
24747@@ -29,7 +29,8 @@
24748 #include <asm/dwarf2.h>
24749 #include <asm/errno.h>
24750 #include <asm/asm.h>
24751-
24752+#include <asm/segment.h>
24753+
24754 /*
24755 * computes a partial checksum, e.g. for TCP/UDP fragments
24756 */
24757@@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
24758
24759 #define ARGBASE 16
24760 #define FP 12
24761-
24762-ENTRY(csum_partial_copy_generic)
24763+
24764+ENTRY(csum_partial_copy_generic_to_user)
24765 CFI_STARTPROC
24766+
24767+#ifdef CONFIG_PAX_MEMORY_UDEREF
24768+ pushl_cfi %gs
24769+ popl_cfi %es
24770+ jmp csum_partial_copy_generic
24771+#endif
24772+
24773+ENTRY(csum_partial_copy_generic_from_user)
24774+
24775+#ifdef CONFIG_PAX_MEMORY_UDEREF
24776+ pushl_cfi %gs
24777+ popl_cfi %ds
24778+#endif
24779+
24780+ENTRY(csum_partial_copy_generic)
24781 subl $4,%esp
24782 CFI_ADJUST_CFA_OFFSET 4
24783 pushl_cfi %edi
24784@@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
24785 jmp 4f
24786 SRC(1: movw (%esi), %bx )
24787 addl $2, %esi
24788-DST( movw %bx, (%edi) )
24789+DST( movw %bx, %es:(%edi) )
24790 addl $2, %edi
24791 addw %bx, %ax
24792 adcl $0, %eax
24793@@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
24794 SRC(1: movl (%esi), %ebx )
24795 SRC( movl 4(%esi), %edx )
24796 adcl %ebx, %eax
24797-DST( movl %ebx, (%edi) )
24798+DST( movl %ebx, %es:(%edi) )
24799 adcl %edx, %eax
24800-DST( movl %edx, 4(%edi) )
24801+DST( movl %edx, %es:4(%edi) )
24802
24803 SRC( movl 8(%esi), %ebx )
24804 SRC( movl 12(%esi), %edx )
24805 adcl %ebx, %eax
24806-DST( movl %ebx, 8(%edi) )
24807+DST( movl %ebx, %es:8(%edi) )
24808 adcl %edx, %eax
24809-DST( movl %edx, 12(%edi) )
24810+DST( movl %edx, %es:12(%edi) )
24811
24812 SRC( movl 16(%esi), %ebx )
24813 SRC( movl 20(%esi), %edx )
24814 adcl %ebx, %eax
24815-DST( movl %ebx, 16(%edi) )
24816+DST( movl %ebx, %es:16(%edi) )
24817 adcl %edx, %eax
24818-DST( movl %edx, 20(%edi) )
24819+DST( movl %edx, %es:20(%edi) )
24820
24821 SRC( movl 24(%esi), %ebx )
24822 SRC( movl 28(%esi), %edx )
24823 adcl %ebx, %eax
24824-DST( movl %ebx, 24(%edi) )
24825+DST( movl %ebx, %es:24(%edi) )
24826 adcl %edx, %eax
24827-DST( movl %edx, 28(%edi) )
24828+DST( movl %edx, %es:28(%edi) )
24829
24830 lea 32(%esi), %esi
24831 lea 32(%edi), %edi
24832@@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
24833 shrl $2, %edx # This clears CF
24834 SRC(3: movl (%esi), %ebx )
24835 adcl %ebx, %eax
24836-DST( movl %ebx, (%edi) )
24837+DST( movl %ebx, %es:(%edi) )
24838 lea 4(%esi), %esi
24839 lea 4(%edi), %edi
24840 dec %edx
24841@@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
24842 jb 5f
24843 SRC( movw (%esi), %cx )
24844 leal 2(%esi), %esi
24845-DST( movw %cx, (%edi) )
24846+DST( movw %cx, %es:(%edi) )
24847 leal 2(%edi), %edi
24848 je 6f
24849 shll $16,%ecx
24850 SRC(5: movb (%esi), %cl )
24851-DST( movb %cl, (%edi) )
24852+DST( movb %cl, %es:(%edi) )
24853 6: addl %ecx, %eax
24854 adcl $0, %eax
24855 7:
24856@@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
24857
24858 6001:
24859 movl ARGBASE+20(%esp), %ebx # src_err_ptr
24860- movl $-EFAULT, (%ebx)
24861+ movl $-EFAULT, %ss:(%ebx)
24862
24863 # zero the complete destination - computing the rest
24864 # is too much work
24865@@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
24866
24867 6002:
24868 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24869- movl $-EFAULT,(%ebx)
24870+ movl $-EFAULT,%ss:(%ebx)
24871 jmp 5000b
24872
24873 .previous
24874
24875+ pushl_cfi %ss
24876+ popl_cfi %ds
24877+ pushl_cfi %ss
24878+ popl_cfi %es
24879 popl_cfi %ebx
24880 CFI_RESTORE ebx
24881 popl_cfi %esi
24882@@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
24883 popl_cfi %ecx # equivalent to addl $4,%esp
24884 ret
24885 CFI_ENDPROC
24886-ENDPROC(csum_partial_copy_generic)
24887+ENDPROC(csum_partial_copy_generic_to_user)
24888
24889 #else
24890
24891 /* Version for PentiumII/PPro */
24892
24893 #define ROUND1(x) \
24894+ nop; nop; nop; \
24895 SRC(movl x(%esi), %ebx ) ; \
24896 addl %ebx, %eax ; \
24897- DST(movl %ebx, x(%edi) ) ;
24898+ DST(movl %ebx, %es:x(%edi)) ;
24899
24900 #define ROUND(x) \
24901+ nop; nop; nop; \
24902 SRC(movl x(%esi), %ebx ) ; \
24903 adcl %ebx, %eax ; \
24904- DST(movl %ebx, x(%edi) ) ;
24905+ DST(movl %ebx, %es:x(%edi)) ;
24906
24907 #define ARGBASE 12
24908-
24909-ENTRY(csum_partial_copy_generic)
24910+
24911+ENTRY(csum_partial_copy_generic_to_user)
24912 CFI_STARTPROC
24913+
24914+#ifdef CONFIG_PAX_MEMORY_UDEREF
24915+ pushl_cfi %gs
24916+ popl_cfi %es
24917+ jmp csum_partial_copy_generic
24918+#endif
24919+
24920+ENTRY(csum_partial_copy_generic_from_user)
24921+
24922+#ifdef CONFIG_PAX_MEMORY_UDEREF
24923+ pushl_cfi %gs
24924+ popl_cfi %ds
24925+#endif
24926+
24927+ENTRY(csum_partial_copy_generic)
24928 pushl_cfi %ebx
24929 CFI_REL_OFFSET ebx, 0
24930 pushl_cfi %edi
24931@@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
24932 subl %ebx, %edi
24933 lea -1(%esi),%edx
24934 andl $-32,%edx
24935- lea 3f(%ebx,%ebx), %ebx
24936+ lea 3f(%ebx,%ebx,2), %ebx
24937 testl %esi, %esi
24938 jmp *%ebx
24939 1: addl $64,%esi
24940@@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
24941 jb 5f
24942 SRC( movw (%esi), %dx )
24943 leal 2(%esi), %esi
24944-DST( movw %dx, (%edi) )
24945+DST( movw %dx, %es:(%edi) )
24946 leal 2(%edi), %edi
24947 je 6f
24948 shll $16,%edx
24949 5:
24950 SRC( movb (%esi), %dl )
24951-DST( movb %dl, (%edi) )
24952+DST( movb %dl, %es:(%edi) )
24953 6: addl %edx, %eax
24954 adcl $0, %eax
24955 7:
24956 .section .fixup, "ax"
24957 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
24958- movl $-EFAULT, (%ebx)
24959+ movl $-EFAULT, %ss:(%ebx)
24960 # zero the complete destination (computing the rest is too much work)
24961 movl ARGBASE+8(%esp),%edi # dst
24962 movl ARGBASE+12(%esp),%ecx # len
24963@@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
24964 rep; stosb
24965 jmp 7b
24966 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
24967- movl $-EFAULT, (%ebx)
24968+ movl $-EFAULT, %ss:(%ebx)
24969 jmp 7b
24970 .previous
24971
24972+#ifdef CONFIG_PAX_MEMORY_UDEREF
24973+ pushl_cfi %ss
24974+ popl_cfi %ds
24975+ pushl_cfi %ss
24976+ popl_cfi %es
24977+#endif
24978+
24979 popl_cfi %esi
24980 CFI_RESTORE esi
24981 popl_cfi %edi
24982@@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
24983 CFI_RESTORE ebx
24984 ret
24985 CFI_ENDPROC
24986-ENDPROC(csum_partial_copy_generic)
24987+ENDPROC(csum_partial_copy_generic_to_user)
24988
24989 #undef ROUND
24990 #undef ROUND1
24991diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
24992index f2145cf..cea889d 100644
24993--- a/arch/x86/lib/clear_page_64.S
24994+++ b/arch/x86/lib/clear_page_64.S
24995@@ -11,6 +11,7 @@ ENTRY(clear_page_c)
24996 movl $4096/8,%ecx
24997 xorl %eax,%eax
24998 rep stosq
24999+ pax_force_retaddr
25000 ret
25001 CFI_ENDPROC
25002 ENDPROC(clear_page_c)
25003@@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
25004 movl $4096,%ecx
25005 xorl %eax,%eax
25006 rep stosb
25007+ pax_force_retaddr
25008 ret
25009 CFI_ENDPROC
25010 ENDPROC(clear_page_c_e)
25011@@ -43,6 +45,7 @@ ENTRY(clear_page)
25012 leaq 64(%rdi),%rdi
25013 jnz .Lloop
25014 nop
25015+ pax_force_retaddr
25016 ret
25017 CFI_ENDPROC
25018 .Lclear_page_end:
25019@@ -58,7 +61,7 @@ ENDPROC(clear_page)
25020
25021 #include <asm/cpufeature.h>
25022
25023- .section .altinstr_replacement,"ax"
25024+ .section .altinstr_replacement,"a"
25025 1: .byte 0xeb /* jmp <disp8> */
25026 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
25027 2: .byte 0xeb /* jmp <disp8> */
25028diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
25029index 1e572c5..2a162cd 100644
25030--- a/arch/x86/lib/cmpxchg16b_emu.S
25031+++ b/arch/x86/lib/cmpxchg16b_emu.S
25032@@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
25033
25034 popf
25035 mov $1, %al
25036+ pax_force_retaddr
25037 ret
25038
25039 not_same:
25040 popf
25041 xor %al,%al
25042+ pax_force_retaddr
25043 ret
25044
25045 CFI_ENDPROC
25046diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
25047index 176cca6..1166c50 100644
25048--- a/arch/x86/lib/copy_page_64.S
25049+++ b/arch/x86/lib/copy_page_64.S
25050@@ -9,6 +9,7 @@ copy_page_rep:
25051 CFI_STARTPROC
25052 movl $4096/8, %ecx
25053 rep movsq
25054+ pax_force_retaddr
25055 ret
25056 CFI_ENDPROC
25057 ENDPROC(copy_page_rep)
25058@@ -20,12 +21,14 @@ ENDPROC(copy_page_rep)
25059
25060 ENTRY(copy_page)
25061 CFI_STARTPROC
25062- subq $2*8, %rsp
25063- CFI_ADJUST_CFA_OFFSET 2*8
25064+ subq $3*8, %rsp
25065+ CFI_ADJUST_CFA_OFFSET 3*8
25066 movq %rbx, (%rsp)
25067 CFI_REL_OFFSET rbx, 0
25068 movq %r12, 1*8(%rsp)
25069 CFI_REL_OFFSET r12, 1*8
25070+ movq %r13, 2*8(%rsp)
25071+ CFI_REL_OFFSET r13, 2*8
25072
25073 movl $(4096/64)-5, %ecx
25074 .p2align 4
25075@@ -36,7 +39,7 @@ ENTRY(copy_page)
25076 movq 0x8*2(%rsi), %rdx
25077 movq 0x8*3(%rsi), %r8
25078 movq 0x8*4(%rsi), %r9
25079- movq 0x8*5(%rsi), %r10
25080+ movq 0x8*5(%rsi), %r13
25081 movq 0x8*6(%rsi), %r11
25082 movq 0x8*7(%rsi), %r12
25083
25084@@ -47,7 +50,7 @@ ENTRY(copy_page)
25085 movq %rdx, 0x8*2(%rdi)
25086 movq %r8, 0x8*3(%rdi)
25087 movq %r9, 0x8*4(%rdi)
25088- movq %r10, 0x8*5(%rdi)
25089+ movq %r13, 0x8*5(%rdi)
25090 movq %r11, 0x8*6(%rdi)
25091 movq %r12, 0x8*7(%rdi)
25092
25093@@ -66,7 +69,7 @@ ENTRY(copy_page)
25094 movq 0x8*2(%rsi), %rdx
25095 movq 0x8*3(%rsi), %r8
25096 movq 0x8*4(%rsi), %r9
25097- movq 0x8*5(%rsi), %r10
25098+ movq 0x8*5(%rsi), %r13
25099 movq 0x8*6(%rsi), %r11
25100 movq 0x8*7(%rsi), %r12
25101
25102@@ -75,7 +78,7 @@ ENTRY(copy_page)
25103 movq %rdx, 0x8*2(%rdi)
25104 movq %r8, 0x8*3(%rdi)
25105 movq %r9, 0x8*4(%rdi)
25106- movq %r10, 0x8*5(%rdi)
25107+ movq %r13, 0x8*5(%rdi)
25108 movq %r11, 0x8*6(%rdi)
25109 movq %r12, 0x8*7(%rdi)
25110
25111@@ -87,8 +90,11 @@ ENTRY(copy_page)
25112 CFI_RESTORE rbx
25113 movq 1*8(%rsp), %r12
25114 CFI_RESTORE r12
25115- addq $2*8, %rsp
25116- CFI_ADJUST_CFA_OFFSET -2*8
25117+ movq 2*8(%rsp), %r13
25118+ CFI_RESTORE r13
25119+ addq $3*8, %rsp
25120+ CFI_ADJUST_CFA_OFFSET -3*8
25121+ pax_force_retaddr
25122 ret
25123 .Lcopy_page_end:
25124 CFI_ENDPROC
25125@@ -99,7 +105,7 @@ ENDPROC(copy_page)
25126
25127 #include <asm/cpufeature.h>
25128
25129- .section .altinstr_replacement,"ax"
25130+ .section .altinstr_replacement,"a"
25131 1: .byte 0xeb /* jmp <disp8> */
25132 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
25133 2:
25134diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
25135index a30ca15..d25fab6 100644
25136--- a/arch/x86/lib/copy_user_64.S
25137+++ b/arch/x86/lib/copy_user_64.S
25138@@ -18,6 +18,7 @@
25139 #include <asm/alternative-asm.h>
25140 #include <asm/asm.h>
25141 #include <asm/smap.h>
25142+#include <asm/pgtable.h>
25143
25144 /*
25145 * By placing feature2 after feature1 in altinstructions section, we logically
25146@@ -31,7 +32,7 @@
25147 .byte 0xe9 /* 32bit jump */
25148 .long \orig-1f /* by default jump to orig */
25149 1:
25150- .section .altinstr_replacement,"ax"
25151+ .section .altinstr_replacement,"a"
25152 2: .byte 0xe9 /* near jump with 32bit immediate */
25153 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
25154 3: .byte 0xe9 /* near jump with 32bit immediate */
25155@@ -70,47 +71,20 @@
25156 #endif
25157 .endm
25158
25159-/* Standard copy_to_user with segment limit checking */
25160-ENTRY(_copy_to_user)
25161- CFI_STARTPROC
25162- GET_THREAD_INFO(%rax)
25163- movq %rdi,%rcx
25164- addq %rdx,%rcx
25165- jc bad_to_user
25166- cmpq TI_addr_limit(%rax),%rcx
25167- ja bad_to_user
25168- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25169- copy_user_generic_unrolled,copy_user_generic_string, \
25170- copy_user_enhanced_fast_string
25171- CFI_ENDPROC
25172-ENDPROC(_copy_to_user)
25173-
25174-/* Standard copy_from_user with segment limit checking */
25175-ENTRY(_copy_from_user)
25176- CFI_STARTPROC
25177- GET_THREAD_INFO(%rax)
25178- movq %rsi,%rcx
25179- addq %rdx,%rcx
25180- jc bad_from_user
25181- cmpq TI_addr_limit(%rax),%rcx
25182- ja bad_from_user
25183- ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
25184- copy_user_generic_unrolled,copy_user_generic_string, \
25185- copy_user_enhanced_fast_string
25186- CFI_ENDPROC
25187-ENDPROC(_copy_from_user)
25188-
25189 .section .fixup,"ax"
25190 /* must zero dest */
25191 ENTRY(bad_from_user)
25192 bad_from_user:
25193 CFI_STARTPROC
25194+ testl %edx,%edx
25195+ js bad_to_user
25196 movl %edx,%ecx
25197 xorl %eax,%eax
25198 rep
25199 stosb
25200 bad_to_user:
25201 movl %edx,%eax
25202+ pax_force_retaddr
25203 ret
25204 CFI_ENDPROC
25205 ENDPROC(bad_from_user)
25206@@ -141,19 +115,19 @@ ENTRY(copy_user_generic_unrolled)
25207 jz 17f
25208 1: movq (%rsi),%r8
25209 2: movq 1*8(%rsi),%r9
25210-3: movq 2*8(%rsi),%r10
25211+3: movq 2*8(%rsi),%rax
25212 4: movq 3*8(%rsi),%r11
25213 5: movq %r8,(%rdi)
25214 6: movq %r9,1*8(%rdi)
25215-7: movq %r10,2*8(%rdi)
25216+7: movq %rax,2*8(%rdi)
25217 8: movq %r11,3*8(%rdi)
25218 9: movq 4*8(%rsi),%r8
25219 10: movq 5*8(%rsi),%r9
25220-11: movq 6*8(%rsi),%r10
25221+11: movq 6*8(%rsi),%rax
25222 12: movq 7*8(%rsi),%r11
25223 13: movq %r8,4*8(%rdi)
25224 14: movq %r9,5*8(%rdi)
25225-15: movq %r10,6*8(%rdi)
25226+15: movq %rax,6*8(%rdi)
25227 16: movq %r11,7*8(%rdi)
25228 leaq 64(%rsi),%rsi
25229 leaq 64(%rdi),%rdi
25230@@ -180,6 +154,7 @@ ENTRY(copy_user_generic_unrolled)
25231 jnz 21b
25232 23: xor %eax,%eax
25233 ASM_CLAC
25234+ pax_force_retaddr
25235 ret
25236
25237 .section .fixup,"ax"
25238@@ -251,6 +226,7 @@ ENTRY(copy_user_generic_string)
25239 movsb
25240 4: xorl %eax,%eax
25241 ASM_CLAC
25242+ pax_force_retaddr
25243 ret
25244
25245 .section .fixup,"ax"
25246@@ -286,6 +262,7 @@ ENTRY(copy_user_enhanced_fast_string)
25247 movsb
25248 2: xorl %eax,%eax
25249 ASM_CLAC
25250+ pax_force_retaddr
25251 ret
25252
25253 .section .fixup,"ax"
25254diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
25255index 6a4f43c..f08b4a2 100644
25256--- a/arch/x86/lib/copy_user_nocache_64.S
25257+++ b/arch/x86/lib/copy_user_nocache_64.S
25258@@ -8,6 +8,7 @@
25259
25260 #include <linux/linkage.h>
25261 #include <asm/dwarf2.h>
25262+#include <asm/alternative-asm.h>
25263
25264 #define FIX_ALIGNMENT 1
25265
25266@@ -16,6 +17,7 @@
25267 #include <asm/thread_info.h>
25268 #include <asm/asm.h>
25269 #include <asm/smap.h>
25270+#include <asm/pgtable.h>
25271
25272 .macro ALIGN_DESTINATION
25273 #ifdef FIX_ALIGNMENT
25274@@ -49,6 +51,15 @@
25275 */
25276 ENTRY(__copy_user_nocache)
25277 CFI_STARTPROC
25278+
25279+#ifdef CONFIG_PAX_MEMORY_UDEREF
25280+ mov pax_user_shadow_base,%rcx
25281+ cmp %rcx,%rsi
25282+ jae 1f
25283+ add %rcx,%rsi
25284+1:
25285+#endif
25286+
25287 ASM_STAC
25288 cmpl $8,%edx
25289 jb 20f /* less then 8 bytes, go to byte copy loop */
25290@@ -59,19 +70,19 @@ ENTRY(__copy_user_nocache)
25291 jz 17f
25292 1: movq (%rsi),%r8
25293 2: movq 1*8(%rsi),%r9
25294-3: movq 2*8(%rsi),%r10
25295+3: movq 2*8(%rsi),%rax
25296 4: movq 3*8(%rsi),%r11
25297 5: movnti %r8,(%rdi)
25298 6: movnti %r9,1*8(%rdi)
25299-7: movnti %r10,2*8(%rdi)
25300+7: movnti %rax,2*8(%rdi)
25301 8: movnti %r11,3*8(%rdi)
25302 9: movq 4*8(%rsi),%r8
25303 10: movq 5*8(%rsi),%r9
25304-11: movq 6*8(%rsi),%r10
25305+11: movq 6*8(%rsi),%rax
25306 12: movq 7*8(%rsi),%r11
25307 13: movnti %r8,4*8(%rdi)
25308 14: movnti %r9,5*8(%rdi)
25309-15: movnti %r10,6*8(%rdi)
25310+15: movnti %rax,6*8(%rdi)
25311 16: movnti %r11,7*8(%rdi)
25312 leaq 64(%rsi),%rsi
25313 leaq 64(%rdi),%rdi
25314@@ -99,6 +110,7 @@ ENTRY(__copy_user_nocache)
25315 23: xorl %eax,%eax
25316 ASM_CLAC
25317 sfence
25318+ pax_force_retaddr
25319 ret
25320
25321 .section .fixup,"ax"
25322diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
25323index 2419d5f..953ee51 100644
25324--- a/arch/x86/lib/csum-copy_64.S
25325+++ b/arch/x86/lib/csum-copy_64.S
25326@@ -9,6 +9,7 @@
25327 #include <asm/dwarf2.h>
25328 #include <asm/errno.h>
25329 #include <asm/asm.h>
25330+#include <asm/alternative-asm.h>
25331
25332 /*
25333 * Checksum copy with exception handling.
25334@@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
25335 CFI_RESTORE rbp
25336 addq $7*8, %rsp
25337 CFI_ADJUST_CFA_OFFSET -7*8
25338+ pax_force_retaddr 0, 1
25339 ret
25340 CFI_RESTORE_STATE
25341
25342diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
25343index 25b7ae8..169fafc 100644
25344--- a/arch/x86/lib/csum-wrappers_64.c
25345+++ b/arch/x86/lib/csum-wrappers_64.c
25346@@ -52,7 +52,7 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
25347 len -= 2;
25348 }
25349 }
25350- isum = csum_partial_copy_generic((__force const void *)src,
25351+ isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
25352 dst, len, isum, errp, NULL);
25353 if (unlikely(*errp))
25354 goto out_err;
25355@@ -105,7 +105,7 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
25356 }
25357
25358 *errp = 0;
25359- return csum_partial_copy_generic(src, (void __force *)dst,
25360+ return csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
25361 len, isum, NULL, errp);
25362 }
25363 EXPORT_SYMBOL(csum_partial_copy_to_user);
25364diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
25365index a451235..79fb5cf 100644
25366--- a/arch/x86/lib/getuser.S
25367+++ b/arch/x86/lib/getuser.S
25368@@ -33,17 +33,40 @@
25369 #include <asm/thread_info.h>
25370 #include <asm/asm.h>
25371 #include <asm/smap.h>
25372+#include <asm/segment.h>
25373+#include <asm/pgtable.h>
25374+#include <asm/alternative-asm.h>
25375+
25376+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
25377+#define __copyuser_seg gs;
25378+#else
25379+#define __copyuser_seg
25380+#endif
25381
25382 .text
25383 ENTRY(__get_user_1)
25384 CFI_STARTPROC
25385+
25386+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25387 GET_THREAD_INFO(%_ASM_DX)
25388 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25389 jae bad_get_user
25390 ASM_STAC
25391-1: movzbl (%_ASM_AX),%edx
25392+
25393+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25394+ mov pax_user_shadow_base,%_ASM_DX
25395+ cmp %_ASM_DX,%_ASM_AX
25396+ jae 1234f
25397+ add %_ASM_DX,%_ASM_AX
25398+1234:
25399+#endif
25400+
25401+#endif
25402+
25403+1: __copyuser_seg movzbl (%_ASM_AX),%edx
25404 xor %eax,%eax
25405 ASM_CLAC
25406+ pax_force_retaddr
25407 ret
25408 CFI_ENDPROC
25409 ENDPROC(__get_user_1)
25410@@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
25411 ENTRY(__get_user_2)
25412 CFI_STARTPROC
25413 add $1,%_ASM_AX
25414+
25415+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25416 jc bad_get_user
25417 GET_THREAD_INFO(%_ASM_DX)
25418 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25419 jae bad_get_user
25420 ASM_STAC
25421-2: movzwl -1(%_ASM_AX),%edx
25422+
25423+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25424+ mov pax_user_shadow_base,%_ASM_DX
25425+ cmp %_ASM_DX,%_ASM_AX
25426+ jae 1234f
25427+ add %_ASM_DX,%_ASM_AX
25428+1234:
25429+#endif
25430+
25431+#endif
25432+
25433+2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
25434 xor %eax,%eax
25435 ASM_CLAC
25436+ pax_force_retaddr
25437 ret
25438 CFI_ENDPROC
25439 ENDPROC(__get_user_2)
25440@@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
25441 ENTRY(__get_user_4)
25442 CFI_STARTPROC
25443 add $3,%_ASM_AX
25444+
25445+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
25446 jc bad_get_user
25447 GET_THREAD_INFO(%_ASM_DX)
25448 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25449 jae bad_get_user
25450 ASM_STAC
25451-3: movl -3(%_ASM_AX),%edx
25452+
25453+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25454+ mov pax_user_shadow_base,%_ASM_DX
25455+ cmp %_ASM_DX,%_ASM_AX
25456+ jae 1234f
25457+ add %_ASM_DX,%_ASM_AX
25458+1234:
25459+#endif
25460+
25461+#endif
25462+
25463+3: __copyuser_seg movl -3(%_ASM_AX),%edx
25464 xor %eax,%eax
25465 ASM_CLAC
25466+ pax_force_retaddr
25467 ret
25468 CFI_ENDPROC
25469 ENDPROC(__get_user_4)
25470@@ -86,10 +137,20 @@ ENTRY(__get_user_8)
25471 GET_THREAD_INFO(%_ASM_DX)
25472 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
25473 jae bad_get_user
25474+
25475+#ifdef CONFIG_PAX_MEMORY_UDEREF
25476+ mov pax_user_shadow_base,%_ASM_DX
25477+ cmp %_ASM_DX,%_ASM_AX
25478+ jae 1234f
25479+ add %_ASM_DX,%_ASM_AX
25480+1234:
25481+#endif
25482+
25483 ASM_STAC
25484 4: movq -7(%_ASM_AX),%rdx
25485 xor %eax,%eax
25486 ASM_CLAC
25487+ pax_force_retaddr
25488 ret
25489 #else
25490 add $7,%_ASM_AX
25491@@ -102,6 +163,7 @@ ENTRY(__get_user_8)
25492 5: movl -3(%_ASM_AX),%ecx
25493 xor %eax,%eax
25494 ASM_CLAC
25495+ pax_force_retaddr
25496 ret
25497 #endif
25498 CFI_ENDPROC
25499@@ -113,6 +175,7 @@ bad_get_user:
25500 xor %edx,%edx
25501 mov $(-EFAULT),%_ASM_AX
25502 ASM_CLAC
25503+ pax_force_retaddr
25504 ret
25505 CFI_ENDPROC
25506 END(bad_get_user)
25507@@ -124,6 +187,7 @@ bad_get_user_8:
25508 xor %ecx,%ecx
25509 mov $(-EFAULT),%_ASM_AX
25510 ASM_CLAC
25511+ pax_force_retaddr
25512 ret
25513 CFI_ENDPROC
25514 END(bad_get_user_8)
25515diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
25516index 54fcffe..7be149e 100644
25517--- a/arch/x86/lib/insn.c
25518+++ b/arch/x86/lib/insn.c
25519@@ -20,8 +20,10 @@
25520
25521 #ifdef __KERNEL__
25522 #include <linux/string.h>
25523+#include <asm/pgtable_types.h>
25524 #else
25525 #include <string.h>
25526+#define ktla_ktva(addr) addr
25527 #endif
25528 #include <asm/inat.h>
25529 #include <asm/insn.h>
25530@@ -53,8 +55,8 @@
25531 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
25532 {
25533 memset(insn, 0, sizeof(*insn));
25534- insn->kaddr = kaddr;
25535- insn->next_byte = kaddr;
25536+ insn->kaddr = ktla_ktva(kaddr);
25537+ insn->next_byte = ktla_ktva(kaddr);
25538 insn->x86_64 = x86_64 ? 1 : 0;
25539 insn->opnd_bytes = 4;
25540 if (x86_64)
25541diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
25542index 05a95e7..326f2fa 100644
25543--- a/arch/x86/lib/iomap_copy_64.S
25544+++ b/arch/x86/lib/iomap_copy_64.S
25545@@ -17,6 +17,7 @@
25546
25547 #include <linux/linkage.h>
25548 #include <asm/dwarf2.h>
25549+#include <asm/alternative-asm.h>
25550
25551 /*
25552 * override generic version in lib/iomap_copy.c
25553@@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
25554 CFI_STARTPROC
25555 movl %edx,%ecx
25556 rep movsd
25557+ pax_force_retaddr
25558 ret
25559 CFI_ENDPROC
25560 ENDPROC(__iowrite32_copy)
25561diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
25562index 1c273be..da9cc0e 100644
25563--- a/arch/x86/lib/memcpy_64.S
25564+++ b/arch/x86/lib/memcpy_64.S
25565@@ -33,6 +33,7 @@
25566 rep movsq
25567 movl %edx, %ecx
25568 rep movsb
25569+ pax_force_retaddr
25570 ret
25571 .Lmemcpy_e:
25572 .previous
25573@@ -49,6 +50,7 @@
25574 movq %rdi, %rax
25575 movq %rdx, %rcx
25576 rep movsb
25577+ pax_force_retaddr
25578 ret
25579 .Lmemcpy_e_e:
25580 .previous
25581@@ -76,13 +78,13 @@ ENTRY(memcpy)
25582 */
25583 movq 0*8(%rsi), %r8
25584 movq 1*8(%rsi), %r9
25585- movq 2*8(%rsi), %r10
25586+ movq 2*8(%rsi), %rcx
25587 movq 3*8(%rsi), %r11
25588 leaq 4*8(%rsi), %rsi
25589
25590 movq %r8, 0*8(%rdi)
25591 movq %r9, 1*8(%rdi)
25592- movq %r10, 2*8(%rdi)
25593+ movq %rcx, 2*8(%rdi)
25594 movq %r11, 3*8(%rdi)
25595 leaq 4*8(%rdi), %rdi
25596 jae .Lcopy_forward_loop
25597@@ -105,12 +107,12 @@ ENTRY(memcpy)
25598 subq $0x20, %rdx
25599 movq -1*8(%rsi), %r8
25600 movq -2*8(%rsi), %r9
25601- movq -3*8(%rsi), %r10
25602+ movq -3*8(%rsi), %rcx
25603 movq -4*8(%rsi), %r11
25604 leaq -4*8(%rsi), %rsi
25605 movq %r8, -1*8(%rdi)
25606 movq %r9, -2*8(%rdi)
25607- movq %r10, -3*8(%rdi)
25608+ movq %rcx, -3*8(%rdi)
25609 movq %r11, -4*8(%rdi)
25610 leaq -4*8(%rdi), %rdi
25611 jae .Lcopy_backward_loop
25612@@ -130,12 +132,13 @@ ENTRY(memcpy)
25613 */
25614 movq 0*8(%rsi), %r8
25615 movq 1*8(%rsi), %r9
25616- movq -2*8(%rsi, %rdx), %r10
25617+ movq -2*8(%rsi, %rdx), %rcx
25618 movq -1*8(%rsi, %rdx), %r11
25619 movq %r8, 0*8(%rdi)
25620 movq %r9, 1*8(%rdi)
25621- movq %r10, -2*8(%rdi, %rdx)
25622+ movq %rcx, -2*8(%rdi, %rdx)
25623 movq %r11, -1*8(%rdi, %rdx)
25624+ pax_force_retaddr
25625 retq
25626 .p2align 4
25627 .Lless_16bytes:
25628@@ -148,6 +151,7 @@ ENTRY(memcpy)
25629 movq -1*8(%rsi, %rdx), %r9
25630 movq %r8, 0*8(%rdi)
25631 movq %r9, -1*8(%rdi, %rdx)
25632+ pax_force_retaddr
25633 retq
25634 .p2align 4
25635 .Lless_8bytes:
25636@@ -161,6 +165,7 @@ ENTRY(memcpy)
25637 movl -4(%rsi, %rdx), %r8d
25638 movl %ecx, (%rdi)
25639 movl %r8d, -4(%rdi, %rdx)
25640+ pax_force_retaddr
25641 retq
25642 .p2align 4
25643 .Lless_3bytes:
25644@@ -179,6 +184,7 @@ ENTRY(memcpy)
25645 movb %cl, (%rdi)
25646
25647 .Lend:
25648+ pax_force_retaddr
25649 retq
25650 CFI_ENDPROC
25651 ENDPROC(memcpy)
25652diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
25653index ee16461..c39c199 100644
25654--- a/arch/x86/lib/memmove_64.S
25655+++ b/arch/x86/lib/memmove_64.S
25656@@ -61,13 +61,13 @@ ENTRY(memmove)
25657 5:
25658 sub $0x20, %rdx
25659 movq 0*8(%rsi), %r11
25660- movq 1*8(%rsi), %r10
25661+ movq 1*8(%rsi), %rcx
25662 movq 2*8(%rsi), %r9
25663 movq 3*8(%rsi), %r8
25664 leaq 4*8(%rsi), %rsi
25665
25666 movq %r11, 0*8(%rdi)
25667- movq %r10, 1*8(%rdi)
25668+ movq %rcx, 1*8(%rdi)
25669 movq %r9, 2*8(%rdi)
25670 movq %r8, 3*8(%rdi)
25671 leaq 4*8(%rdi), %rdi
25672@@ -81,10 +81,10 @@ ENTRY(memmove)
25673 4:
25674 movq %rdx, %rcx
25675 movq -8(%rsi, %rdx), %r11
25676- lea -8(%rdi, %rdx), %r10
25677+ lea -8(%rdi, %rdx), %r9
25678 shrq $3, %rcx
25679 rep movsq
25680- movq %r11, (%r10)
25681+ movq %r11, (%r9)
25682 jmp 13f
25683 .Lmemmove_end_forward:
25684
25685@@ -95,14 +95,14 @@ ENTRY(memmove)
25686 7:
25687 movq %rdx, %rcx
25688 movq (%rsi), %r11
25689- movq %rdi, %r10
25690+ movq %rdi, %r9
25691 leaq -8(%rsi, %rdx), %rsi
25692 leaq -8(%rdi, %rdx), %rdi
25693 shrq $3, %rcx
25694 std
25695 rep movsq
25696 cld
25697- movq %r11, (%r10)
25698+ movq %r11, (%r9)
25699 jmp 13f
25700
25701 /*
25702@@ -127,13 +127,13 @@ ENTRY(memmove)
25703 8:
25704 subq $0x20, %rdx
25705 movq -1*8(%rsi), %r11
25706- movq -2*8(%rsi), %r10
25707+ movq -2*8(%rsi), %rcx
25708 movq -3*8(%rsi), %r9
25709 movq -4*8(%rsi), %r8
25710 leaq -4*8(%rsi), %rsi
25711
25712 movq %r11, -1*8(%rdi)
25713- movq %r10, -2*8(%rdi)
25714+ movq %rcx, -2*8(%rdi)
25715 movq %r9, -3*8(%rdi)
25716 movq %r8, -4*8(%rdi)
25717 leaq -4*8(%rdi), %rdi
25718@@ -151,11 +151,11 @@ ENTRY(memmove)
25719 * Move data from 16 bytes to 31 bytes.
25720 */
25721 movq 0*8(%rsi), %r11
25722- movq 1*8(%rsi), %r10
25723+ movq 1*8(%rsi), %rcx
25724 movq -2*8(%rsi, %rdx), %r9
25725 movq -1*8(%rsi, %rdx), %r8
25726 movq %r11, 0*8(%rdi)
25727- movq %r10, 1*8(%rdi)
25728+ movq %rcx, 1*8(%rdi)
25729 movq %r9, -2*8(%rdi, %rdx)
25730 movq %r8, -1*8(%rdi, %rdx)
25731 jmp 13f
25732@@ -167,9 +167,9 @@ ENTRY(memmove)
25733 * Move data from 8 bytes to 15 bytes.
25734 */
25735 movq 0*8(%rsi), %r11
25736- movq -1*8(%rsi, %rdx), %r10
25737+ movq -1*8(%rsi, %rdx), %r9
25738 movq %r11, 0*8(%rdi)
25739- movq %r10, -1*8(%rdi, %rdx)
25740+ movq %r9, -1*8(%rdi, %rdx)
25741 jmp 13f
25742 10:
25743 cmpq $4, %rdx
25744@@ -178,9 +178,9 @@ ENTRY(memmove)
25745 * Move data from 4 bytes to 7 bytes.
25746 */
25747 movl (%rsi), %r11d
25748- movl -4(%rsi, %rdx), %r10d
25749+ movl -4(%rsi, %rdx), %r9d
25750 movl %r11d, (%rdi)
25751- movl %r10d, -4(%rdi, %rdx)
25752+ movl %r9d, -4(%rdi, %rdx)
25753 jmp 13f
25754 11:
25755 cmp $2, %rdx
25756@@ -189,9 +189,9 @@ ENTRY(memmove)
25757 * Move data from 2 bytes to 3 bytes.
25758 */
25759 movw (%rsi), %r11w
25760- movw -2(%rsi, %rdx), %r10w
25761+ movw -2(%rsi, %rdx), %r9w
25762 movw %r11w, (%rdi)
25763- movw %r10w, -2(%rdi, %rdx)
25764+ movw %r9w, -2(%rdi, %rdx)
25765 jmp 13f
25766 12:
25767 cmp $1, %rdx
25768@@ -202,6 +202,7 @@ ENTRY(memmove)
25769 movb (%rsi), %r11b
25770 movb %r11b, (%rdi)
25771 13:
25772+ pax_force_retaddr
25773 retq
25774 CFI_ENDPROC
25775
25776@@ -210,6 +211,7 @@ ENTRY(memmove)
25777 /* Forward moving data. */
25778 movq %rdx, %rcx
25779 rep movsb
25780+ pax_force_retaddr
25781 retq
25782 .Lmemmove_end_forward_efs:
25783 .previous
25784diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
25785index 2dcb380..963660a 100644
25786--- a/arch/x86/lib/memset_64.S
25787+++ b/arch/x86/lib/memset_64.S
25788@@ -30,6 +30,7 @@
25789 movl %edx,%ecx
25790 rep stosb
25791 movq %r9,%rax
25792+ pax_force_retaddr
25793 ret
25794 .Lmemset_e:
25795 .previous
25796@@ -52,6 +53,7 @@
25797 movq %rdx,%rcx
25798 rep stosb
25799 movq %r9,%rax
25800+ pax_force_retaddr
25801 ret
25802 .Lmemset_e_e:
25803 .previous
25804@@ -59,7 +61,7 @@
25805 ENTRY(memset)
25806 ENTRY(__memset)
25807 CFI_STARTPROC
25808- movq %rdi,%r10
25809+ movq %rdi,%r11
25810
25811 /* expand byte value */
25812 movzbl %sil,%ecx
25813@@ -117,7 +119,8 @@ ENTRY(__memset)
25814 jnz .Lloop_1
25815
25816 .Lende:
25817- movq %r10,%rax
25818+ movq %r11,%rax
25819+ pax_force_retaddr
25820 ret
25821
25822 CFI_RESTORE_STATE
25823diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
25824index c9f2d9b..e7fd2c0 100644
25825--- a/arch/x86/lib/mmx_32.c
25826+++ b/arch/x86/lib/mmx_32.c
25827@@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25828 {
25829 void *p;
25830 int i;
25831+ unsigned long cr0;
25832
25833 if (unlikely(in_interrupt()))
25834 return __memcpy(to, from, len);
25835@@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
25836 kernel_fpu_begin();
25837
25838 __asm__ __volatile__ (
25839- "1: prefetch (%0)\n" /* This set is 28 bytes */
25840- " prefetch 64(%0)\n"
25841- " prefetch 128(%0)\n"
25842- " prefetch 192(%0)\n"
25843- " prefetch 256(%0)\n"
25844+ "1: prefetch (%1)\n" /* This set is 28 bytes */
25845+ " prefetch 64(%1)\n"
25846+ " prefetch 128(%1)\n"
25847+ " prefetch 192(%1)\n"
25848+ " prefetch 256(%1)\n"
25849 "2: \n"
25850 ".section .fixup, \"ax\"\n"
25851- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25852+ "3: \n"
25853+
25854+#ifdef CONFIG_PAX_KERNEXEC
25855+ " movl %%cr0, %0\n"
25856+ " movl %0, %%eax\n"
25857+ " andl $0xFFFEFFFF, %%eax\n"
25858+ " movl %%eax, %%cr0\n"
25859+#endif
25860+
25861+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25862+
25863+#ifdef CONFIG_PAX_KERNEXEC
25864+ " movl %0, %%cr0\n"
25865+#endif
25866+
25867 " jmp 2b\n"
25868 ".previous\n"
25869 _ASM_EXTABLE(1b, 3b)
25870- : : "r" (from));
25871+ : "=&r" (cr0) : "r" (from) : "ax");
25872
25873 for ( ; i > 5; i--) {
25874 __asm__ __volatile__ (
25875- "1: prefetch 320(%0)\n"
25876- "2: movq (%0), %%mm0\n"
25877- " movq 8(%0), %%mm1\n"
25878- " movq 16(%0), %%mm2\n"
25879- " movq 24(%0), %%mm3\n"
25880- " movq %%mm0, (%1)\n"
25881- " movq %%mm1, 8(%1)\n"
25882- " movq %%mm2, 16(%1)\n"
25883- " movq %%mm3, 24(%1)\n"
25884- " movq 32(%0), %%mm0\n"
25885- " movq 40(%0), %%mm1\n"
25886- " movq 48(%0), %%mm2\n"
25887- " movq 56(%0), %%mm3\n"
25888- " movq %%mm0, 32(%1)\n"
25889- " movq %%mm1, 40(%1)\n"
25890- " movq %%mm2, 48(%1)\n"
25891- " movq %%mm3, 56(%1)\n"
25892+ "1: prefetch 320(%1)\n"
25893+ "2: movq (%1), %%mm0\n"
25894+ " movq 8(%1), %%mm1\n"
25895+ " movq 16(%1), %%mm2\n"
25896+ " movq 24(%1), %%mm3\n"
25897+ " movq %%mm0, (%2)\n"
25898+ " movq %%mm1, 8(%2)\n"
25899+ " movq %%mm2, 16(%2)\n"
25900+ " movq %%mm3, 24(%2)\n"
25901+ " movq 32(%1), %%mm0\n"
25902+ " movq 40(%1), %%mm1\n"
25903+ " movq 48(%1), %%mm2\n"
25904+ " movq 56(%1), %%mm3\n"
25905+ " movq %%mm0, 32(%2)\n"
25906+ " movq %%mm1, 40(%2)\n"
25907+ " movq %%mm2, 48(%2)\n"
25908+ " movq %%mm3, 56(%2)\n"
25909 ".section .fixup, \"ax\"\n"
25910- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25911+ "3:\n"
25912+
25913+#ifdef CONFIG_PAX_KERNEXEC
25914+ " movl %%cr0, %0\n"
25915+ " movl %0, %%eax\n"
25916+ " andl $0xFFFEFFFF, %%eax\n"
25917+ " movl %%eax, %%cr0\n"
25918+#endif
25919+
25920+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
25921+
25922+#ifdef CONFIG_PAX_KERNEXEC
25923+ " movl %0, %%cr0\n"
25924+#endif
25925+
25926 " jmp 2b\n"
25927 ".previous\n"
25928 _ASM_EXTABLE(1b, 3b)
25929- : : "r" (from), "r" (to) : "memory");
25930+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
25931
25932 from += 64;
25933 to += 64;
25934@@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
25935 static void fast_copy_page(void *to, void *from)
25936 {
25937 int i;
25938+ unsigned long cr0;
25939
25940 kernel_fpu_begin();
25941
25942@@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
25943 * but that is for later. -AV
25944 */
25945 __asm__ __volatile__(
25946- "1: prefetch (%0)\n"
25947- " prefetch 64(%0)\n"
25948- " prefetch 128(%0)\n"
25949- " prefetch 192(%0)\n"
25950- " prefetch 256(%0)\n"
25951+ "1: prefetch (%1)\n"
25952+ " prefetch 64(%1)\n"
25953+ " prefetch 128(%1)\n"
25954+ " prefetch 192(%1)\n"
25955+ " prefetch 256(%1)\n"
25956 "2: \n"
25957 ".section .fixup, \"ax\"\n"
25958- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25959+ "3: \n"
25960+
25961+#ifdef CONFIG_PAX_KERNEXEC
25962+ " movl %%cr0, %0\n"
25963+ " movl %0, %%eax\n"
25964+ " andl $0xFFFEFFFF, %%eax\n"
25965+ " movl %%eax, %%cr0\n"
25966+#endif
25967+
25968+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
25969+
25970+#ifdef CONFIG_PAX_KERNEXEC
25971+ " movl %0, %%cr0\n"
25972+#endif
25973+
25974 " jmp 2b\n"
25975 ".previous\n"
25976- _ASM_EXTABLE(1b, 3b) : : "r" (from));
25977+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
25978
25979 for (i = 0; i < (4096-320)/64; i++) {
25980 __asm__ __volatile__ (
25981- "1: prefetch 320(%0)\n"
25982- "2: movq (%0), %%mm0\n"
25983- " movntq %%mm0, (%1)\n"
25984- " movq 8(%0), %%mm1\n"
25985- " movntq %%mm1, 8(%1)\n"
25986- " movq 16(%0), %%mm2\n"
25987- " movntq %%mm2, 16(%1)\n"
25988- " movq 24(%0), %%mm3\n"
25989- " movntq %%mm3, 24(%1)\n"
25990- " movq 32(%0), %%mm4\n"
25991- " movntq %%mm4, 32(%1)\n"
25992- " movq 40(%0), %%mm5\n"
25993- " movntq %%mm5, 40(%1)\n"
25994- " movq 48(%0), %%mm6\n"
25995- " movntq %%mm6, 48(%1)\n"
25996- " movq 56(%0), %%mm7\n"
25997- " movntq %%mm7, 56(%1)\n"
25998+ "1: prefetch 320(%1)\n"
25999+ "2: movq (%1), %%mm0\n"
26000+ " movntq %%mm0, (%2)\n"
26001+ " movq 8(%1), %%mm1\n"
26002+ " movntq %%mm1, 8(%2)\n"
26003+ " movq 16(%1), %%mm2\n"
26004+ " movntq %%mm2, 16(%2)\n"
26005+ " movq 24(%1), %%mm3\n"
26006+ " movntq %%mm3, 24(%2)\n"
26007+ " movq 32(%1), %%mm4\n"
26008+ " movntq %%mm4, 32(%2)\n"
26009+ " movq 40(%1), %%mm5\n"
26010+ " movntq %%mm5, 40(%2)\n"
26011+ " movq 48(%1), %%mm6\n"
26012+ " movntq %%mm6, 48(%2)\n"
26013+ " movq 56(%1), %%mm7\n"
26014+ " movntq %%mm7, 56(%2)\n"
26015 ".section .fixup, \"ax\"\n"
26016- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26017+ "3:\n"
26018+
26019+#ifdef CONFIG_PAX_KERNEXEC
26020+ " movl %%cr0, %0\n"
26021+ " movl %0, %%eax\n"
26022+ " andl $0xFFFEFFFF, %%eax\n"
26023+ " movl %%eax, %%cr0\n"
26024+#endif
26025+
26026+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26027+
26028+#ifdef CONFIG_PAX_KERNEXEC
26029+ " movl %0, %%cr0\n"
26030+#endif
26031+
26032 " jmp 2b\n"
26033 ".previous\n"
26034- _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
26035+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26036
26037 from += 64;
26038 to += 64;
26039@@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
26040 static void fast_copy_page(void *to, void *from)
26041 {
26042 int i;
26043+ unsigned long cr0;
26044
26045 kernel_fpu_begin();
26046
26047 __asm__ __volatile__ (
26048- "1: prefetch (%0)\n"
26049- " prefetch 64(%0)\n"
26050- " prefetch 128(%0)\n"
26051- " prefetch 192(%0)\n"
26052- " prefetch 256(%0)\n"
26053+ "1: prefetch (%1)\n"
26054+ " prefetch 64(%1)\n"
26055+ " prefetch 128(%1)\n"
26056+ " prefetch 192(%1)\n"
26057+ " prefetch 256(%1)\n"
26058 "2: \n"
26059 ".section .fixup, \"ax\"\n"
26060- "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26061+ "3: \n"
26062+
26063+#ifdef CONFIG_PAX_KERNEXEC
26064+ " movl %%cr0, %0\n"
26065+ " movl %0, %%eax\n"
26066+ " andl $0xFFFEFFFF, %%eax\n"
26067+ " movl %%eax, %%cr0\n"
26068+#endif
26069+
26070+ " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
26071+
26072+#ifdef CONFIG_PAX_KERNEXEC
26073+ " movl %0, %%cr0\n"
26074+#endif
26075+
26076 " jmp 2b\n"
26077 ".previous\n"
26078- _ASM_EXTABLE(1b, 3b) : : "r" (from));
26079+ _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
26080
26081 for (i = 0; i < 4096/64; i++) {
26082 __asm__ __volatile__ (
26083- "1: prefetch 320(%0)\n"
26084- "2: movq (%0), %%mm0\n"
26085- " movq 8(%0), %%mm1\n"
26086- " movq 16(%0), %%mm2\n"
26087- " movq 24(%0), %%mm3\n"
26088- " movq %%mm0, (%1)\n"
26089- " movq %%mm1, 8(%1)\n"
26090- " movq %%mm2, 16(%1)\n"
26091- " movq %%mm3, 24(%1)\n"
26092- " movq 32(%0), %%mm0\n"
26093- " movq 40(%0), %%mm1\n"
26094- " movq 48(%0), %%mm2\n"
26095- " movq 56(%0), %%mm3\n"
26096- " movq %%mm0, 32(%1)\n"
26097- " movq %%mm1, 40(%1)\n"
26098- " movq %%mm2, 48(%1)\n"
26099- " movq %%mm3, 56(%1)\n"
26100+ "1: prefetch 320(%1)\n"
26101+ "2: movq (%1), %%mm0\n"
26102+ " movq 8(%1), %%mm1\n"
26103+ " movq 16(%1), %%mm2\n"
26104+ " movq 24(%1), %%mm3\n"
26105+ " movq %%mm0, (%2)\n"
26106+ " movq %%mm1, 8(%2)\n"
26107+ " movq %%mm2, 16(%2)\n"
26108+ " movq %%mm3, 24(%2)\n"
26109+ " movq 32(%1), %%mm0\n"
26110+ " movq 40(%1), %%mm1\n"
26111+ " movq 48(%1), %%mm2\n"
26112+ " movq 56(%1), %%mm3\n"
26113+ " movq %%mm0, 32(%2)\n"
26114+ " movq %%mm1, 40(%2)\n"
26115+ " movq %%mm2, 48(%2)\n"
26116+ " movq %%mm3, 56(%2)\n"
26117 ".section .fixup, \"ax\"\n"
26118- "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26119+ "3:\n"
26120+
26121+#ifdef CONFIG_PAX_KERNEXEC
26122+ " movl %%cr0, %0\n"
26123+ " movl %0, %%eax\n"
26124+ " andl $0xFFFEFFFF, %%eax\n"
26125+ " movl %%eax, %%cr0\n"
26126+#endif
26127+
26128+ " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
26129+
26130+#ifdef CONFIG_PAX_KERNEXEC
26131+ " movl %0, %%cr0\n"
26132+#endif
26133+
26134 " jmp 2b\n"
26135 ".previous\n"
26136 _ASM_EXTABLE(1b, 3b)
26137- : : "r" (from), "r" (to) : "memory");
26138+ : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
26139
26140 from += 64;
26141 to += 64;
26142diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
26143index f6d13ee..aca5f0b 100644
26144--- a/arch/x86/lib/msr-reg.S
26145+++ b/arch/x86/lib/msr-reg.S
26146@@ -3,6 +3,7 @@
26147 #include <asm/dwarf2.h>
26148 #include <asm/asm.h>
26149 #include <asm/msr.h>
26150+#include <asm/alternative-asm.h>
26151
26152 #ifdef CONFIG_X86_64
26153 /*
26154@@ -16,7 +17,7 @@ ENTRY(\op\()_safe_regs)
26155 CFI_STARTPROC
26156 pushq_cfi %rbx
26157 pushq_cfi %rbp
26158- movq %rdi, %r10 /* Save pointer */
26159+ movq %rdi, %r9 /* Save pointer */
26160 xorl %r11d, %r11d /* Return value */
26161 movl (%rdi), %eax
26162 movl 4(%rdi), %ecx
26163@@ -27,16 +28,17 @@ ENTRY(\op\()_safe_regs)
26164 movl 28(%rdi), %edi
26165 CFI_REMEMBER_STATE
26166 1: \op
26167-2: movl %eax, (%r10)
26168+2: movl %eax, (%r9)
26169 movl %r11d, %eax /* Return value */
26170- movl %ecx, 4(%r10)
26171- movl %edx, 8(%r10)
26172- movl %ebx, 12(%r10)
26173- movl %ebp, 20(%r10)
26174- movl %esi, 24(%r10)
26175- movl %edi, 28(%r10)
26176+ movl %ecx, 4(%r9)
26177+ movl %edx, 8(%r9)
26178+ movl %ebx, 12(%r9)
26179+ movl %ebp, 20(%r9)
26180+ movl %esi, 24(%r9)
26181+ movl %edi, 28(%r9)
26182 popq_cfi %rbp
26183 popq_cfi %rbx
26184+ pax_force_retaddr
26185 ret
26186 3:
26187 CFI_RESTORE_STATE
26188diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
26189index fc6ba17..d4d989d 100644
26190--- a/arch/x86/lib/putuser.S
26191+++ b/arch/x86/lib/putuser.S
26192@@ -16,7 +16,9 @@
26193 #include <asm/errno.h>
26194 #include <asm/asm.h>
26195 #include <asm/smap.h>
26196-
26197+#include <asm/segment.h>
26198+#include <asm/pgtable.h>
26199+#include <asm/alternative-asm.h>
26200
26201 /*
26202 * __put_user_X
26203@@ -30,57 +32,125 @@
26204 * as they get called from within inline assembly.
26205 */
26206
26207-#define ENTER CFI_STARTPROC ; \
26208- GET_THREAD_INFO(%_ASM_BX)
26209-#define EXIT ASM_CLAC ; \
26210- ret ; \
26211+#define ENTER CFI_STARTPROC
26212+#define EXIT ASM_CLAC ; \
26213+ pax_force_retaddr ; \
26214+ ret ; \
26215 CFI_ENDPROC
26216
26217+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26218+#define _DEST %_ASM_CX,%_ASM_BX
26219+#else
26220+#define _DEST %_ASM_CX
26221+#endif
26222+
26223+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
26224+#define __copyuser_seg gs;
26225+#else
26226+#define __copyuser_seg
26227+#endif
26228+
26229 .text
26230 ENTRY(__put_user_1)
26231 ENTER
26232+
26233+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26234+ GET_THREAD_INFO(%_ASM_BX)
26235 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
26236 jae bad_put_user
26237 ASM_STAC
26238-1: movb %al,(%_ASM_CX)
26239+
26240+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26241+ mov pax_user_shadow_base,%_ASM_BX
26242+ cmp %_ASM_BX,%_ASM_CX
26243+ jb 1234f
26244+ xor %ebx,%ebx
26245+1234:
26246+#endif
26247+
26248+#endif
26249+
26250+1: __copyuser_seg movb %al,(_DEST)
26251 xor %eax,%eax
26252 EXIT
26253 ENDPROC(__put_user_1)
26254
26255 ENTRY(__put_user_2)
26256 ENTER
26257+
26258+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26259+ GET_THREAD_INFO(%_ASM_BX)
26260 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26261 sub $1,%_ASM_BX
26262 cmp %_ASM_BX,%_ASM_CX
26263 jae bad_put_user
26264 ASM_STAC
26265-2: movw %ax,(%_ASM_CX)
26266+
26267+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26268+ mov pax_user_shadow_base,%_ASM_BX
26269+ cmp %_ASM_BX,%_ASM_CX
26270+ jb 1234f
26271+ xor %ebx,%ebx
26272+1234:
26273+#endif
26274+
26275+#endif
26276+
26277+2: __copyuser_seg movw %ax,(_DEST)
26278 xor %eax,%eax
26279 EXIT
26280 ENDPROC(__put_user_2)
26281
26282 ENTRY(__put_user_4)
26283 ENTER
26284+
26285+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26286+ GET_THREAD_INFO(%_ASM_BX)
26287 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26288 sub $3,%_ASM_BX
26289 cmp %_ASM_BX,%_ASM_CX
26290 jae bad_put_user
26291 ASM_STAC
26292-3: movl %eax,(%_ASM_CX)
26293+
26294+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26295+ mov pax_user_shadow_base,%_ASM_BX
26296+ cmp %_ASM_BX,%_ASM_CX
26297+ jb 1234f
26298+ xor %ebx,%ebx
26299+1234:
26300+#endif
26301+
26302+#endif
26303+
26304+3: __copyuser_seg movl %eax,(_DEST)
26305 xor %eax,%eax
26306 EXIT
26307 ENDPROC(__put_user_4)
26308
26309 ENTRY(__put_user_8)
26310 ENTER
26311+
26312+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
26313+ GET_THREAD_INFO(%_ASM_BX)
26314 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
26315 sub $7,%_ASM_BX
26316 cmp %_ASM_BX,%_ASM_CX
26317 jae bad_put_user
26318 ASM_STAC
26319-4: mov %_ASM_AX,(%_ASM_CX)
26320+
26321+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
26322+ mov pax_user_shadow_base,%_ASM_BX
26323+ cmp %_ASM_BX,%_ASM_CX
26324+ jb 1234f
26325+ xor %ebx,%ebx
26326+1234:
26327+#endif
26328+
26329+#endif
26330+
26331+4: __copyuser_seg mov %_ASM_AX,(_DEST)
26332 #ifdef CONFIG_X86_32
26333-5: movl %edx,4(%_ASM_CX)
26334+5: __copyuser_seg movl %edx,4(_DEST)
26335 #endif
26336 xor %eax,%eax
26337 EXIT
26338diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
26339index 1cad221..de671ee 100644
26340--- a/arch/x86/lib/rwlock.S
26341+++ b/arch/x86/lib/rwlock.S
26342@@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
26343 FRAME
26344 0: LOCK_PREFIX
26345 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26346+
26347+#ifdef CONFIG_PAX_REFCOUNT
26348+ jno 1234f
26349+ LOCK_PREFIX
26350+ WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26351+ int $4
26352+1234:
26353+ _ASM_EXTABLE(1234b, 1234b)
26354+#endif
26355+
26356 1: rep; nop
26357 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
26358 jne 1b
26359 LOCK_PREFIX
26360 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
26361+
26362+#ifdef CONFIG_PAX_REFCOUNT
26363+ jno 1234f
26364+ LOCK_PREFIX
26365+ WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
26366+ int $4
26367+1234:
26368+ _ASM_EXTABLE(1234b, 1234b)
26369+#endif
26370+
26371 jnz 0b
26372 ENDFRAME
26373+ pax_force_retaddr
26374 ret
26375 CFI_ENDPROC
26376 END(__write_lock_failed)
26377@@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
26378 FRAME
26379 0: LOCK_PREFIX
26380 READ_LOCK_SIZE(inc) (%__lock_ptr)
26381+
26382+#ifdef CONFIG_PAX_REFCOUNT
26383+ jno 1234f
26384+ LOCK_PREFIX
26385+ READ_LOCK_SIZE(dec) (%__lock_ptr)
26386+ int $4
26387+1234:
26388+ _ASM_EXTABLE(1234b, 1234b)
26389+#endif
26390+
26391 1: rep; nop
26392 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
26393 js 1b
26394 LOCK_PREFIX
26395 READ_LOCK_SIZE(dec) (%__lock_ptr)
26396+
26397+#ifdef CONFIG_PAX_REFCOUNT
26398+ jno 1234f
26399+ LOCK_PREFIX
26400+ READ_LOCK_SIZE(inc) (%__lock_ptr)
26401+ int $4
26402+1234:
26403+ _ASM_EXTABLE(1234b, 1234b)
26404+#endif
26405+
26406 js 0b
26407 ENDFRAME
26408+ pax_force_retaddr
26409 ret
26410 CFI_ENDPROC
26411 END(__read_lock_failed)
26412diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
26413index 5dff5f0..cadebf4 100644
26414--- a/arch/x86/lib/rwsem.S
26415+++ b/arch/x86/lib/rwsem.S
26416@@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
26417 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26418 CFI_RESTORE __ASM_REG(dx)
26419 restore_common_regs
26420+ pax_force_retaddr
26421 ret
26422 CFI_ENDPROC
26423 ENDPROC(call_rwsem_down_read_failed)
26424@@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
26425 movq %rax,%rdi
26426 call rwsem_down_write_failed
26427 restore_common_regs
26428+ pax_force_retaddr
26429 ret
26430 CFI_ENDPROC
26431 ENDPROC(call_rwsem_down_write_failed)
26432@@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
26433 movq %rax,%rdi
26434 call rwsem_wake
26435 restore_common_regs
26436-1: ret
26437+1: pax_force_retaddr
26438+ ret
26439 CFI_ENDPROC
26440 ENDPROC(call_rwsem_wake)
26441
26442@@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
26443 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
26444 CFI_RESTORE __ASM_REG(dx)
26445 restore_common_regs
26446+ pax_force_retaddr
26447 ret
26448 CFI_ENDPROC
26449 ENDPROC(call_rwsem_downgrade_wake)
26450diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
26451index a63efd6..ccecad8 100644
26452--- a/arch/x86/lib/thunk_64.S
26453+++ b/arch/x86/lib/thunk_64.S
26454@@ -8,6 +8,7 @@
26455 #include <linux/linkage.h>
26456 #include <asm/dwarf2.h>
26457 #include <asm/calling.h>
26458+#include <asm/alternative-asm.h>
26459
26460 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
26461 .macro THUNK name, func, put_ret_addr_in_rdi=0
26462@@ -41,5 +42,6 @@
26463 SAVE_ARGS
26464 restore:
26465 RESTORE_ARGS
26466+ pax_force_retaddr
26467 ret
26468 CFI_ENDPROC
26469diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
26470index f0312d7..9c39d63 100644
26471--- a/arch/x86/lib/usercopy_32.c
26472+++ b/arch/x86/lib/usercopy_32.c
26473@@ -42,11 +42,13 @@ do { \
26474 int __d0; \
26475 might_fault(); \
26476 __asm__ __volatile__( \
26477+ __COPYUSER_SET_ES \
26478 ASM_STAC "\n" \
26479 "0: rep; stosl\n" \
26480 " movl %2,%0\n" \
26481 "1: rep; stosb\n" \
26482 "2: " ASM_CLAC "\n" \
26483+ __COPYUSER_RESTORE_ES \
26484 ".section .fixup,\"ax\"\n" \
26485 "3: lea 0(%2,%0,4),%0\n" \
26486 " jmp 2b\n" \
26487@@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
26488
26489 #ifdef CONFIG_X86_INTEL_USERCOPY
26490 static unsigned long
26491-__copy_user_intel(void __user *to, const void *from, unsigned long size)
26492+__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
26493 {
26494 int d0, d1;
26495 __asm__ __volatile__(
26496@@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26497 " .align 2,0x90\n"
26498 "3: movl 0(%4), %%eax\n"
26499 "4: movl 4(%4), %%edx\n"
26500- "5: movl %%eax, 0(%3)\n"
26501- "6: movl %%edx, 4(%3)\n"
26502+ "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
26503+ "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
26504 "7: movl 8(%4), %%eax\n"
26505 "8: movl 12(%4),%%edx\n"
26506- "9: movl %%eax, 8(%3)\n"
26507- "10: movl %%edx, 12(%3)\n"
26508+ "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
26509+ "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
26510 "11: movl 16(%4), %%eax\n"
26511 "12: movl 20(%4), %%edx\n"
26512- "13: movl %%eax, 16(%3)\n"
26513- "14: movl %%edx, 20(%3)\n"
26514+ "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
26515+ "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
26516 "15: movl 24(%4), %%eax\n"
26517 "16: movl 28(%4), %%edx\n"
26518- "17: movl %%eax, 24(%3)\n"
26519- "18: movl %%edx, 28(%3)\n"
26520+ "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
26521+ "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
26522 "19: movl 32(%4), %%eax\n"
26523 "20: movl 36(%4), %%edx\n"
26524- "21: movl %%eax, 32(%3)\n"
26525- "22: movl %%edx, 36(%3)\n"
26526+ "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
26527+ "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
26528 "23: movl 40(%4), %%eax\n"
26529 "24: movl 44(%4), %%edx\n"
26530- "25: movl %%eax, 40(%3)\n"
26531- "26: movl %%edx, 44(%3)\n"
26532+ "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
26533+ "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
26534 "27: movl 48(%4), %%eax\n"
26535 "28: movl 52(%4), %%edx\n"
26536- "29: movl %%eax, 48(%3)\n"
26537- "30: movl %%edx, 52(%3)\n"
26538+ "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
26539+ "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
26540 "31: movl 56(%4), %%eax\n"
26541 "32: movl 60(%4), %%edx\n"
26542- "33: movl %%eax, 56(%3)\n"
26543- "34: movl %%edx, 60(%3)\n"
26544+ "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
26545+ "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
26546 " addl $-64, %0\n"
26547 " addl $64, %4\n"
26548 " addl $64, %3\n"
26549@@ -149,10 +151,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26550 " shrl $2, %0\n"
26551 " andl $3, %%eax\n"
26552 " cld\n"
26553+ __COPYUSER_SET_ES
26554 "99: rep; movsl\n"
26555 "36: movl %%eax, %0\n"
26556 "37: rep; movsb\n"
26557 "100:\n"
26558+ __COPYUSER_RESTORE_ES
26559 ".section .fixup,\"ax\"\n"
26560 "101: lea 0(%%eax,%0,4),%0\n"
26561 " jmp 100b\n"
26562@@ -202,46 +206,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
26563 }
26564
26565 static unsigned long
26566+__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
26567+{
26568+ int d0, d1;
26569+ __asm__ __volatile__(
26570+ " .align 2,0x90\n"
26571+ "1: "__copyuser_seg" movl 32(%4), %%eax\n"
26572+ " cmpl $67, %0\n"
26573+ " jbe 3f\n"
26574+ "2: "__copyuser_seg" movl 64(%4), %%eax\n"
26575+ " .align 2,0x90\n"
26576+ "3: "__copyuser_seg" movl 0(%4), %%eax\n"
26577+ "4: "__copyuser_seg" movl 4(%4), %%edx\n"
26578+ "5: movl %%eax, 0(%3)\n"
26579+ "6: movl %%edx, 4(%3)\n"
26580+ "7: "__copyuser_seg" movl 8(%4), %%eax\n"
26581+ "8: "__copyuser_seg" movl 12(%4),%%edx\n"
26582+ "9: movl %%eax, 8(%3)\n"
26583+ "10: movl %%edx, 12(%3)\n"
26584+ "11: "__copyuser_seg" movl 16(%4), %%eax\n"
26585+ "12: "__copyuser_seg" movl 20(%4), %%edx\n"
26586+ "13: movl %%eax, 16(%3)\n"
26587+ "14: movl %%edx, 20(%3)\n"
26588+ "15: "__copyuser_seg" movl 24(%4), %%eax\n"
26589+ "16: "__copyuser_seg" movl 28(%4), %%edx\n"
26590+ "17: movl %%eax, 24(%3)\n"
26591+ "18: movl %%edx, 28(%3)\n"
26592+ "19: "__copyuser_seg" movl 32(%4), %%eax\n"
26593+ "20: "__copyuser_seg" movl 36(%4), %%edx\n"
26594+ "21: movl %%eax, 32(%3)\n"
26595+ "22: movl %%edx, 36(%3)\n"
26596+ "23: "__copyuser_seg" movl 40(%4), %%eax\n"
26597+ "24: "__copyuser_seg" movl 44(%4), %%edx\n"
26598+ "25: movl %%eax, 40(%3)\n"
26599+ "26: movl %%edx, 44(%3)\n"
26600+ "27: "__copyuser_seg" movl 48(%4), %%eax\n"
26601+ "28: "__copyuser_seg" movl 52(%4), %%edx\n"
26602+ "29: movl %%eax, 48(%3)\n"
26603+ "30: movl %%edx, 52(%3)\n"
26604+ "31: "__copyuser_seg" movl 56(%4), %%eax\n"
26605+ "32: "__copyuser_seg" movl 60(%4), %%edx\n"
26606+ "33: movl %%eax, 56(%3)\n"
26607+ "34: movl %%edx, 60(%3)\n"
26608+ " addl $-64, %0\n"
26609+ " addl $64, %4\n"
26610+ " addl $64, %3\n"
26611+ " cmpl $63, %0\n"
26612+ " ja 1b\n"
26613+ "35: movl %0, %%eax\n"
26614+ " shrl $2, %0\n"
26615+ " andl $3, %%eax\n"
26616+ " cld\n"
26617+ "99: rep; "__copyuser_seg" movsl\n"
26618+ "36: movl %%eax, %0\n"
26619+ "37: rep; "__copyuser_seg" movsb\n"
26620+ "100:\n"
26621+ ".section .fixup,\"ax\"\n"
26622+ "101: lea 0(%%eax,%0,4),%0\n"
26623+ " jmp 100b\n"
26624+ ".previous\n"
26625+ _ASM_EXTABLE(1b,100b)
26626+ _ASM_EXTABLE(2b,100b)
26627+ _ASM_EXTABLE(3b,100b)
26628+ _ASM_EXTABLE(4b,100b)
26629+ _ASM_EXTABLE(5b,100b)
26630+ _ASM_EXTABLE(6b,100b)
26631+ _ASM_EXTABLE(7b,100b)
26632+ _ASM_EXTABLE(8b,100b)
26633+ _ASM_EXTABLE(9b,100b)
26634+ _ASM_EXTABLE(10b,100b)
26635+ _ASM_EXTABLE(11b,100b)
26636+ _ASM_EXTABLE(12b,100b)
26637+ _ASM_EXTABLE(13b,100b)
26638+ _ASM_EXTABLE(14b,100b)
26639+ _ASM_EXTABLE(15b,100b)
26640+ _ASM_EXTABLE(16b,100b)
26641+ _ASM_EXTABLE(17b,100b)
26642+ _ASM_EXTABLE(18b,100b)
26643+ _ASM_EXTABLE(19b,100b)
26644+ _ASM_EXTABLE(20b,100b)
26645+ _ASM_EXTABLE(21b,100b)
26646+ _ASM_EXTABLE(22b,100b)
26647+ _ASM_EXTABLE(23b,100b)
26648+ _ASM_EXTABLE(24b,100b)
26649+ _ASM_EXTABLE(25b,100b)
26650+ _ASM_EXTABLE(26b,100b)
26651+ _ASM_EXTABLE(27b,100b)
26652+ _ASM_EXTABLE(28b,100b)
26653+ _ASM_EXTABLE(29b,100b)
26654+ _ASM_EXTABLE(30b,100b)
26655+ _ASM_EXTABLE(31b,100b)
26656+ _ASM_EXTABLE(32b,100b)
26657+ _ASM_EXTABLE(33b,100b)
26658+ _ASM_EXTABLE(34b,100b)
26659+ _ASM_EXTABLE(35b,100b)
26660+ _ASM_EXTABLE(36b,100b)
26661+ _ASM_EXTABLE(37b,100b)
26662+ _ASM_EXTABLE(99b,101b)
26663+ : "=&c"(size), "=&D" (d0), "=&S" (d1)
26664+ : "1"(to), "2"(from), "0"(size)
26665+ : "eax", "edx", "memory");
26666+ return size;
26667+}
26668+
26669+static unsigned long __size_overflow(3)
26670 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26671 {
26672 int d0, d1;
26673 __asm__ __volatile__(
26674 " .align 2,0x90\n"
26675- "0: movl 32(%4), %%eax\n"
26676+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26677 " cmpl $67, %0\n"
26678 " jbe 2f\n"
26679- "1: movl 64(%4), %%eax\n"
26680+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26681 " .align 2,0x90\n"
26682- "2: movl 0(%4), %%eax\n"
26683- "21: movl 4(%4), %%edx\n"
26684+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26685+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26686 " movl %%eax, 0(%3)\n"
26687 " movl %%edx, 4(%3)\n"
26688- "3: movl 8(%4), %%eax\n"
26689- "31: movl 12(%4),%%edx\n"
26690+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26691+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26692 " movl %%eax, 8(%3)\n"
26693 " movl %%edx, 12(%3)\n"
26694- "4: movl 16(%4), %%eax\n"
26695- "41: movl 20(%4), %%edx\n"
26696+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26697+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26698 " movl %%eax, 16(%3)\n"
26699 " movl %%edx, 20(%3)\n"
26700- "10: movl 24(%4), %%eax\n"
26701- "51: movl 28(%4), %%edx\n"
26702+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26703+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26704 " movl %%eax, 24(%3)\n"
26705 " movl %%edx, 28(%3)\n"
26706- "11: movl 32(%4), %%eax\n"
26707- "61: movl 36(%4), %%edx\n"
26708+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26709+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26710 " movl %%eax, 32(%3)\n"
26711 " movl %%edx, 36(%3)\n"
26712- "12: movl 40(%4), %%eax\n"
26713- "71: movl 44(%4), %%edx\n"
26714+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26715+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26716 " movl %%eax, 40(%3)\n"
26717 " movl %%edx, 44(%3)\n"
26718- "13: movl 48(%4), %%eax\n"
26719- "81: movl 52(%4), %%edx\n"
26720+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26721+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26722 " movl %%eax, 48(%3)\n"
26723 " movl %%edx, 52(%3)\n"
26724- "14: movl 56(%4), %%eax\n"
26725- "91: movl 60(%4), %%edx\n"
26726+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26727+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26728 " movl %%eax, 56(%3)\n"
26729 " movl %%edx, 60(%3)\n"
26730 " addl $-64, %0\n"
26731@@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26732 " shrl $2, %0\n"
26733 " andl $3, %%eax\n"
26734 " cld\n"
26735- "6: rep; movsl\n"
26736+ "6: rep; "__copyuser_seg" movsl\n"
26737 " movl %%eax,%0\n"
26738- "7: rep; movsb\n"
26739+ "7: rep; "__copyuser_seg" movsb\n"
26740 "8:\n"
26741 ".section .fixup,\"ax\"\n"
26742 "9: lea 0(%%eax,%0,4),%0\n"
26743@@ -298,48 +406,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
26744 * hyoshiok@miraclelinux.com
26745 */
26746
26747-static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26748+static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
26749 const void __user *from, unsigned long size)
26750 {
26751 int d0, d1;
26752
26753 __asm__ __volatile__(
26754 " .align 2,0x90\n"
26755- "0: movl 32(%4), %%eax\n"
26756+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26757 " cmpl $67, %0\n"
26758 " jbe 2f\n"
26759- "1: movl 64(%4), %%eax\n"
26760+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26761 " .align 2,0x90\n"
26762- "2: movl 0(%4), %%eax\n"
26763- "21: movl 4(%4), %%edx\n"
26764+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26765+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26766 " movnti %%eax, 0(%3)\n"
26767 " movnti %%edx, 4(%3)\n"
26768- "3: movl 8(%4), %%eax\n"
26769- "31: movl 12(%4),%%edx\n"
26770+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26771+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26772 " movnti %%eax, 8(%3)\n"
26773 " movnti %%edx, 12(%3)\n"
26774- "4: movl 16(%4), %%eax\n"
26775- "41: movl 20(%4), %%edx\n"
26776+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26777+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26778 " movnti %%eax, 16(%3)\n"
26779 " movnti %%edx, 20(%3)\n"
26780- "10: movl 24(%4), %%eax\n"
26781- "51: movl 28(%4), %%edx\n"
26782+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26783+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26784 " movnti %%eax, 24(%3)\n"
26785 " movnti %%edx, 28(%3)\n"
26786- "11: movl 32(%4), %%eax\n"
26787- "61: movl 36(%4), %%edx\n"
26788+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26789+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26790 " movnti %%eax, 32(%3)\n"
26791 " movnti %%edx, 36(%3)\n"
26792- "12: movl 40(%4), %%eax\n"
26793- "71: movl 44(%4), %%edx\n"
26794+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26795+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26796 " movnti %%eax, 40(%3)\n"
26797 " movnti %%edx, 44(%3)\n"
26798- "13: movl 48(%4), %%eax\n"
26799- "81: movl 52(%4), %%edx\n"
26800+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26801+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26802 " movnti %%eax, 48(%3)\n"
26803 " movnti %%edx, 52(%3)\n"
26804- "14: movl 56(%4), %%eax\n"
26805- "91: movl 60(%4), %%edx\n"
26806+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26807+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26808 " movnti %%eax, 56(%3)\n"
26809 " movnti %%edx, 60(%3)\n"
26810 " addl $-64, %0\n"
26811@@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26812 " shrl $2, %0\n"
26813 " andl $3, %%eax\n"
26814 " cld\n"
26815- "6: rep; movsl\n"
26816+ "6: rep; "__copyuser_seg" movsl\n"
26817 " movl %%eax,%0\n"
26818- "7: rep; movsb\n"
26819+ "7: rep; "__copyuser_seg" movsb\n"
26820 "8:\n"
26821 ".section .fixup,\"ax\"\n"
26822 "9: lea 0(%%eax,%0,4),%0\n"
26823@@ -392,48 +500,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
26824 return size;
26825 }
26826
26827-static unsigned long __copy_user_intel_nocache(void *to,
26828+static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
26829 const void __user *from, unsigned long size)
26830 {
26831 int d0, d1;
26832
26833 __asm__ __volatile__(
26834 " .align 2,0x90\n"
26835- "0: movl 32(%4), %%eax\n"
26836+ "0: "__copyuser_seg" movl 32(%4), %%eax\n"
26837 " cmpl $67, %0\n"
26838 " jbe 2f\n"
26839- "1: movl 64(%4), %%eax\n"
26840+ "1: "__copyuser_seg" movl 64(%4), %%eax\n"
26841 " .align 2,0x90\n"
26842- "2: movl 0(%4), %%eax\n"
26843- "21: movl 4(%4), %%edx\n"
26844+ "2: "__copyuser_seg" movl 0(%4), %%eax\n"
26845+ "21: "__copyuser_seg" movl 4(%4), %%edx\n"
26846 " movnti %%eax, 0(%3)\n"
26847 " movnti %%edx, 4(%3)\n"
26848- "3: movl 8(%4), %%eax\n"
26849- "31: movl 12(%4),%%edx\n"
26850+ "3: "__copyuser_seg" movl 8(%4), %%eax\n"
26851+ "31: "__copyuser_seg" movl 12(%4),%%edx\n"
26852 " movnti %%eax, 8(%3)\n"
26853 " movnti %%edx, 12(%3)\n"
26854- "4: movl 16(%4), %%eax\n"
26855- "41: movl 20(%4), %%edx\n"
26856+ "4: "__copyuser_seg" movl 16(%4), %%eax\n"
26857+ "41: "__copyuser_seg" movl 20(%4), %%edx\n"
26858 " movnti %%eax, 16(%3)\n"
26859 " movnti %%edx, 20(%3)\n"
26860- "10: movl 24(%4), %%eax\n"
26861- "51: movl 28(%4), %%edx\n"
26862+ "10: "__copyuser_seg" movl 24(%4), %%eax\n"
26863+ "51: "__copyuser_seg" movl 28(%4), %%edx\n"
26864 " movnti %%eax, 24(%3)\n"
26865 " movnti %%edx, 28(%3)\n"
26866- "11: movl 32(%4), %%eax\n"
26867- "61: movl 36(%4), %%edx\n"
26868+ "11: "__copyuser_seg" movl 32(%4), %%eax\n"
26869+ "61: "__copyuser_seg" movl 36(%4), %%edx\n"
26870 " movnti %%eax, 32(%3)\n"
26871 " movnti %%edx, 36(%3)\n"
26872- "12: movl 40(%4), %%eax\n"
26873- "71: movl 44(%4), %%edx\n"
26874+ "12: "__copyuser_seg" movl 40(%4), %%eax\n"
26875+ "71: "__copyuser_seg" movl 44(%4), %%edx\n"
26876 " movnti %%eax, 40(%3)\n"
26877 " movnti %%edx, 44(%3)\n"
26878- "13: movl 48(%4), %%eax\n"
26879- "81: movl 52(%4), %%edx\n"
26880+ "13: "__copyuser_seg" movl 48(%4), %%eax\n"
26881+ "81: "__copyuser_seg" movl 52(%4), %%edx\n"
26882 " movnti %%eax, 48(%3)\n"
26883 " movnti %%edx, 52(%3)\n"
26884- "14: movl 56(%4), %%eax\n"
26885- "91: movl 60(%4), %%edx\n"
26886+ "14: "__copyuser_seg" movl 56(%4), %%eax\n"
26887+ "91: "__copyuser_seg" movl 60(%4), %%edx\n"
26888 " movnti %%eax, 56(%3)\n"
26889 " movnti %%edx, 60(%3)\n"
26890 " addl $-64, %0\n"
26891@@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
26892 " shrl $2, %0\n"
26893 " andl $3, %%eax\n"
26894 " cld\n"
26895- "6: rep; movsl\n"
26896+ "6: rep; "__copyuser_seg" movsl\n"
26897 " movl %%eax,%0\n"
26898- "7: rep; movsb\n"
26899+ "7: rep; "__copyuser_seg" movsb\n"
26900 "8:\n"
26901 ".section .fixup,\"ax\"\n"
26902 "9: lea 0(%%eax,%0,4),%0\n"
26903@@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
26904 */
26905 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
26906 unsigned long size);
26907-unsigned long __copy_user_intel(void __user *to, const void *from,
26908+unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
26909+ unsigned long size);
26910+unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
26911 unsigned long size);
26912 unsigned long __copy_user_zeroing_intel_nocache(void *to,
26913 const void __user *from, unsigned long size);
26914 #endif /* CONFIG_X86_INTEL_USERCOPY */
26915
26916 /* Generic arbitrary sized copy. */
26917-#define __copy_user(to, from, size) \
26918+#define __copy_user(to, from, size, prefix, set, restore) \
26919 do { \
26920 int __d0, __d1, __d2; \
26921 __asm__ __volatile__( \
26922+ set \
26923 " cmp $7,%0\n" \
26924 " jbe 1f\n" \
26925 " movl %1,%0\n" \
26926 " negl %0\n" \
26927 " andl $7,%0\n" \
26928 " subl %0,%3\n" \
26929- "4: rep; movsb\n" \
26930+ "4: rep; "prefix"movsb\n" \
26931 " movl %3,%0\n" \
26932 " shrl $2,%0\n" \
26933 " andl $3,%3\n" \
26934 " .align 2,0x90\n" \
26935- "0: rep; movsl\n" \
26936+ "0: rep; "prefix"movsl\n" \
26937 " movl %3,%0\n" \
26938- "1: rep; movsb\n" \
26939+ "1: rep; "prefix"movsb\n" \
26940 "2:\n" \
26941+ restore \
26942 ".section .fixup,\"ax\"\n" \
26943 "5: addl %3,%0\n" \
26944 " jmp 2b\n" \
26945@@ -538,14 +650,14 @@ do { \
26946 " negl %0\n" \
26947 " andl $7,%0\n" \
26948 " subl %0,%3\n" \
26949- "4: rep; movsb\n" \
26950+ "4: rep; "__copyuser_seg"movsb\n" \
26951 " movl %3,%0\n" \
26952 " shrl $2,%0\n" \
26953 " andl $3,%3\n" \
26954 " .align 2,0x90\n" \
26955- "0: rep; movsl\n" \
26956+ "0: rep; "__copyuser_seg"movsl\n" \
26957 " movl %3,%0\n" \
26958- "1: rep; movsb\n" \
26959+ "1: rep; "__copyuser_seg"movsb\n" \
26960 "2:\n" \
26961 ".section .fixup,\"ax\"\n" \
26962 "5: addl %3,%0\n" \
26963@@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
26964 {
26965 stac();
26966 if (movsl_is_ok(to, from, n))
26967- __copy_user(to, from, n);
26968+ __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
26969 else
26970- n = __copy_user_intel(to, from, n);
26971+ n = __generic_copy_to_user_intel(to, from, n);
26972 clac();
26973 return n;
26974 }
26975@@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
26976 {
26977 stac();
26978 if (movsl_is_ok(to, from, n))
26979- __copy_user(to, from, n);
26980+ __copy_user(to, from, n, __copyuser_seg, "", "");
26981 else
26982- n = __copy_user_intel((void __user *)to,
26983- (const void *)from, n);
26984+ n = __generic_copy_from_user_intel(to, from, n);
26985 clac();
26986 return n;
26987 }
26988@@ -632,66 +743,51 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
26989 if (n > 64 && cpu_has_xmm2)
26990 n = __copy_user_intel_nocache(to, from, n);
26991 else
26992- __copy_user(to, from, n);
26993+ __copy_user(to, from, n, __copyuser_seg, "", "");
26994 #else
26995- __copy_user(to, from, n);
26996+ __copy_user(to, from, n, __copyuser_seg, "", "");
26997 #endif
26998 clac();
26999 return n;
27000 }
27001 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
27002
27003-/**
27004- * copy_to_user: - Copy a block of data into user space.
27005- * @to: Destination address, in user space.
27006- * @from: Source address, in kernel space.
27007- * @n: Number of bytes to copy.
27008- *
27009- * Context: User context only. This function may sleep.
27010- *
27011- * Copy data from kernel space to user space.
27012- *
27013- * Returns number of bytes that could not be copied.
27014- * On success, this will be zero.
27015- */
27016-unsigned long
27017-copy_to_user(void __user *to, const void *from, unsigned long n)
27018-{
27019- if (access_ok(VERIFY_WRITE, to, n))
27020- n = __copy_to_user(to, from, n);
27021- return n;
27022-}
27023-EXPORT_SYMBOL(copy_to_user);
27024-
27025-/**
27026- * copy_from_user: - Copy a block of data from user space.
27027- * @to: Destination address, in kernel space.
27028- * @from: Source address, in user space.
27029- * @n: Number of bytes to copy.
27030- *
27031- * Context: User context only. This function may sleep.
27032- *
27033- * Copy data from user space to kernel space.
27034- *
27035- * Returns number of bytes that could not be copied.
27036- * On success, this will be zero.
27037- *
27038- * If some data could not be copied, this function will pad the copied
27039- * data to the requested size using zero bytes.
27040- */
27041-unsigned long
27042-_copy_from_user(void *to, const void __user *from, unsigned long n)
27043-{
27044- if (access_ok(VERIFY_READ, from, n))
27045- n = __copy_from_user(to, from, n);
27046- else
27047- memset(to, 0, n);
27048- return n;
27049-}
27050-EXPORT_SYMBOL(_copy_from_user);
27051-
27052 void copy_from_user_overflow(void)
27053 {
27054 WARN(1, "Buffer overflow detected!\n");
27055 }
27056 EXPORT_SYMBOL(copy_from_user_overflow);
27057+
27058+void copy_to_user_overflow(void)
27059+{
27060+ WARN(1, "Buffer overflow detected!\n");
27061+}
27062+EXPORT_SYMBOL(copy_to_user_overflow);
27063+
27064+#ifdef CONFIG_PAX_MEMORY_UDEREF
27065+void __set_fs(mm_segment_t x)
27066+{
27067+ switch (x.seg) {
27068+ case 0:
27069+ loadsegment(gs, 0);
27070+ break;
27071+ case TASK_SIZE_MAX:
27072+ loadsegment(gs, __USER_DS);
27073+ break;
27074+ case -1UL:
27075+ loadsegment(gs, __KERNEL_DS);
27076+ break;
27077+ default:
27078+ BUG();
27079+ }
27080+ return;
27081+}
27082+EXPORT_SYMBOL(__set_fs);
27083+
27084+void set_fs(mm_segment_t x)
27085+{
27086+ current_thread_info()->addr_limit = x;
27087+ __set_fs(x);
27088+}
27089+EXPORT_SYMBOL(set_fs);
27090+#endif
27091diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
27092index 906fea3..ee8a097 100644
27093--- a/arch/x86/lib/usercopy_64.c
27094+++ b/arch/x86/lib/usercopy_64.c
27095@@ -39,7 +39,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
27096 _ASM_EXTABLE(0b,3b)
27097 _ASM_EXTABLE(1b,2b)
27098 : [size8] "=&c"(size), [dst] "=&D" (__d0)
27099- : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
27100+ : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
27101 [zero] "r" (0UL), [eight] "r" (8UL));
27102 clac();
27103 return size;
27104@@ -54,12 +54,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
27105 }
27106 EXPORT_SYMBOL(clear_user);
27107
27108-unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
27109+unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
27110 {
27111- if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
27112- return copy_user_generic((__force void *)to, (__force void *)from, len);
27113- }
27114- return len;
27115+ if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
27116+ return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
27117+ return len;
27118 }
27119 EXPORT_SYMBOL(copy_in_user);
27120
27121@@ -69,7 +68,7 @@ EXPORT_SYMBOL(copy_in_user);
27122 * it is not necessary to optimize tail handling.
27123 */
27124 unsigned long
27125-copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27126+copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
27127 {
27128 char c;
27129 unsigned zero_len;
27130@@ -87,3 +86,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
27131 clac();
27132 return len;
27133 }
27134+
27135+void copy_from_user_overflow(void)
27136+{
27137+ WARN(1, "Buffer overflow detected!\n");
27138+}
27139+EXPORT_SYMBOL(copy_from_user_overflow);
27140+
27141+void copy_to_user_overflow(void)
27142+{
27143+ WARN(1, "Buffer overflow detected!\n");
27144+}
27145+EXPORT_SYMBOL(copy_to_user_overflow);
27146diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
27147index 903ec1e..c4166b2 100644
27148--- a/arch/x86/mm/extable.c
27149+++ b/arch/x86/mm/extable.c
27150@@ -6,12 +6,24 @@
27151 static inline unsigned long
27152 ex_insn_addr(const struct exception_table_entry *x)
27153 {
27154- return (unsigned long)&x->insn + x->insn;
27155+ unsigned long reloc = 0;
27156+
27157+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27158+ reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27159+#endif
27160+
27161+ return (unsigned long)&x->insn + x->insn + reloc;
27162 }
27163 static inline unsigned long
27164 ex_fixup_addr(const struct exception_table_entry *x)
27165 {
27166- return (unsigned long)&x->fixup + x->fixup;
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->fixup + x->fixup + reloc;
27174 }
27175
27176 int fixup_exception(struct pt_regs *regs)
27177@@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
27178 unsigned long new_ip;
27179
27180 #ifdef CONFIG_PNPBIOS
27181- if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
27182+ if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
27183 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
27184 extern u32 pnp_bios_is_utter_crap;
27185 pnp_bios_is_utter_crap = 1;
27186@@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
27187 i += 4;
27188 p->fixup -= i;
27189 i += 4;
27190+
27191+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27192+ BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
27193+ p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27194+ p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
27195+#endif
27196+
27197 }
27198 }
27199
27200diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
27201index 0e88336..2bb9777 100644
27202--- a/arch/x86/mm/fault.c
27203+++ b/arch/x86/mm/fault.c
27204@@ -13,12 +13,19 @@
27205 #include <linux/perf_event.h> /* perf_sw_event */
27206 #include <linux/hugetlb.h> /* hstate_index_to_shift */
27207 #include <linux/prefetch.h> /* prefetchw */
27208+#include <linux/unistd.h>
27209+#include <linux/compiler.h>
27210
27211 #include <asm/traps.h> /* dotraplinkage, ... */
27212 #include <asm/pgalloc.h> /* pgd_*(), ... */
27213 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
27214 #include <asm/fixmap.h> /* VSYSCALL_START */
27215 #include <asm/context_tracking.h> /* exception_enter(), ... */
27216+#include <asm/tlbflush.h>
27217+
27218+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27219+#include <asm/stacktrace.h>
27220+#endif
27221
27222 /*
27223 * Page fault error code bits:
27224@@ -56,7 +63,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
27225 int ret = 0;
27226
27227 /* kprobe_running() needs smp_processor_id() */
27228- if (kprobes_built_in() && !user_mode_vm(regs)) {
27229+ if (kprobes_built_in() && !user_mode(regs)) {
27230 preempt_disable();
27231 if (kprobe_running() && kprobe_fault_handler(regs, 14))
27232 ret = 1;
27233@@ -117,7 +124,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
27234 return !instr_lo || (instr_lo>>1) == 1;
27235 case 0x00:
27236 /* Prefetch instruction is 0x0F0D or 0x0F18 */
27237- if (probe_kernel_address(instr, opcode))
27238+ if (user_mode(regs)) {
27239+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27240+ return 0;
27241+ } else if (probe_kernel_address(instr, opcode))
27242 return 0;
27243
27244 *prefetch = (instr_lo == 0xF) &&
27245@@ -151,7 +161,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
27246 while (instr < max_instr) {
27247 unsigned char opcode;
27248
27249- if (probe_kernel_address(instr, opcode))
27250+ if (user_mode(regs)) {
27251+ if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
27252+ break;
27253+ } else if (probe_kernel_address(instr, opcode))
27254 break;
27255
27256 instr++;
27257@@ -182,6 +195,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
27258 force_sig_info(si_signo, &info, tsk);
27259 }
27260
27261+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27262+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
27263+#endif
27264+
27265+#ifdef CONFIG_PAX_EMUTRAMP
27266+static int pax_handle_fetch_fault(struct pt_regs *regs);
27267+#endif
27268+
27269+#ifdef CONFIG_PAX_PAGEEXEC
27270+static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
27271+{
27272+ pgd_t *pgd;
27273+ pud_t *pud;
27274+ pmd_t *pmd;
27275+
27276+ pgd = pgd_offset(mm, address);
27277+ if (!pgd_present(*pgd))
27278+ return NULL;
27279+ pud = pud_offset(pgd, address);
27280+ if (!pud_present(*pud))
27281+ return NULL;
27282+ pmd = pmd_offset(pud, address);
27283+ if (!pmd_present(*pmd))
27284+ return NULL;
27285+ return pmd;
27286+}
27287+#endif
27288+
27289 DEFINE_SPINLOCK(pgd_lock);
27290 LIST_HEAD(pgd_list);
27291
27292@@ -232,10 +273,22 @@ void vmalloc_sync_all(void)
27293 for (address = VMALLOC_START & PMD_MASK;
27294 address >= TASK_SIZE && address < FIXADDR_TOP;
27295 address += PMD_SIZE) {
27296+
27297+#ifdef CONFIG_PAX_PER_CPU_PGD
27298+ unsigned long cpu;
27299+#else
27300 struct page *page;
27301+#endif
27302
27303 spin_lock(&pgd_lock);
27304+
27305+#ifdef CONFIG_PAX_PER_CPU_PGD
27306+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
27307+ pgd_t *pgd = get_cpu_pgd(cpu);
27308+ pmd_t *ret;
27309+#else
27310 list_for_each_entry(page, &pgd_list, lru) {
27311+ pgd_t *pgd;
27312 spinlock_t *pgt_lock;
27313 pmd_t *ret;
27314
27315@@ -243,8 +296,14 @@ void vmalloc_sync_all(void)
27316 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
27317
27318 spin_lock(pgt_lock);
27319- ret = vmalloc_sync_one(page_address(page), address);
27320+ pgd = page_address(page);
27321+#endif
27322+
27323+ ret = vmalloc_sync_one(pgd, address);
27324+
27325+#ifndef CONFIG_PAX_PER_CPU_PGD
27326 spin_unlock(pgt_lock);
27327+#endif
27328
27329 if (!ret)
27330 break;
27331@@ -278,6 +337,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27332 * an interrupt in the middle of a task switch..
27333 */
27334 pgd_paddr = read_cr3();
27335+
27336+#ifdef CONFIG_PAX_PER_CPU_PGD
27337+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
27338+#endif
27339+
27340 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
27341 if (!pmd_k)
27342 return -1;
27343@@ -373,7 +437,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
27344 * happen within a race in page table update. In the later
27345 * case just flush:
27346 */
27347+
27348+#ifdef CONFIG_PAX_PER_CPU_PGD
27349+ BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
27350+ pgd = pgd_offset_cpu(smp_processor_id(), address);
27351+#else
27352 pgd = pgd_offset(current->active_mm, address);
27353+#endif
27354+
27355 pgd_ref = pgd_offset_k(address);
27356 if (pgd_none(*pgd_ref))
27357 return -1;
27358@@ -543,7 +614,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
27359 static int is_errata100(struct pt_regs *regs, unsigned long address)
27360 {
27361 #ifdef CONFIG_X86_64
27362- if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
27363+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
27364 return 1;
27365 #endif
27366 return 0;
27367@@ -570,7 +641,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
27368 }
27369
27370 static const char nx_warning[] = KERN_CRIT
27371-"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
27372+"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
27373
27374 static void
27375 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27376@@ -579,15 +650,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
27377 if (!oops_may_print())
27378 return;
27379
27380- if (error_code & PF_INSTR) {
27381+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
27382 unsigned int level;
27383
27384 pte_t *pte = lookup_address(address, &level);
27385
27386 if (pte && pte_present(*pte) && !pte_exec(*pte))
27387- printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
27388+ printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
27389 }
27390
27391+#ifdef CONFIG_PAX_KERNEXEC
27392+ if (init_mm.start_code <= address && address < init_mm.end_code) {
27393+ if (current->signal->curr_ip)
27394+ printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
27395+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
27396+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27397+ else
27398+ printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
27399+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
27400+ }
27401+#endif
27402+
27403 printk(KERN_ALERT "BUG: unable to handle kernel ");
27404 if (address < PAGE_SIZE)
27405 printk(KERN_CONT "NULL pointer dereference");
27406@@ -750,6 +833,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
27407 return;
27408 }
27409 #endif
27410+
27411+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27412+ if (pax_is_fetch_fault(regs, error_code, address)) {
27413+
27414+#ifdef CONFIG_PAX_EMUTRAMP
27415+ switch (pax_handle_fetch_fault(regs)) {
27416+ case 2:
27417+ return;
27418+ }
27419+#endif
27420+
27421+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27422+ do_group_exit(SIGKILL);
27423+ }
27424+#endif
27425+
27426 /* Kernel addresses are always protection faults: */
27427 if (address >= TASK_SIZE)
27428 error_code |= PF_PROT;
27429@@ -835,7 +934,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
27430 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
27431 printk(KERN_ERR
27432 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
27433- tsk->comm, tsk->pid, address);
27434+ tsk->comm, task_pid_nr(tsk), address);
27435 code = BUS_MCEERR_AR;
27436 }
27437 #endif
27438@@ -898,6 +997,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
27439 return 1;
27440 }
27441
27442+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27443+static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
27444+{
27445+ pte_t *pte;
27446+ pmd_t *pmd;
27447+ spinlock_t *ptl;
27448+ unsigned char pte_mask;
27449+
27450+ if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
27451+ !(mm->pax_flags & MF_PAX_PAGEEXEC))
27452+ return 0;
27453+
27454+ /* PaX: it's our fault, let's handle it if we can */
27455+
27456+ /* PaX: take a look at read faults before acquiring any locks */
27457+ if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
27458+ /* instruction fetch attempt from a protected page in user mode */
27459+ up_read(&mm->mmap_sem);
27460+
27461+#ifdef CONFIG_PAX_EMUTRAMP
27462+ switch (pax_handle_fetch_fault(regs)) {
27463+ case 2:
27464+ return 1;
27465+ }
27466+#endif
27467+
27468+ pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
27469+ do_group_exit(SIGKILL);
27470+ }
27471+
27472+ pmd = pax_get_pmd(mm, address);
27473+ if (unlikely(!pmd))
27474+ return 0;
27475+
27476+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
27477+ if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
27478+ pte_unmap_unlock(pte, ptl);
27479+ return 0;
27480+ }
27481+
27482+ if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
27483+ /* write attempt to a protected page in user mode */
27484+ pte_unmap_unlock(pte, ptl);
27485+ return 0;
27486+ }
27487+
27488+#ifdef CONFIG_SMP
27489+ if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
27490+#else
27491+ if (likely(address > get_limit(regs->cs)))
27492+#endif
27493+ {
27494+ set_pte(pte, pte_mkread(*pte));
27495+ __flush_tlb_one(address);
27496+ pte_unmap_unlock(pte, ptl);
27497+ up_read(&mm->mmap_sem);
27498+ return 1;
27499+ }
27500+
27501+ pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
27502+
27503+ /*
27504+ * PaX: fill DTLB with user rights and retry
27505+ */
27506+ __asm__ __volatile__ (
27507+ "orb %2,(%1)\n"
27508+#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
27509+/*
27510+ * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
27511+ * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
27512+ * page fault when examined during a TLB load attempt. this is true not only
27513+ * for PTEs holding a non-present entry but also present entries that will
27514+ * raise a page fault (such as those set up by PaX, or the copy-on-write
27515+ * mechanism). in effect it means that we do *not* need to flush the TLBs
27516+ * for our target pages since their PTEs are simply not in the TLBs at all.
27517+
27518+ * the best thing in omitting it is that we gain around 15-20% speed in the
27519+ * fast path of the page fault handler and can get rid of tracing since we
27520+ * can no longer flush unintended entries.
27521+ */
27522+ "invlpg (%0)\n"
27523+#endif
27524+ __copyuser_seg"testb $0,(%0)\n"
27525+ "xorb %3,(%1)\n"
27526+ :
27527+ : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
27528+ : "memory", "cc");
27529+ pte_unmap_unlock(pte, ptl);
27530+ up_read(&mm->mmap_sem);
27531+ return 1;
27532+}
27533+#endif
27534+
27535 /*
27536 * Handle a spurious fault caused by a stale TLB entry.
27537 *
27538@@ -964,6 +1156,9 @@ int show_unhandled_signals = 1;
27539 static inline int
27540 access_error(unsigned long error_code, struct vm_area_struct *vma)
27541 {
27542+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
27543+ return 1;
27544+
27545 if (error_code & PF_WRITE) {
27546 /* write, present and write, not present: */
27547 if (unlikely(!(vma->vm_flags & VM_WRITE)))
27548@@ -992,7 +1187,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
27549 if (error_code & PF_USER)
27550 return false;
27551
27552- if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
27553+ if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
27554 return false;
27555
27556 return true;
27557@@ -1008,18 +1203,33 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27558 {
27559 struct vm_area_struct *vma;
27560 struct task_struct *tsk;
27561- unsigned long address;
27562 struct mm_struct *mm;
27563 int fault;
27564 int write = error_code & PF_WRITE;
27565 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
27566 (write ? FAULT_FLAG_WRITE : 0);
27567
27568- tsk = current;
27569- mm = tsk->mm;
27570-
27571 /* Get the faulting address: */
27572- address = read_cr2();
27573+ unsigned long address = read_cr2();
27574+
27575+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
27576+ if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
27577+ if (!search_exception_tables(regs->ip)) {
27578+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27579+ bad_area_nosemaphore(regs, error_code, address);
27580+ return;
27581+ }
27582+ if (address < pax_user_shadow_base) {
27583+ printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
27584+ printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
27585+ show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
27586+ } else
27587+ address -= pax_user_shadow_base;
27588+ }
27589+#endif
27590+
27591+ tsk = current;
27592+ mm = tsk->mm;
27593
27594 /*
27595 * Detect and handle instructions that would cause a page fault for
27596@@ -1080,7 +1290,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
27597 * User-mode registers count as a user access even for any
27598 * potential system fault or CPU buglet:
27599 */
27600- if (user_mode_vm(regs)) {
27601+ if (user_mode(regs)) {
27602 local_irq_enable();
27603 error_code |= PF_USER;
27604 } else {
27605@@ -1142,6 +1352,11 @@ retry:
27606 might_sleep();
27607 }
27608
27609+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27610+ if (pax_handle_pageexec_fault(regs, mm, address, error_code))
27611+ return;
27612+#endif
27613+
27614 vma = find_vma(mm, address);
27615 if (unlikely(!vma)) {
27616 bad_area(regs, error_code, address);
27617@@ -1153,18 +1368,24 @@ retry:
27618 bad_area(regs, error_code, address);
27619 return;
27620 }
27621- if (error_code & PF_USER) {
27622- /*
27623- * Accessing the stack below %sp is always a bug.
27624- * The large cushion allows instructions like enter
27625- * and pusha to work. ("enter $65535, $31" pushes
27626- * 32 pointers and then decrements %sp by 65535.)
27627- */
27628- if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
27629- bad_area(regs, error_code, address);
27630- return;
27631- }
27632+ /*
27633+ * Accessing the stack below %sp is always a bug.
27634+ * The large cushion allows instructions like enter
27635+ * and pusha to work. ("enter $65535, $31" pushes
27636+ * 32 pointers and then decrements %sp by 65535.)
27637+ */
27638+ if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
27639+ bad_area(regs, error_code, address);
27640+ return;
27641 }
27642+
27643+#ifdef CONFIG_PAX_SEGMEXEC
27644+ if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
27645+ bad_area(regs, error_code, address);
27646+ return;
27647+ }
27648+#endif
27649+
27650 if (unlikely(expand_stack(vma, address))) {
27651 bad_area(regs, error_code, address);
27652 return;
27653@@ -1228,3 +1449,292 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
27654 __do_page_fault(regs, error_code);
27655 exception_exit(regs);
27656 }
27657+
27658+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27659+static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
27660+{
27661+ struct mm_struct *mm = current->mm;
27662+ unsigned long ip = regs->ip;
27663+
27664+ if (v8086_mode(regs))
27665+ ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
27666+
27667+#ifdef CONFIG_PAX_PAGEEXEC
27668+ if (mm->pax_flags & MF_PAX_PAGEEXEC) {
27669+ if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
27670+ return true;
27671+ if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
27672+ return true;
27673+ return false;
27674+ }
27675+#endif
27676+
27677+#ifdef CONFIG_PAX_SEGMEXEC
27678+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
27679+ if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
27680+ return true;
27681+ return false;
27682+ }
27683+#endif
27684+
27685+ return false;
27686+}
27687+#endif
27688+
27689+#ifdef CONFIG_PAX_EMUTRAMP
27690+static int pax_handle_fetch_fault_32(struct pt_regs *regs)
27691+{
27692+ int err;
27693+
27694+ do { /* PaX: libffi trampoline emulation */
27695+ unsigned char mov, jmp;
27696+ unsigned int addr1, addr2;
27697+
27698+#ifdef CONFIG_X86_64
27699+ if ((regs->ip + 9) >> 32)
27700+ break;
27701+#endif
27702+
27703+ err = get_user(mov, (unsigned char __user *)regs->ip);
27704+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27705+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27706+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27707+
27708+ if (err)
27709+ break;
27710+
27711+ if (mov == 0xB8 && jmp == 0xE9) {
27712+ regs->ax = addr1;
27713+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27714+ return 2;
27715+ }
27716+ } while (0);
27717+
27718+ do { /* PaX: gcc trampoline emulation #1 */
27719+ unsigned char mov1, mov2;
27720+ unsigned short jmp;
27721+ unsigned int addr1, addr2;
27722+
27723+#ifdef CONFIG_X86_64
27724+ if ((regs->ip + 11) >> 32)
27725+ break;
27726+#endif
27727+
27728+ err = get_user(mov1, (unsigned char __user *)regs->ip);
27729+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27730+ err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
27731+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27732+ err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
27733+
27734+ if (err)
27735+ break;
27736+
27737+ if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
27738+ regs->cx = addr1;
27739+ regs->ax = addr2;
27740+ regs->ip = addr2;
27741+ return 2;
27742+ }
27743+ } while (0);
27744+
27745+ do { /* PaX: gcc trampoline emulation #2 */
27746+ unsigned char mov, jmp;
27747+ unsigned int addr1, addr2;
27748+
27749+#ifdef CONFIG_X86_64
27750+ if ((regs->ip + 9) >> 32)
27751+ break;
27752+#endif
27753+
27754+ err = get_user(mov, (unsigned char __user *)regs->ip);
27755+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
27756+ err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
27757+ err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
27758+
27759+ if (err)
27760+ break;
27761+
27762+ if (mov == 0xB9 && jmp == 0xE9) {
27763+ regs->cx = addr1;
27764+ regs->ip = (unsigned int)(regs->ip + addr2 + 10);
27765+ return 2;
27766+ }
27767+ } while (0);
27768+
27769+ return 1; /* PaX in action */
27770+}
27771+
27772+#ifdef CONFIG_X86_64
27773+static int pax_handle_fetch_fault_64(struct pt_regs *regs)
27774+{
27775+ int err;
27776+
27777+ do { /* PaX: libffi trampoline emulation */
27778+ unsigned short mov1, mov2, jmp1;
27779+ unsigned char stcclc, jmp2;
27780+ unsigned long addr1, addr2;
27781+
27782+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27783+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27784+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27785+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27786+ err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
27787+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
27788+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
27789+
27790+ if (err)
27791+ break;
27792+
27793+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27794+ regs->r11 = addr1;
27795+ regs->r10 = addr2;
27796+ if (stcclc == 0xF8)
27797+ regs->flags &= ~X86_EFLAGS_CF;
27798+ else
27799+ regs->flags |= X86_EFLAGS_CF;
27800+ regs->ip = addr1;
27801+ return 2;
27802+ }
27803+ } while (0);
27804+
27805+ do { /* PaX: gcc trampoline emulation #1 */
27806+ unsigned short mov1, mov2, jmp1;
27807+ unsigned char jmp2;
27808+ unsigned int addr1;
27809+ unsigned long addr2;
27810+
27811+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27812+ err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
27813+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
27814+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
27815+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
27816+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
27817+
27818+ if (err)
27819+ break;
27820+
27821+ if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27822+ regs->r11 = addr1;
27823+ regs->r10 = addr2;
27824+ regs->ip = addr1;
27825+ return 2;
27826+ }
27827+ } while (0);
27828+
27829+ do { /* PaX: gcc trampoline emulation #2 */
27830+ unsigned short mov1, mov2, jmp1;
27831+ unsigned char jmp2;
27832+ unsigned long addr1, addr2;
27833+
27834+ err = get_user(mov1, (unsigned short __user *)regs->ip);
27835+ err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
27836+ err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
27837+ err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
27838+ err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
27839+ err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
27840+
27841+ if (err)
27842+ break;
27843+
27844+ if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
27845+ regs->r11 = addr1;
27846+ regs->r10 = addr2;
27847+ regs->ip = addr1;
27848+ return 2;
27849+ }
27850+ } while (0);
27851+
27852+ return 1; /* PaX in action */
27853+}
27854+#endif
27855+
27856+/*
27857+ * PaX: decide what to do with offenders (regs->ip = fault address)
27858+ *
27859+ * returns 1 when task should be killed
27860+ * 2 when gcc trampoline was detected
27861+ */
27862+static int pax_handle_fetch_fault(struct pt_regs *regs)
27863+{
27864+ if (v8086_mode(regs))
27865+ return 1;
27866+
27867+ if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
27868+ return 1;
27869+
27870+#ifdef CONFIG_X86_32
27871+ return pax_handle_fetch_fault_32(regs);
27872+#else
27873+ if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
27874+ return pax_handle_fetch_fault_32(regs);
27875+ else
27876+ return pax_handle_fetch_fault_64(regs);
27877+#endif
27878+}
27879+#endif
27880+
27881+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
27882+void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
27883+{
27884+ long i;
27885+
27886+ printk(KERN_ERR "PAX: bytes at PC: ");
27887+ for (i = 0; i < 20; i++) {
27888+ unsigned char c;
27889+ if (get_user(c, (unsigned char __force_user *)pc+i))
27890+ printk(KERN_CONT "?? ");
27891+ else
27892+ printk(KERN_CONT "%02x ", c);
27893+ }
27894+ printk("\n");
27895+
27896+ printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
27897+ for (i = -1; i < 80 / (long)sizeof(long); i++) {
27898+ unsigned long c;
27899+ if (get_user(c, (unsigned long __force_user *)sp+i)) {
27900+#ifdef CONFIG_X86_32
27901+ printk(KERN_CONT "???????? ");
27902+#else
27903+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
27904+ printk(KERN_CONT "???????? ???????? ");
27905+ else
27906+ printk(KERN_CONT "???????????????? ");
27907+#endif
27908+ } else {
27909+#ifdef CONFIG_X86_64
27910+ if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
27911+ printk(KERN_CONT "%08x ", (unsigned int)c);
27912+ printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
27913+ } else
27914+#endif
27915+ printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
27916+ }
27917+ }
27918+ printk("\n");
27919+}
27920+#endif
27921+
27922+/**
27923+ * probe_kernel_write(): safely attempt to write to a location
27924+ * @dst: address to write to
27925+ * @src: pointer to the data that shall be written
27926+ * @size: size of the data chunk
27927+ *
27928+ * Safely write to address @dst from the buffer at @src. If a kernel fault
27929+ * happens, handle that and return -EFAULT.
27930+ */
27931+long notrace probe_kernel_write(void *dst, const void *src, size_t size)
27932+{
27933+ long ret;
27934+ mm_segment_t old_fs = get_fs();
27935+
27936+ set_fs(KERNEL_DS);
27937+ pagefault_disable();
27938+ pax_open_kernel();
27939+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
27940+ pax_close_kernel();
27941+ pagefault_enable();
27942+ set_fs(old_fs);
27943+
27944+ return ret ? -EFAULT : 0;
27945+}
27946diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
27947index dd74e46..7d26398 100644
27948--- a/arch/x86/mm/gup.c
27949+++ b/arch/x86/mm/gup.c
27950@@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
27951 addr = start;
27952 len = (unsigned long) nr_pages << PAGE_SHIFT;
27953 end = start + len;
27954- if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27955+ if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
27956 (void __user *)start, len)))
27957 return 0;
27958
27959diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
27960index 6f31ee5..8ee4164 100644
27961--- a/arch/x86/mm/highmem_32.c
27962+++ b/arch/x86/mm/highmem_32.c
27963@@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
27964 idx = type + KM_TYPE_NR*smp_processor_id();
27965 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
27966 BUG_ON(!pte_none(*(kmap_pte-idx)));
27967+
27968+ pax_open_kernel();
27969 set_pte(kmap_pte-idx, mk_pte(page, prot));
27970+ pax_close_kernel();
27971+
27972 arch_flush_lazy_mmu_mode();
27973
27974 return (void *)vaddr;
27975diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
27976index ae1aa71..d9bea75 100644
27977--- a/arch/x86/mm/hugetlbpage.c
27978+++ b/arch/x86/mm/hugetlbpage.c
27979@@ -271,23 +271,30 @@ follow_huge_pud(struct mm_struct *mm, unsigned long address,
27980 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
27981 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
27982 unsigned long addr, unsigned long len,
27983- unsigned long pgoff, unsigned long flags)
27984+ unsigned long pgoff, unsigned long flags, unsigned long offset)
27985 {
27986 struct hstate *h = hstate_file(file);
27987 struct vm_unmapped_area_info info;
27988-
27989+
27990 info.flags = 0;
27991 info.length = len;
27992 info.low_limit = TASK_UNMAPPED_BASE;
27993+
27994+#ifdef CONFIG_PAX_RANDMMAP
27995+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
27996+ info.low_limit += current->mm->delta_mmap;
27997+#endif
27998+
27999 info.high_limit = TASK_SIZE;
28000 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28001 info.align_offset = 0;
28002+ info.threadstack_offset = offset;
28003 return vm_unmapped_area(&info);
28004 }
28005
28006 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28007 unsigned long addr0, unsigned long len,
28008- unsigned long pgoff, unsigned long flags)
28009+ unsigned long pgoff, unsigned long flags, unsigned long offset)
28010 {
28011 struct hstate *h = hstate_file(file);
28012 struct vm_unmapped_area_info info;
28013@@ -299,6 +306,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28014 info.high_limit = current->mm->mmap_base;
28015 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
28016 info.align_offset = 0;
28017+ info.threadstack_offset = offset;
28018 addr = vm_unmapped_area(&info);
28019
28020 /*
28021@@ -311,6 +319,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
28022 VM_BUG_ON(addr != -ENOMEM);
28023 info.flags = 0;
28024 info.low_limit = TASK_UNMAPPED_BASE;
28025+
28026+#ifdef CONFIG_PAX_RANDMMAP
28027+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
28028+ info.low_limit += current->mm->delta_mmap;
28029+#endif
28030+
28031 info.high_limit = TASK_SIZE;
28032 addr = vm_unmapped_area(&info);
28033 }
28034@@ -325,10 +339,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28035 struct hstate *h = hstate_file(file);
28036 struct mm_struct *mm = current->mm;
28037 struct vm_area_struct *vma;
28038+ unsigned long pax_task_size = TASK_SIZE;
28039+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
28040
28041 if (len & ~huge_page_mask(h))
28042 return -EINVAL;
28043- if (len > TASK_SIZE)
28044+
28045+#ifdef CONFIG_PAX_SEGMEXEC
28046+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28047+ pax_task_size = SEGMEXEC_TASK_SIZE;
28048+#endif
28049+
28050+ pax_task_size -= PAGE_SIZE;
28051+
28052+ if (len > pax_task_size)
28053 return -ENOMEM;
28054
28055 if (flags & MAP_FIXED) {
28056@@ -337,19 +361,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
28057 return addr;
28058 }
28059
28060+#ifdef CONFIG_PAX_RANDMMAP
28061+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
28062+#endif
28063+
28064 if (addr) {
28065 addr = ALIGN(addr, huge_page_size(h));
28066 vma = find_vma(mm, addr);
28067- if (TASK_SIZE - len >= addr &&
28068- (!vma || addr + len <= vma->vm_start))
28069+ if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
28070 return addr;
28071 }
28072 if (mm->get_unmapped_area == arch_get_unmapped_area)
28073 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
28074- pgoff, flags);
28075+ pgoff, flags, offset);
28076 else
28077 return hugetlb_get_unmapped_area_topdown(file, addr, len,
28078- pgoff, flags);
28079+ pgoff, flags, offset);
28080 }
28081
28082 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
28083diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
28084index 0c13708..689fe7f 100644
28085--- a/arch/x86/mm/init.c
28086+++ b/arch/x86/mm/init.c
28087@@ -4,6 +4,7 @@
28088 #include <linux/swap.h>
28089 #include <linux/memblock.h>
28090 #include <linux/bootmem.h> /* for max_low_pfn */
28091+#include <linux/tboot.h>
28092
28093 #include <asm/cacheflush.h>
28094 #include <asm/e820.h>
28095@@ -17,6 +18,8 @@
28096 #include <asm/proto.h>
28097 #include <asm/dma.h> /* for MAX_DMA_PFN */
28098 #include <asm/microcode.h>
28099+#include <asm/desc.h>
28100+#include <asm/bios_ebda.h>
28101
28102 #include "mm_internal.h"
28103
28104@@ -464,10 +467,40 @@ void __init init_mem_mapping(void)
28105 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
28106 * mmio resources as well as potential bios/acpi data regions.
28107 */
28108+
28109+#ifdef CONFIG_GRKERNSEC_KMEM
28110+static unsigned int ebda_start __read_only;
28111+static unsigned int ebda_end __read_only;
28112+#endif
28113+
28114 int devmem_is_allowed(unsigned long pagenr)
28115 {
28116- if (pagenr < 256)
28117+#ifdef CONFIG_GRKERNSEC_KMEM
28118+ /* allow BDA */
28119+ if (!pagenr)
28120 return 1;
28121+ /* allow EBDA */
28122+ if (pagenr >= ebda_start && pagenr < ebda_end)
28123+ return 1;
28124+ /* if tboot is in use, allow access to its hardcoded serial log range */
28125+ if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
28126+ return 1;
28127+#else
28128+ if (!pagenr)
28129+ return 1;
28130+#ifdef CONFIG_VM86
28131+ if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
28132+ return 1;
28133+#endif
28134+#endif
28135+
28136+ if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
28137+ return 1;
28138+#ifdef CONFIG_GRKERNSEC_KMEM
28139+ /* throw out everything else below 1MB */
28140+ if (pagenr <= 256)
28141+ return 0;
28142+#endif
28143 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
28144 return 0;
28145 if (!page_is_ram(pagenr))
28146@@ -524,8 +557,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
28147 #endif
28148 }
28149
28150+#ifdef CONFIG_GRKERNSEC_KMEM
28151+static inline void gr_init_ebda(void)
28152+{
28153+ unsigned int ebda_addr;
28154+ unsigned int ebda_size = 0;
28155+
28156+ ebda_addr = get_bios_ebda();
28157+ if (ebda_addr) {
28158+ ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
28159+ ebda_size <<= 10;
28160+ }
28161+ if (ebda_addr && ebda_size) {
28162+ ebda_start = ebda_addr >> PAGE_SHIFT;
28163+ ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
28164+ } else {
28165+ ebda_start = 0x9f000 >> PAGE_SHIFT;
28166+ ebda_end = 0xa0000 >> PAGE_SHIFT;
28167+ }
28168+}
28169+#else
28170+static inline void gr_init_ebda(void) { }
28171+#endif
28172+
28173 void free_initmem(void)
28174 {
28175+#ifdef CONFIG_PAX_KERNEXEC
28176+#ifdef CONFIG_X86_32
28177+ /* PaX: limit KERNEL_CS to actual size */
28178+ unsigned long addr, limit;
28179+ struct desc_struct d;
28180+ int cpu;
28181+#else
28182+ pgd_t *pgd;
28183+ pud_t *pud;
28184+ pmd_t *pmd;
28185+ unsigned long addr, end;
28186+#endif
28187+#endif
28188+
28189+ gr_init_ebda();
28190+
28191+#ifdef CONFIG_PAX_KERNEXEC
28192+#ifdef CONFIG_X86_32
28193+ limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
28194+ limit = (limit - 1UL) >> PAGE_SHIFT;
28195+
28196+ memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
28197+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
28198+ pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
28199+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
28200+ write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
28201+ }
28202+
28203+ /* PaX: make KERNEL_CS read-only */
28204+ addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
28205+ if (!paravirt_enabled())
28206+ set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
28207+/*
28208+ for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
28209+ pgd = pgd_offset_k(addr);
28210+ pud = pud_offset(pgd, addr);
28211+ pmd = pmd_offset(pud, addr);
28212+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28213+ }
28214+*/
28215+#ifdef CONFIG_X86_PAE
28216+ set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
28217+/*
28218+ for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
28219+ pgd = pgd_offset_k(addr);
28220+ pud = pud_offset(pgd, addr);
28221+ pmd = pmd_offset(pud, addr);
28222+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28223+ }
28224+*/
28225+#endif
28226+
28227+#ifdef CONFIG_MODULES
28228+ set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
28229+#endif
28230+
28231+#else
28232+ /* PaX: make kernel code/rodata read-only, rest non-executable */
28233+ for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
28234+ pgd = pgd_offset_k(addr);
28235+ pud = pud_offset(pgd, addr);
28236+ pmd = pmd_offset(pud, addr);
28237+ if (!pmd_present(*pmd))
28238+ continue;
28239+ if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
28240+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28241+ else
28242+ set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
28243+ }
28244+
28245+ addr = (unsigned long)__va(__pa(__START_KERNEL_map));
28246+ end = addr + KERNEL_IMAGE_SIZE;
28247+ for (; addr < end; addr += PMD_SIZE) {
28248+ pgd = pgd_offset_k(addr);
28249+ pud = pud_offset(pgd, addr);
28250+ pmd = pmd_offset(pud, addr);
28251+ if (!pmd_present(*pmd))
28252+ continue;
28253+ if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
28254+ set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
28255+ }
28256+#endif
28257+
28258+ flush_tlb_all();
28259+#endif
28260+
28261 free_init_pages("unused kernel memory",
28262 (unsigned long)(&__init_begin),
28263 (unsigned long)(&__init_end));
28264diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
28265index 2d19001..6a1046c 100644
28266--- a/arch/x86/mm/init_32.c
28267+++ b/arch/x86/mm/init_32.c
28268@@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
28269 bool __read_mostly __vmalloc_start_set = false;
28270
28271 /*
28272- * Creates a middle page table and puts a pointer to it in the
28273- * given global directory entry. This only returns the gd entry
28274- * in non-PAE compilation mode, since the middle layer is folded.
28275- */
28276-static pmd_t * __init one_md_table_init(pgd_t *pgd)
28277-{
28278- pud_t *pud;
28279- pmd_t *pmd_table;
28280-
28281-#ifdef CONFIG_X86_PAE
28282- if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
28283- pmd_table = (pmd_t *)alloc_low_page();
28284- paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
28285- set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
28286- pud = pud_offset(pgd, 0);
28287- BUG_ON(pmd_table != pmd_offset(pud, 0));
28288-
28289- return pmd_table;
28290- }
28291-#endif
28292- pud = pud_offset(pgd, 0);
28293- pmd_table = pmd_offset(pud, 0);
28294-
28295- return pmd_table;
28296-}
28297-
28298-/*
28299 * Create a page table and place a pointer to it in a middle page
28300 * directory entry:
28301 */
28302@@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
28303 pte_t *page_table = (pte_t *)alloc_low_page();
28304
28305 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
28306+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
28307+ set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
28308+#else
28309 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
28310+#endif
28311 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
28312 }
28313
28314 return pte_offset_kernel(pmd, 0);
28315 }
28316
28317+static pmd_t * __init one_md_table_init(pgd_t *pgd)
28318+{
28319+ pud_t *pud;
28320+ pmd_t *pmd_table;
28321+
28322+ pud = pud_offset(pgd, 0);
28323+ pmd_table = pmd_offset(pud, 0);
28324+
28325+ return pmd_table;
28326+}
28327+
28328 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
28329 {
28330 int pgd_idx = pgd_index(vaddr);
28331@@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28332 int pgd_idx, pmd_idx;
28333 unsigned long vaddr;
28334 pgd_t *pgd;
28335+ pud_t *pud;
28336 pmd_t *pmd;
28337 pte_t *pte = NULL;
28338 unsigned long count = page_table_range_init_count(start, end);
28339@@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28340 pgd = pgd_base + pgd_idx;
28341
28342 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
28343- pmd = one_md_table_init(pgd);
28344- pmd = pmd + pmd_index(vaddr);
28345+ pud = pud_offset(pgd, vaddr);
28346+ pmd = pmd_offset(pud, vaddr);
28347+
28348+#ifdef CONFIG_X86_PAE
28349+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28350+#endif
28351+
28352 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
28353 pmd++, pmd_idx++) {
28354 pte = page_table_kmap_check(one_page_table_init(pmd),
28355@@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
28356 }
28357 }
28358
28359-static inline int is_kernel_text(unsigned long addr)
28360+static inline int is_kernel_text(unsigned long start, unsigned long end)
28361 {
28362- if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
28363- return 1;
28364- return 0;
28365+ if ((start > ktla_ktva((unsigned long)_etext) ||
28366+ end <= ktla_ktva((unsigned long)_stext)) &&
28367+ (start > ktla_ktva((unsigned long)_einittext) ||
28368+ end <= ktla_ktva((unsigned long)_sinittext)) &&
28369+
28370+#ifdef CONFIG_ACPI_SLEEP
28371+ (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
28372+#endif
28373+
28374+ (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
28375+ return 0;
28376+ return 1;
28377 }
28378
28379 /*
28380@@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
28381 unsigned long last_map_addr = end;
28382 unsigned long start_pfn, end_pfn;
28383 pgd_t *pgd_base = swapper_pg_dir;
28384- int pgd_idx, pmd_idx, pte_ofs;
28385+ unsigned int pgd_idx, pmd_idx, pte_ofs;
28386 unsigned long pfn;
28387 pgd_t *pgd;
28388+ pud_t *pud;
28389 pmd_t *pmd;
28390 pte_t *pte;
28391 unsigned pages_2m, pages_4k;
28392@@ -291,8 +295,13 @@ repeat:
28393 pfn = start_pfn;
28394 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28395 pgd = pgd_base + pgd_idx;
28396- for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
28397- pmd = one_md_table_init(pgd);
28398+ for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
28399+ pud = pud_offset(pgd, 0);
28400+ pmd = pmd_offset(pud, 0);
28401+
28402+#ifdef CONFIG_X86_PAE
28403+ paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
28404+#endif
28405
28406 if (pfn >= end_pfn)
28407 continue;
28408@@ -304,14 +313,13 @@ repeat:
28409 #endif
28410 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
28411 pmd++, pmd_idx++) {
28412- unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
28413+ unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
28414
28415 /*
28416 * Map with big pages if possible, otherwise
28417 * create normal page tables:
28418 */
28419 if (use_pse) {
28420- unsigned int addr2;
28421 pgprot_t prot = PAGE_KERNEL_LARGE;
28422 /*
28423 * first pass will use the same initial
28424@@ -322,11 +330,7 @@ repeat:
28425 _PAGE_PSE);
28426
28427 pfn &= PMD_MASK >> PAGE_SHIFT;
28428- addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
28429- PAGE_OFFSET + PAGE_SIZE-1;
28430-
28431- if (is_kernel_text(addr) ||
28432- is_kernel_text(addr2))
28433+ if (is_kernel_text(address, address + PMD_SIZE))
28434 prot = PAGE_KERNEL_LARGE_EXEC;
28435
28436 pages_2m++;
28437@@ -343,7 +347,7 @@ repeat:
28438 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
28439 pte += pte_ofs;
28440 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
28441- pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
28442+ pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
28443 pgprot_t prot = PAGE_KERNEL;
28444 /*
28445 * first pass will use the same initial
28446@@ -351,7 +355,7 @@ repeat:
28447 */
28448 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
28449
28450- if (is_kernel_text(addr))
28451+ if (is_kernel_text(address, address + PAGE_SIZE))
28452 prot = PAGE_KERNEL_EXEC;
28453
28454 pages_4k++;
28455@@ -482,7 +486,7 @@ void __init native_pagetable_init(void)
28456
28457 pud = pud_offset(pgd, va);
28458 pmd = pmd_offset(pud, va);
28459- if (!pmd_present(*pmd))
28460+ if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
28461 break;
28462
28463 /* should not be large page here */
28464@@ -540,12 +544,10 @@ void __init early_ioremap_page_table_range_init(void)
28465
28466 static void __init pagetable_init(void)
28467 {
28468- pgd_t *pgd_base = swapper_pg_dir;
28469-
28470- permanent_kmaps_init(pgd_base);
28471+ permanent_kmaps_init(swapper_pg_dir);
28472 }
28473
28474-pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28475+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
28476 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28477
28478 /* user-defined highmem size */
28479@@ -752,6 +754,12 @@ void __init mem_init(void)
28480
28481 pci_iommu_alloc();
28482
28483+#ifdef CONFIG_PAX_PER_CPU_PGD
28484+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28485+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28486+ KERNEL_PGD_PTRS);
28487+#endif
28488+
28489 #ifdef CONFIG_FLATMEM
28490 BUG_ON(!mem_map);
28491 #endif
28492@@ -780,7 +788,7 @@ void __init mem_init(void)
28493 after_bootmem = 1;
28494
28495 codesize = (unsigned long) &_etext - (unsigned long) &_text;
28496- datasize = (unsigned long) &_edata - (unsigned long) &_etext;
28497+ datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
28498 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
28499
28500 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
28501@@ -821,10 +829,10 @@ void __init mem_init(void)
28502 ((unsigned long)&__init_end -
28503 (unsigned long)&__init_begin) >> 10,
28504
28505- (unsigned long)&_etext, (unsigned long)&_edata,
28506- ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
28507+ (unsigned long)&_sdata, (unsigned long)&_edata,
28508+ ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
28509
28510- (unsigned long)&_text, (unsigned long)&_etext,
28511+ ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
28512 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
28513
28514 /*
28515@@ -914,6 +922,7 @@ void set_kernel_text_rw(void)
28516 if (!kernel_set_to_readonly)
28517 return;
28518
28519+ start = ktla_ktva(start);
28520 pr_debug("Set kernel text: %lx - %lx for read write\n",
28521 start, start+size);
28522
28523@@ -928,6 +937,7 @@ void set_kernel_text_ro(void)
28524 if (!kernel_set_to_readonly)
28525 return;
28526
28527+ start = ktla_ktva(start);
28528 pr_debug("Set kernel text: %lx - %lx for read only\n",
28529 start, start+size);
28530
28531@@ -956,6 +966,7 @@ void mark_rodata_ro(void)
28532 unsigned long start = PFN_ALIGN(_text);
28533 unsigned long size = PFN_ALIGN(_etext) - start;
28534
28535+ start = ktla_ktva(start);
28536 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
28537 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
28538 size >> 10);
28539diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
28540index 474e28f..647dd12 100644
28541--- a/arch/x86/mm/init_64.c
28542+++ b/arch/x86/mm/init_64.c
28543@@ -150,7 +150,7 @@ early_param("gbpages", parse_direct_gbpages_on);
28544 * around without checking the pgd every time.
28545 */
28546
28547-pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
28548+pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
28549 EXPORT_SYMBOL_GPL(__supported_pte_mask);
28550
28551 int force_personality32;
28552@@ -183,12 +183,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28553
28554 for (address = start; address <= end; address += PGDIR_SIZE) {
28555 const pgd_t *pgd_ref = pgd_offset_k(address);
28556+
28557+#ifdef CONFIG_PAX_PER_CPU_PGD
28558+ unsigned long cpu;
28559+#else
28560 struct page *page;
28561+#endif
28562
28563 if (pgd_none(*pgd_ref))
28564 continue;
28565
28566 spin_lock(&pgd_lock);
28567+
28568+#ifdef CONFIG_PAX_PER_CPU_PGD
28569+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
28570+ pgd_t *pgd = pgd_offset_cpu(cpu, address);
28571+#else
28572 list_for_each_entry(page, &pgd_list, lru) {
28573 pgd_t *pgd;
28574 spinlock_t *pgt_lock;
28575@@ -197,6 +207,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28576 /* the pgt_lock only for Xen */
28577 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
28578 spin_lock(pgt_lock);
28579+#endif
28580
28581 if (pgd_none(*pgd))
28582 set_pgd(pgd, *pgd_ref);
28583@@ -204,7 +215,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
28584 BUG_ON(pgd_page_vaddr(*pgd)
28585 != pgd_page_vaddr(*pgd_ref));
28586
28587+#ifndef CONFIG_PAX_PER_CPU_PGD
28588 spin_unlock(pgt_lock);
28589+#endif
28590+
28591 }
28592 spin_unlock(&pgd_lock);
28593 }
28594@@ -237,7 +251,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
28595 {
28596 if (pgd_none(*pgd)) {
28597 pud_t *pud = (pud_t *)spp_getpage();
28598- pgd_populate(&init_mm, pgd, pud);
28599+ pgd_populate_kernel(&init_mm, pgd, pud);
28600 if (pud != pud_offset(pgd, 0))
28601 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
28602 pud, pud_offset(pgd, 0));
28603@@ -249,7 +263,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
28604 {
28605 if (pud_none(*pud)) {
28606 pmd_t *pmd = (pmd_t *) spp_getpage();
28607- pud_populate(&init_mm, pud, pmd);
28608+ pud_populate_kernel(&init_mm, pud, pmd);
28609 if (pmd != pmd_offset(pud, 0))
28610 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
28611 pmd, pmd_offset(pud, 0));
28612@@ -278,7 +292,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
28613 pmd = fill_pmd(pud, vaddr);
28614 pte = fill_pte(pmd, vaddr);
28615
28616+ pax_open_kernel();
28617 set_pte(pte, new_pte);
28618+ pax_close_kernel();
28619
28620 /*
28621 * It's enough to flush this one mapping.
28622@@ -337,14 +353,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
28623 pgd = pgd_offset_k((unsigned long)__va(phys));
28624 if (pgd_none(*pgd)) {
28625 pud = (pud_t *) spp_getpage();
28626- set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
28627- _PAGE_USER));
28628+ set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
28629 }
28630 pud = pud_offset(pgd, (unsigned long)__va(phys));
28631 if (pud_none(*pud)) {
28632 pmd = (pmd_t *) spp_getpage();
28633- set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
28634- _PAGE_USER));
28635+ set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
28636 }
28637 pmd = pmd_offset(pud, phys);
28638 BUG_ON(!pmd_none(*pmd));
28639@@ -585,7 +599,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
28640 prot);
28641
28642 spin_lock(&init_mm.page_table_lock);
28643- pud_populate(&init_mm, pud, pmd);
28644+ pud_populate_kernel(&init_mm, pud, pmd);
28645 spin_unlock(&init_mm.page_table_lock);
28646 }
28647 __flush_tlb_all();
28648@@ -626,7 +640,7 @@ kernel_physical_mapping_init(unsigned long start,
28649 page_size_mask);
28650
28651 spin_lock(&init_mm.page_table_lock);
28652- pgd_populate(&init_mm, pgd, pud);
28653+ pgd_populate_kernel(&init_mm, pgd, pud);
28654 spin_unlock(&init_mm.page_table_lock);
28655 pgd_changed = true;
28656 }
28657@@ -1065,6 +1079,12 @@ void __init mem_init(void)
28658
28659 pci_iommu_alloc();
28660
28661+#ifdef CONFIG_PAX_PER_CPU_PGD
28662+ clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
28663+ swapper_pg_dir + KERNEL_PGD_BOUNDARY,
28664+ KERNEL_PGD_PTRS);
28665+#endif
28666+
28667 /* clear_bss() already clear the empty_zero_page */
28668
28669 reservedpages = 0;
28670@@ -1224,8 +1244,8 @@ int kern_addr_valid(unsigned long addr)
28671 static struct vm_area_struct gate_vma = {
28672 .vm_start = VSYSCALL_START,
28673 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
28674- .vm_page_prot = PAGE_READONLY_EXEC,
28675- .vm_flags = VM_READ | VM_EXEC
28676+ .vm_page_prot = PAGE_READONLY,
28677+ .vm_flags = VM_READ
28678 };
28679
28680 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
28681@@ -1259,7 +1279,7 @@ int in_gate_area_no_mm(unsigned long addr)
28682
28683 const char *arch_vma_name(struct vm_area_struct *vma)
28684 {
28685- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
28686+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
28687 return "[vdso]";
28688 if (vma == &gate_vma)
28689 return "[vsyscall]";
28690diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
28691index 7b179b4..6bd17777 100644
28692--- a/arch/x86/mm/iomap_32.c
28693+++ b/arch/x86/mm/iomap_32.c
28694@@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
28695 type = kmap_atomic_idx_push();
28696 idx = type + KM_TYPE_NR * smp_processor_id();
28697 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
28698+
28699+ pax_open_kernel();
28700 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
28701+ pax_close_kernel();
28702+
28703 arch_flush_lazy_mmu_mode();
28704
28705 return (void *)vaddr;
28706diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
28707index 78fe3f1..73b95e2 100644
28708--- a/arch/x86/mm/ioremap.c
28709+++ b/arch/x86/mm/ioremap.c
28710@@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
28711 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
28712 int is_ram = page_is_ram(pfn);
28713
28714- if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
28715+ if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
28716 return NULL;
28717 WARN_ON_ONCE(is_ram);
28718 }
28719@@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
28720 *
28721 * Caller must ensure there is only one unmapping for the same pointer.
28722 */
28723-void iounmap(volatile void __iomem *addr)
28724+void iounmap(const volatile void __iomem *addr)
28725 {
28726 struct vm_struct *p, *o;
28727
28728@@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28729
28730 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
28731 if (page_is_ram(start >> PAGE_SHIFT))
28732+#ifdef CONFIG_HIGHMEM
28733+ if ((start >> PAGE_SHIFT) < max_low_pfn)
28734+#endif
28735 return __va(phys);
28736
28737 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
28738@@ -327,6 +330,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
28739 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
28740 {
28741 if (page_is_ram(phys >> PAGE_SHIFT))
28742+#ifdef CONFIG_HIGHMEM
28743+ if ((phys >> PAGE_SHIFT) < max_low_pfn)
28744+#endif
28745 return;
28746
28747 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
28748@@ -344,7 +350,7 @@ static int __init early_ioremap_debug_setup(char *str)
28749 early_param("early_ioremap_debug", early_ioremap_debug_setup);
28750
28751 static __initdata int after_paging_init;
28752-static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
28753+static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
28754
28755 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
28756 {
28757@@ -381,8 +387,7 @@ void __init early_ioremap_init(void)
28758 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
28759
28760 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
28761- memset(bm_pte, 0, sizeof(bm_pte));
28762- pmd_populate_kernel(&init_mm, pmd, bm_pte);
28763+ pmd_populate_user(&init_mm, pmd, bm_pte);
28764
28765 /*
28766 * The boot-ioremap range spans multiple pmds, for which
28767diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
28768index d87dd6d..bf3fa66 100644
28769--- a/arch/x86/mm/kmemcheck/kmemcheck.c
28770+++ b/arch/x86/mm/kmemcheck/kmemcheck.c
28771@@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
28772 * memory (e.g. tracked pages)? For now, we need this to avoid
28773 * invoking kmemcheck for PnP BIOS calls.
28774 */
28775- if (regs->flags & X86_VM_MASK)
28776+ if (v8086_mode(regs))
28777 return false;
28778- if (regs->cs != __KERNEL_CS)
28779+ if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
28780 return false;
28781
28782 pte = kmemcheck_pte_lookup(address);
28783diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
28784index 845df68..1d8d29f 100644
28785--- a/arch/x86/mm/mmap.c
28786+++ b/arch/x86/mm/mmap.c
28787@@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
28788 * Leave an at least ~128 MB hole with possible stack randomization.
28789 */
28790 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
28791-#define MAX_GAP (TASK_SIZE/6*5)
28792+#define MAX_GAP (pax_task_size/6*5)
28793
28794 static int mmap_is_legacy(void)
28795 {
28796@@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
28797 return rnd << PAGE_SHIFT;
28798 }
28799
28800-static unsigned long mmap_base(void)
28801+static unsigned long mmap_base(struct mm_struct *mm)
28802 {
28803 unsigned long gap = rlimit(RLIMIT_STACK);
28804+ unsigned long pax_task_size = TASK_SIZE;
28805+
28806+#ifdef CONFIG_PAX_SEGMEXEC
28807+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28808+ pax_task_size = SEGMEXEC_TASK_SIZE;
28809+#endif
28810
28811 if (gap < MIN_GAP)
28812 gap = MIN_GAP;
28813 else if (gap > MAX_GAP)
28814 gap = MAX_GAP;
28815
28816- return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
28817+ return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
28818 }
28819
28820 /*
28821 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
28822 * does, but not when emulating X86_32
28823 */
28824-static unsigned long mmap_legacy_base(void)
28825+static unsigned long mmap_legacy_base(struct mm_struct *mm)
28826 {
28827- if (mmap_is_ia32())
28828+ if (mmap_is_ia32()) {
28829+
28830+#ifdef CONFIG_PAX_SEGMEXEC
28831+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
28832+ return SEGMEXEC_TASK_UNMAPPED_BASE;
28833+ else
28834+#endif
28835+
28836 return TASK_UNMAPPED_BASE;
28837- else
28838+ } else
28839 return TASK_UNMAPPED_BASE + mmap_rnd();
28840 }
28841
28842@@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
28843 void arch_pick_mmap_layout(struct mm_struct *mm)
28844 {
28845 if (mmap_is_legacy()) {
28846- mm->mmap_base = mmap_legacy_base();
28847+ mm->mmap_base = mmap_legacy_base(mm);
28848+
28849+#ifdef CONFIG_PAX_RANDMMAP
28850+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28851+ mm->mmap_base += mm->delta_mmap;
28852+#endif
28853+
28854 mm->get_unmapped_area = arch_get_unmapped_area;
28855 mm->unmap_area = arch_unmap_area;
28856 } else {
28857- mm->mmap_base = mmap_base();
28858+ mm->mmap_base = mmap_base(mm);
28859+
28860+#ifdef CONFIG_PAX_RANDMMAP
28861+ if (mm->pax_flags & MF_PAX_RANDMMAP)
28862+ mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
28863+#endif
28864+
28865 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
28866 mm->unmap_area = arch_unmap_area_topdown;
28867 }
28868diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
28869index dc0b727..f612039 100644
28870--- a/arch/x86/mm/mmio-mod.c
28871+++ b/arch/x86/mm/mmio-mod.c
28872@@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
28873 break;
28874 default:
28875 {
28876- unsigned char *ip = (unsigned char *)instptr;
28877+ unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
28878 my_trace->opcode = MMIO_UNKNOWN_OP;
28879 my_trace->width = 0;
28880 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
28881@@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
28882 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28883 void __iomem *addr)
28884 {
28885- static atomic_t next_id;
28886+ static atomic_unchecked_t next_id;
28887 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
28888 /* These are page-unaligned. */
28889 struct mmiotrace_map map = {
28890@@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
28891 .private = trace
28892 },
28893 .phys = offset,
28894- .id = atomic_inc_return(&next_id)
28895+ .id = atomic_inc_return_unchecked(&next_id)
28896 };
28897 map.map_id = trace->id;
28898
28899@@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
28900 ioremap_trace_core(offset, size, addr);
28901 }
28902
28903-static void iounmap_trace_core(volatile void __iomem *addr)
28904+static void iounmap_trace_core(const volatile void __iomem *addr)
28905 {
28906 struct mmiotrace_map map = {
28907 .phys = 0,
28908@@ -328,7 +328,7 @@ not_enabled:
28909 }
28910 }
28911
28912-void mmiotrace_iounmap(volatile void __iomem *addr)
28913+void mmiotrace_iounmap(const volatile void __iomem *addr)
28914 {
28915 might_sleep();
28916 if (is_enabled()) /* recheck and proper locking in *_core() */
28917diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
28918index 72fe01e..f1a8daa 100644
28919--- a/arch/x86/mm/numa.c
28920+++ b/arch/x86/mm/numa.c
28921@@ -477,7 +477,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
28922 return true;
28923 }
28924
28925-static int __init numa_register_memblks(struct numa_meminfo *mi)
28926+static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
28927 {
28928 unsigned long uninitialized_var(pfn_align);
28929 int i, nid;
28930diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
28931index 0e38951..4ca8458 100644
28932--- a/arch/x86/mm/pageattr-test.c
28933+++ b/arch/x86/mm/pageattr-test.c
28934@@ -36,7 +36,7 @@ enum {
28935
28936 static int pte_testbit(pte_t pte)
28937 {
28938- return pte_flags(pte) & _PAGE_UNUSED1;
28939+ return pte_flags(pte) & _PAGE_CPA_TEST;
28940 }
28941
28942 struct split_state {
28943diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
28944index fb4e73e..43f7238 100644
28945--- a/arch/x86/mm/pageattr.c
28946+++ b/arch/x86/mm/pageattr.c
28947@@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28948 */
28949 #ifdef CONFIG_PCI_BIOS
28950 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
28951- pgprot_val(forbidden) |= _PAGE_NX;
28952+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28953 #endif
28954
28955 /*
28956@@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28957 * Does not cover __inittext since that is gone later on. On
28958 * 64bit we do not enforce !NX on the low mapping
28959 */
28960- if (within(address, (unsigned long)_text, (unsigned long)_etext))
28961- pgprot_val(forbidden) |= _PAGE_NX;
28962+ if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
28963+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28964
28965+#ifdef CONFIG_DEBUG_RODATA
28966 /*
28967 * The .rodata section needs to be read-only. Using the pfn
28968 * catches all aliases.
28969@@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28970 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
28971 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
28972 pgprot_val(forbidden) |= _PAGE_RW;
28973+#endif
28974
28975 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
28976 /*
28977@@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
28978 }
28979 #endif
28980
28981+#ifdef CONFIG_PAX_KERNEXEC
28982+ if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
28983+ pgprot_val(forbidden) |= _PAGE_RW;
28984+ pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
28985+ }
28986+#endif
28987+
28988 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
28989
28990 return prot;
28991@@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
28992 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
28993 {
28994 /* change init_mm */
28995+ pax_open_kernel();
28996 set_pte_atomic(kpte, pte);
28997+
28998 #ifdef CONFIG_X86_32
28999 if (!SHARED_KERNEL_PMD) {
29000+
29001+#ifdef CONFIG_PAX_PER_CPU_PGD
29002+ unsigned long cpu;
29003+#else
29004 struct page *page;
29005+#endif
29006
29007+#ifdef CONFIG_PAX_PER_CPU_PGD
29008+ for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
29009+ pgd_t *pgd = get_cpu_pgd(cpu);
29010+#else
29011 list_for_each_entry(page, &pgd_list, lru) {
29012- pgd_t *pgd;
29013+ pgd_t *pgd = (pgd_t *)page_address(page);
29014+#endif
29015+
29016 pud_t *pud;
29017 pmd_t *pmd;
29018
29019- pgd = (pgd_t *)page_address(page) + pgd_index(address);
29020+ pgd += pgd_index(address);
29021 pud = pud_offset(pgd, address);
29022 pmd = pmd_offset(pud, address);
29023 set_pte_atomic((pte_t *)pmd, pte);
29024 }
29025 }
29026 #endif
29027+ pax_close_kernel();
29028 }
29029
29030 static int
29031diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
29032index 6574388..87e9bef 100644
29033--- a/arch/x86/mm/pat.c
29034+++ b/arch/x86/mm/pat.c
29035@@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
29036
29037 if (!entry) {
29038 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
29039- current->comm, current->pid, start, end - 1);
29040+ current->comm, task_pid_nr(current), start, end - 1);
29041 return -EINVAL;
29042 }
29043
29044@@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29045
29046 while (cursor < to) {
29047 if (!devmem_is_allowed(pfn)) {
29048- printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
29049- current->comm, from, to - 1);
29050+ printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
29051+ current->comm, from, to - 1, cursor);
29052 return 0;
29053 }
29054 cursor += PAGE_SIZE;
29055@@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
29056 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
29057 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
29058 "for [mem %#010Lx-%#010Lx]\n",
29059- current->comm, current->pid,
29060+ current->comm, task_pid_nr(current),
29061 cattr_name(flags),
29062 base, (unsigned long long)(base + size-1));
29063 return -EINVAL;
29064@@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29065 flags = lookup_memtype(paddr);
29066 if (want_flags != flags) {
29067 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
29068- current->comm, current->pid,
29069+ current->comm, task_pid_nr(current),
29070 cattr_name(want_flags),
29071 (unsigned long long)paddr,
29072 (unsigned long long)(paddr + size - 1),
29073@@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
29074 free_memtype(paddr, paddr + size);
29075 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
29076 " for [mem %#010Lx-%#010Lx], got %s\n",
29077- current->comm, current->pid,
29078+ current->comm, task_pid_nr(current),
29079 cattr_name(want_flags),
29080 (unsigned long long)paddr,
29081 (unsigned long long)(paddr + size - 1),
29082diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
29083index 9f0614d..92ae64a 100644
29084--- a/arch/x86/mm/pf_in.c
29085+++ b/arch/x86/mm/pf_in.c
29086@@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
29087 int i;
29088 enum reason_type rv = OTHERS;
29089
29090- p = (unsigned char *)ins_addr;
29091+ p = (unsigned char *)ktla_ktva(ins_addr);
29092 p += skip_prefix(p, &prf);
29093 p += get_opcode(p, &opcode);
29094
29095@@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
29096 struct prefix_bits prf;
29097 int i;
29098
29099- p = (unsigned char *)ins_addr;
29100+ p = (unsigned char *)ktla_ktva(ins_addr);
29101 p += skip_prefix(p, &prf);
29102 p += get_opcode(p, &opcode);
29103
29104@@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
29105 struct prefix_bits prf;
29106 int i;
29107
29108- p = (unsigned char *)ins_addr;
29109+ p = (unsigned char *)ktla_ktva(ins_addr);
29110 p += skip_prefix(p, &prf);
29111 p += get_opcode(p, &opcode);
29112
29113@@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
29114 struct prefix_bits prf;
29115 int i;
29116
29117- p = (unsigned char *)ins_addr;
29118+ p = (unsigned char *)ktla_ktva(ins_addr);
29119 p += skip_prefix(p, &prf);
29120 p += get_opcode(p, &opcode);
29121 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
29122@@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
29123 struct prefix_bits prf;
29124 int i;
29125
29126- p = (unsigned char *)ins_addr;
29127+ p = (unsigned char *)ktla_ktva(ins_addr);
29128 p += skip_prefix(p, &prf);
29129 p += get_opcode(p, &opcode);
29130 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
29131diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
29132index 17fda6a..489c74a 100644
29133--- a/arch/x86/mm/pgtable.c
29134+++ b/arch/x86/mm/pgtable.c
29135@@ -91,10 +91,64 @@ static inline void pgd_list_del(pgd_t *pgd)
29136 list_del(&page->lru);
29137 }
29138
29139-#define UNSHARED_PTRS_PER_PGD \
29140- (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29141+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29142+pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
29143
29144+void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
29145+{
29146+ unsigned int count = USER_PGD_PTRS;
29147
29148+ while (count--)
29149+ *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
29150+}
29151+#endif
29152+
29153+#ifdef CONFIG_PAX_PER_CPU_PGD
29154+void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
29155+{
29156+ unsigned int count = USER_PGD_PTRS;
29157+
29158+ while (count--) {
29159+ pgd_t pgd;
29160+
29161+#ifdef CONFIG_X86_64
29162+ pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
29163+#else
29164+ pgd = *src++;
29165+#endif
29166+
29167+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29168+ pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
29169+#endif
29170+
29171+ *dst++ = pgd;
29172+ }
29173+
29174+}
29175+#endif
29176+
29177+#ifdef CONFIG_X86_64
29178+#define pxd_t pud_t
29179+#define pyd_t pgd_t
29180+#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
29181+#define pxd_free(mm, pud) pud_free((mm), (pud))
29182+#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
29183+#define pyd_offset(mm, address) pgd_offset((mm), (address))
29184+#define PYD_SIZE PGDIR_SIZE
29185+#else
29186+#define pxd_t pmd_t
29187+#define pyd_t pud_t
29188+#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
29189+#define pxd_free(mm, pud) pmd_free((mm), (pud))
29190+#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
29191+#define pyd_offset(mm, address) pud_offset((mm), (address))
29192+#define PYD_SIZE PUD_SIZE
29193+#endif
29194+
29195+#ifdef CONFIG_PAX_PER_CPU_PGD
29196+static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
29197+static inline void pgd_dtor(pgd_t *pgd) {}
29198+#else
29199 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
29200 {
29201 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
29202@@ -135,6 +189,7 @@ static void pgd_dtor(pgd_t *pgd)
29203 pgd_list_del(pgd);
29204 spin_unlock(&pgd_lock);
29205 }
29206+#endif
29207
29208 /*
29209 * List of all pgd's needed for non-PAE so it can invalidate entries
29210@@ -147,7 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
29211 * -- nyc
29212 */
29213
29214-#ifdef CONFIG_X86_PAE
29215+#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
29216 /*
29217 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
29218 * updating the top-level pagetable entries to guarantee the
29219@@ -159,7 +214,7 @@ static void pgd_dtor(pgd_t *pgd)
29220 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
29221 * and initialize the kernel pmds here.
29222 */
29223-#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
29224+#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
29225
29226 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29227 {
29228@@ -177,36 +232,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
29229 */
29230 flush_tlb_mm(mm);
29231 }
29232+#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
29233+#define PREALLOCATED_PXDS USER_PGD_PTRS
29234 #else /* !CONFIG_X86_PAE */
29235
29236 /* No need to prepopulate any pagetable entries in non-PAE modes. */
29237-#define PREALLOCATED_PMDS 0
29238+#define PREALLOCATED_PXDS 0
29239
29240 #endif /* CONFIG_X86_PAE */
29241
29242-static void free_pmds(pmd_t *pmds[])
29243+static void free_pxds(pxd_t *pxds[])
29244 {
29245 int i;
29246
29247- for(i = 0; i < PREALLOCATED_PMDS; i++)
29248- if (pmds[i])
29249- free_page((unsigned long)pmds[i]);
29250+ for(i = 0; i < PREALLOCATED_PXDS; i++)
29251+ if (pxds[i])
29252+ free_page((unsigned long)pxds[i]);
29253 }
29254
29255-static int preallocate_pmds(pmd_t *pmds[])
29256+static int preallocate_pxds(pxd_t *pxds[])
29257 {
29258 int i;
29259 bool failed = false;
29260
29261- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29262- pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
29263- if (pmd == NULL)
29264+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29265+ pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
29266+ if (pxd == NULL)
29267 failed = true;
29268- pmds[i] = pmd;
29269+ pxds[i] = pxd;
29270 }
29271
29272 if (failed) {
29273- free_pmds(pmds);
29274+ free_pxds(pxds);
29275 return -ENOMEM;
29276 }
29277
29278@@ -219,51 +276,55 @@ static int preallocate_pmds(pmd_t *pmds[])
29279 * preallocate which never got a corresponding vma will need to be
29280 * freed manually.
29281 */
29282-static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
29283+static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
29284 {
29285 int i;
29286
29287- for(i = 0; i < PREALLOCATED_PMDS; i++) {
29288+ for(i = 0; i < PREALLOCATED_PXDS; i++) {
29289 pgd_t pgd = pgdp[i];
29290
29291 if (pgd_val(pgd) != 0) {
29292- pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
29293+ pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
29294
29295- pgdp[i] = native_make_pgd(0);
29296+ set_pgd(pgdp + i, native_make_pgd(0));
29297
29298- paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
29299- pmd_free(mm, pmd);
29300+ paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
29301+ pxd_free(mm, pxd);
29302 }
29303 }
29304 }
29305
29306-static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
29307+static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
29308 {
29309- pud_t *pud;
29310+ pyd_t *pyd;
29311 unsigned long addr;
29312 int i;
29313
29314- if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
29315+ if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
29316 return;
29317
29318- pud = pud_offset(pgd, 0);
29319+#ifdef CONFIG_X86_64
29320+ pyd = pyd_offset(mm, 0L);
29321+#else
29322+ pyd = pyd_offset(pgd, 0L);
29323+#endif
29324
29325- for (addr = i = 0; i < PREALLOCATED_PMDS;
29326- i++, pud++, addr += PUD_SIZE) {
29327- pmd_t *pmd = pmds[i];
29328+ for (addr = i = 0; i < PREALLOCATED_PXDS;
29329+ i++, pyd++, addr += PYD_SIZE) {
29330+ pxd_t *pxd = pxds[i];
29331
29332 if (i >= KERNEL_PGD_BOUNDARY)
29333- memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29334- sizeof(pmd_t) * PTRS_PER_PMD);
29335+ memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
29336+ sizeof(pxd_t) * PTRS_PER_PMD);
29337
29338- pud_populate(mm, pud, pmd);
29339+ pyd_populate(mm, pyd, pxd);
29340 }
29341 }
29342
29343 pgd_t *pgd_alloc(struct mm_struct *mm)
29344 {
29345 pgd_t *pgd;
29346- pmd_t *pmds[PREALLOCATED_PMDS];
29347+ pxd_t *pxds[PREALLOCATED_PXDS];
29348
29349 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
29350
29351@@ -272,11 +333,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29352
29353 mm->pgd = pgd;
29354
29355- if (preallocate_pmds(pmds) != 0)
29356+ if (preallocate_pxds(pxds) != 0)
29357 goto out_free_pgd;
29358
29359 if (paravirt_pgd_alloc(mm) != 0)
29360- goto out_free_pmds;
29361+ goto out_free_pxds;
29362
29363 /*
29364 * Make sure that pre-populating the pmds is atomic with
29365@@ -286,14 +347,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
29366 spin_lock(&pgd_lock);
29367
29368 pgd_ctor(mm, pgd);
29369- pgd_prepopulate_pmd(mm, pgd, pmds);
29370+ pgd_prepopulate_pxd(mm, pgd, pxds);
29371
29372 spin_unlock(&pgd_lock);
29373
29374 return pgd;
29375
29376-out_free_pmds:
29377- free_pmds(pmds);
29378+out_free_pxds:
29379+ free_pxds(pxds);
29380 out_free_pgd:
29381 free_page((unsigned long)pgd);
29382 out:
29383@@ -302,7 +363,7 @@ out:
29384
29385 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
29386 {
29387- pgd_mop_up_pmds(mm, pgd);
29388+ pgd_mop_up_pxds(mm, pgd);
29389 pgd_dtor(pgd);
29390 paravirt_pgd_free(mm, pgd);
29391 free_page((unsigned long)pgd);
29392diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
29393index a69bcb8..19068ab 100644
29394--- a/arch/x86/mm/pgtable_32.c
29395+++ b/arch/x86/mm/pgtable_32.c
29396@@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
29397 return;
29398 }
29399 pte = pte_offset_kernel(pmd, vaddr);
29400+
29401+ pax_open_kernel();
29402 if (pte_val(pteval))
29403 set_pte_at(&init_mm, vaddr, pte, pteval);
29404 else
29405 pte_clear(&init_mm, vaddr, pte);
29406+ pax_close_kernel();
29407
29408 /*
29409 * It's enough to flush this one mapping.
29410diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
29411index e666cbb..61788c45 100644
29412--- a/arch/x86/mm/physaddr.c
29413+++ b/arch/x86/mm/physaddr.c
29414@@ -10,7 +10,7 @@
29415 #ifdef CONFIG_X86_64
29416
29417 #ifdef CONFIG_DEBUG_VIRTUAL
29418-unsigned long __phys_addr(unsigned long x)
29419+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29420 {
29421 unsigned long y = x - __START_KERNEL_map;
29422
29423@@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
29424 #else
29425
29426 #ifdef CONFIG_DEBUG_VIRTUAL
29427-unsigned long __phys_addr(unsigned long x)
29428+unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
29429 {
29430 unsigned long phys_addr = x - PAGE_OFFSET;
29431 /* VMALLOC_* aren't constants */
29432diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
29433index 410531d..0f16030 100644
29434--- a/arch/x86/mm/setup_nx.c
29435+++ b/arch/x86/mm/setup_nx.c
29436@@ -5,8 +5,10 @@
29437 #include <asm/pgtable.h>
29438 #include <asm/proto.h>
29439
29440+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29441 static int disable_nx __cpuinitdata;
29442
29443+#ifndef CONFIG_PAX_PAGEEXEC
29444 /*
29445 * noexec = on|off
29446 *
29447@@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
29448 return 0;
29449 }
29450 early_param("noexec", noexec_setup);
29451+#endif
29452+
29453+#endif
29454
29455 void __cpuinit x86_configure_nx(void)
29456 {
29457+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
29458 if (cpu_has_nx && !disable_nx)
29459 __supported_pte_mask |= _PAGE_NX;
29460 else
29461+#endif
29462 __supported_pte_mask &= ~_PAGE_NX;
29463 }
29464
29465diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
29466index 282375f..e03a98f 100644
29467--- a/arch/x86/mm/tlb.c
29468+++ b/arch/x86/mm/tlb.c
29469@@ -48,7 +48,11 @@ void leave_mm(int cpu)
29470 BUG();
29471 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
29472 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
29473+
29474+#ifndef CONFIG_PAX_PER_CPU_PGD
29475 load_cr3(swapper_pg_dir);
29476+#endif
29477+
29478 }
29479 }
29480 EXPORT_SYMBOL_GPL(leave_mm);
29481diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
29482index 877b9a1..a8ecf42 100644
29483--- a/arch/x86/net/bpf_jit.S
29484+++ b/arch/x86/net/bpf_jit.S
29485@@ -9,6 +9,7 @@
29486 */
29487 #include <linux/linkage.h>
29488 #include <asm/dwarf2.h>
29489+#include <asm/alternative-asm.h>
29490
29491 /*
29492 * Calling convention :
29493@@ -35,6 +36,7 @@ sk_load_word_positive_offset:
29494 jle bpf_slow_path_word
29495 mov (SKBDATA,%rsi),%eax
29496 bswap %eax /* ntohl() */
29497+ pax_force_retaddr
29498 ret
29499
29500 sk_load_half:
29501@@ -52,6 +54,7 @@ sk_load_half_positive_offset:
29502 jle bpf_slow_path_half
29503 movzwl (SKBDATA,%rsi),%eax
29504 rol $8,%ax # ntohs()
29505+ pax_force_retaddr
29506 ret
29507
29508 sk_load_byte:
29509@@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
29510 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
29511 jle bpf_slow_path_byte
29512 movzbl (SKBDATA,%rsi),%eax
29513+ pax_force_retaddr
29514 ret
29515
29516 /**
29517@@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
29518 movzbl (SKBDATA,%rsi),%ebx
29519 and $15,%bl
29520 shl $2,%bl
29521+ pax_force_retaddr
29522 ret
29523
29524 /* rsi contains offset and can be scratched */
29525@@ -109,6 +114,7 @@ bpf_slow_path_word:
29526 js bpf_error
29527 mov -12(%rbp),%eax
29528 bswap %eax
29529+ pax_force_retaddr
29530 ret
29531
29532 bpf_slow_path_half:
29533@@ -117,12 +123,14 @@ bpf_slow_path_half:
29534 mov -12(%rbp),%ax
29535 rol $8,%ax
29536 movzwl %ax,%eax
29537+ pax_force_retaddr
29538 ret
29539
29540 bpf_slow_path_byte:
29541 bpf_slow_path_common(1)
29542 js bpf_error
29543 movzbl -12(%rbp),%eax
29544+ pax_force_retaddr
29545 ret
29546
29547 bpf_slow_path_byte_msh:
29548@@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
29549 and $15,%al
29550 shl $2,%al
29551 xchg %eax,%ebx
29552+ pax_force_retaddr
29553 ret
29554
29555 #define sk_negative_common(SIZE) \
29556@@ -157,6 +166,7 @@ sk_load_word_negative_offset:
29557 sk_negative_common(4)
29558 mov (%rax), %eax
29559 bswap %eax
29560+ pax_force_retaddr
29561 ret
29562
29563 bpf_slow_path_half_neg:
29564@@ -168,6 +178,7 @@ sk_load_half_negative_offset:
29565 mov (%rax),%ax
29566 rol $8,%ax
29567 movzwl %ax,%eax
29568+ pax_force_retaddr
29569 ret
29570
29571 bpf_slow_path_byte_neg:
29572@@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
29573 .globl sk_load_byte_negative_offset
29574 sk_negative_common(1)
29575 movzbl (%rax), %eax
29576+ pax_force_retaddr
29577 ret
29578
29579 bpf_slow_path_byte_msh_neg:
29580@@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
29581 and $15,%al
29582 shl $2,%al
29583 xchg %eax,%ebx
29584+ pax_force_retaddr
29585 ret
29586
29587 bpf_error:
29588@@ -197,4 +210,5 @@ bpf_error:
29589 xor %eax,%eax
29590 mov -8(%rbp),%rbx
29591 leaveq
29592+ pax_force_retaddr
29593 ret
29594diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
29595index 3cbe4538..003d011 100644
29596--- a/arch/x86/net/bpf_jit_comp.c
29597+++ b/arch/x86/net/bpf_jit_comp.c
29598@@ -12,6 +12,7 @@
29599 #include <linux/netdevice.h>
29600 #include <linux/filter.h>
29601 #include <linux/if_vlan.h>
29602+#include <linux/random.h>
29603
29604 /*
29605 * Conventions :
29606@@ -49,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
29607 return ptr + len;
29608 }
29609
29610+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29611+#define MAX_INSTR_CODE_SIZE 96
29612+#else
29613+#define MAX_INSTR_CODE_SIZE 64
29614+#endif
29615+
29616 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
29617
29618 #define EMIT1(b1) EMIT(b1, 1)
29619 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
29620 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
29621 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
29622+
29623+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29624+/* original constant will appear in ecx */
29625+#define DILUTE_CONST_SEQUENCE(_off, _key) \
29626+do { \
29627+ /* mov ecx, randkey */ \
29628+ EMIT1(0xb9); \
29629+ EMIT(_key, 4); \
29630+ /* xor ecx, randkey ^ off */ \
29631+ EMIT2(0x81, 0xf1); \
29632+ EMIT((_key) ^ (_off), 4); \
29633+} while (0)
29634+
29635+#define EMIT1_off32(b1, _off) \
29636+do { \
29637+ switch (b1) { \
29638+ case 0x05: /* add eax, imm32 */ \
29639+ case 0x2d: /* sub eax, imm32 */ \
29640+ case 0x25: /* and eax, imm32 */ \
29641+ case 0x0d: /* or eax, imm32 */ \
29642+ case 0xb8: /* mov eax, imm32 */ \
29643+ case 0x35: /* xor eax, imm32 */ \
29644+ case 0x3d: /* cmp eax, imm32 */ \
29645+ case 0xa9: /* test eax, imm32 */ \
29646+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29647+ EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
29648+ break; \
29649+ case 0xbb: /* mov ebx, imm32 */ \
29650+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29651+ /* mov ebx, ecx */ \
29652+ EMIT2(0x89, 0xcb); \
29653+ break; \
29654+ case 0xbe: /* mov esi, imm32 */ \
29655+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29656+ /* mov esi, ecx */ \
29657+ EMIT2(0x89, 0xce); \
29658+ break; \
29659+ case 0xe8: /* call rel imm32, always to known funcs */ \
29660+ EMIT1(b1); \
29661+ EMIT(_off, 4); \
29662+ break; \
29663+ case 0xe9: /* jmp rel imm32 */ \
29664+ EMIT1(b1); \
29665+ EMIT(_off, 4); \
29666+ /* prevent fall-through, we're not called if off = 0 */ \
29667+ EMIT(0xcccccccc, 4); \
29668+ EMIT(0xcccccccc, 4); \
29669+ break; \
29670+ default: \
29671+ BUILD_BUG(); \
29672+ } \
29673+} while (0)
29674+
29675+#define EMIT2_off32(b1, b2, _off) \
29676+do { \
29677+ if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
29678+ EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
29679+ EMIT(randkey, 4); \
29680+ EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
29681+ EMIT((_off) - randkey, 4); \
29682+ } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
29683+ DILUTE_CONST_SEQUENCE(_off, randkey); \
29684+ /* imul eax, ecx */ \
29685+ EMIT3(0x0f, 0xaf, 0xc1); \
29686+ } else { \
29687+ BUILD_BUG(); \
29688+ } \
29689+} while (0)
29690+#else
29691 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
29692+#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
29693+#endif
29694
29695 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
29696 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
29697@@ -90,6 +168,24 @@ do { \
29698 #define X86_JBE 0x76
29699 #define X86_JA 0x77
29700
29701+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29702+#define APPEND_FLOW_VERIFY() \
29703+do { \
29704+ /* mov ecx, randkey */ \
29705+ EMIT1(0xb9); \
29706+ EMIT(randkey, 4); \
29707+ /* cmp ecx, randkey */ \
29708+ EMIT2(0x81, 0xf9); \
29709+ EMIT(randkey, 4); \
29710+ /* jz after 8 int 3s */ \
29711+ EMIT2(0x74, 0x08); \
29712+ EMIT(0xcccccccc, 4); \
29713+ EMIT(0xcccccccc, 4); \
29714+} while (0)
29715+#else
29716+#define APPEND_FLOW_VERIFY() do { } while (0)
29717+#endif
29718+
29719 #define EMIT_COND_JMP(op, offset) \
29720 do { \
29721 if (is_near(offset)) \
29722@@ -97,6 +193,7 @@ do { \
29723 else { \
29724 EMIT2(0x0f, op + 0x10); \
29725 EMIT(offset, 4); /* jxx .+off32 */ \
29726+ APPEND_FLOW_VERIFY(); \
29727 } \
29728 } while (0)
29729
29730@@ -121,6 +218,11 @@ static inline void bpf_flush_icache(void *start, void *end)
29731 set_fs(old_fs);
29732 }
29733
29734+struct bpf_jit_work {
29735+ struct work_struct work;
29736+ void *image;
29737+};
29738+
29739 #define CHOOSE_LOAD_FUNC(K, func) \
29740 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
29741
29742@@ -146,7 +248,7 @@ static int pkt_type_offset(void)
29743
29744 void bpf_jit_compile(struct sk_filter *fp)
29745 {
29746- u8 temp[64];
29747+ u8 temp[MAX_INSTR_CODE_SIZE];
29748 u8 *prog;
29749 unsigned int proglen, oldproglen = 0;
29750 int ilen, i;
29751@@ -159,6 +261,9 @@ void bpf_jit_compile(struct sk_filter *fp)
29752 unsigned int *addrs;
29753 const struct sock_filter *filter = fp->insns;
29754 int flen = fp->len;
29755+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29756+ unsigned int randkey;
29757+#endif
29758
29759 if (!bpf_jit_enable)
29760 return;
29761@@ -167,11 +272,19 @@ void bpf_jit_compile(struct sk_filter *fp)
29762 if (addrs == NULL)
29763 return;
29764
29765+ fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
29766+ if (!fp->work)
29767+ goto out;
29768+
29769+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29770+ randkey = get_random_int();
29771+#endif
29772+
29773 /* Before first pass, make a rough estimation of addrs[]
29774- * each bpf instruction is translated to less than 64 bytes
29775+ * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
29776 */
29777 for (proglen = 0, i = 0; i < flen; i++) {
29778- proglen += 64;
29779+ proglen += MAX_INSTR_CODE_SIZE;
29780 addrs[i] = proglen;
29781 }
29782 cleanup_addr = proglen; /* epilogue address */
29783@@ -282,10 +395,8 @@ void bpf_jit_compile(struct sk_filter *fp)
29784 case BPF_S_ALU_MUL_K: /* A *= K */
29785 if (is_imm8(K))
29786 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
29787- else {
29788- EMIT2(0x69, 0xc0); /* imul imm32,%eax */
29789- EMIT(K, 4);
29790- }
29791+ else
29792+ EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
29793 break;
29794 case BPF_S_ALU_DIV_X: /* A /= X; */
29795 seen |= SEEN_XREG;
29796@@ -325,13 +436,23 @@ void bpf_jit_compile(struct sk_filter *fp)
29797 break;
29798 case BPF_S_ALU_MOD_K: /* A %= K; */
29799 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
29800+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29801+ DILUTE_CONST_SEQUENCE(K, randkey);
29802+#else
29803 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
29804+#endif
29805 EMIT2(0xf7, 0xf1); /* div %ecx */
29806 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
29807 break;
29808 case BPF_S_ALU_DIV_K: /* A = reciprocal_divide(A, K); */
29809+#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
29810+ DILUTE_CONST_SEQUENCE(K, randkey);
29811+ // imul rax, rcx
29812+ EMIT4(0x48, 0x0f, 0xaf, 0xc1);
29813+#else
29814 EMIT3(0x48, 0x69, 0xc0); /* imul imm32,%rax,%rax */
29815 EMIT(K, 4);
29816+#endif
29817 EMIT4(0x48, 0xc1, 0xe8, 0x20); /* shr $0x20,%rax */
29818 break;
29819 case BPF_S_ALU_AND_X:
29820@@ -602,8 +723,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
29821 if (is_imm8(K)) {
29822 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
29823 } else {
29824- EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
29825- EMIT(K, 4);
29826+ EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
29827 }
29828 } else {
29829 EMIT2(0x89,0xde); /* mov %ebx,%esi */
29830@@ -686,17 +806,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29831 break;
29832 default:
29833 /* hmm, too complex filter, give up with jit compiler */
29834- goto out;
29835+ goto error;
29836 }
29837 ilen = prog - temp;
29838 if (image) {
29839 if (unlikely(proglen + ilen > oldproglen)) {
29840 pr_err("bpb_jit_compile fatal error\n");
29841- kfree(addrs);
29842- module_free(NULL, image);
29843- return;
29844+ module_free_exec(NULL, image);
29845+ goto error;
29846 }
29847+ pax_open_kernel();
29848 memcpy(image + proglen, temp, ilen);
29849+ pax_close_kernel();
29850 }
29851 proglen += ilen;
29852 addrs[i] = proglen;
29853@@ -717,11 +838,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29854 break;
29855 }
29856 if (proglen == oldproglen) {
29857- image = module_alloc(max_t(unsigned int,
29858- proglen,
29859- sizeof(struct work_struct)));
29860+ image = module_alloc_exec(proglen);
29861 if (!image)
29862- goto out;
29863+ goto error;
29864 }
29865 oldproglen = proglen;
29866 }
29867@@ -737,7 +856,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
29868 bpf_flush_icache(image, image + proglen);
29869
29870 fp->bpf_func = (void *)image;
29871- }
29872+ } else
29873+error:
29874+ kfree(fp->work);
29875+
29876 out:
29877 kfree(addrs);
29878 return;
29879@@ -745,18 +867,20 @@ out:
29880
29881 static void jit_free_defer(struct work_struct *arg)
29882 {
29883- module_free(NULL, arg);
29884+ module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
29885+ kfree(arg);
29886 }
29887
29888 /* run from softirq, we must use a work_struct to call
29889- * module_free() from process context
29890+ * module_free_exec() from process context
29891 */
29892 void bpf_jit_free(struct sk_filter *fp)
29893 {
29894 if (fp->bpf_func != sk_run_filter) {
29895- struct work_struct *work = (struct work_struct *)fp->bpf_func;
29896+ struct work_struct *work = &fp->work->work;
29897
29898 INIT_WORK(work, jit_free_defer);
29899+ fp->work->image = fp->bpf_func;
29900 schedule_work(work);
29901 }
29902 }
29903diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
29904index d6aa6e8..266395a 100644
29905--- a/arch/x86/oprofile/backtrace.c
29906+++ b/arch/x86/oprofile/backtrace.c
29907@@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
29908 struct stack_frame_ia32 *fp;
29909 unsigned long bytes;
29910
29911- bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
29912+ bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
29913 if (bytes != sizeof(bufhead))
29914 return NULL;
29915
29916- fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
29917+ fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
29918
29919 oprofile_add_trace(bufhead[0].return_address);
29920
29921@@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
29922 struct stack_frame bufhead[2];
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@@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
29931 {
29932 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
29933
29934- if (!user_mode_vm(regs)) {
29935+ if (!user_mode(regs)) {
29936 unsigned long stack = kernel_stack_pointer(regs);
29937 if (depth)
29938 dump_trace(NULL, regs, (unsigned long *)stack, 0,
29939diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
29940index 48768df..ba9143c 100644
29941--- a/arch/x86/oprofile/nmi_int.c
29942+++ b/arch/x86/oprofile/nmi_int.c
29943@@ -23,6 +23,7 @@
29944 #include <asm/nmi.h>
29945 #include <asm/msr.h>
29946 #include <asm/apic.h>
29947+#include <asm/pgtable.h>
29948
29949 #include "op_counter.h"
29950 #include "op_x86_model.h"
29951@@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
29952 if (ret)
29953 return ret;
29954
29955- if (!model->num_virt_counters)
29956- model->num_virt_counters = model->num_counters;
29957+ if (!model->num_virt_counters) {
29958+ pax_open_kernel();
29959+ *(unsigned int *)&model->num_virt_counters = model->num_counters;
29960+ pax_close_kernel();
29961+ }
29962
29963 mux_init(ops);
29964
29965diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
29966index b2b9443..be58856 100644
29967--- a/arch/x86/oprofile/op_model_amd.c
29968+++ b/arch/x86/oprofile/op_model_amd.c
29969@@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
29970 num_counters = AMD64_NUM_COUNTERS;
29971 }
29972
29973- op_amd_spec.num_counters = num_counters;
29974- op_amd_spec.num_controls = num_counters;
29975- op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29976+ pax_open_kernel();
29977+ *(unsigned int *)&op_amd_spec.num_counters = num_counters;
29978+ *(unsigned int *)&op_amd_spec.num_controls = num_counters;
29979+ *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
29980+ pax_close_kernel();
29981
29982 return 0;
29983 }
29984diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
29985index d90528e..0127e2b 100644
29986--- a/arch/x86/oprofile/op_model_ppro.c
29987+++ b/arch/x86/oprofile/op_model_ppro.c
29988@@ -19,6 +19,7 @@
29989 #include <asm/msr.h>
29990 #include <asm/apic.h>
29991 #include <asm/nmi.h>
29992+#include <asm/pgtable.h>
29993
29994 #include "op_x86_model.h"
29995 #include "op_counter.h"
29996@@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
29997
29998 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
29999
30000- op_arch_perfmon_spec.num_counters = num_counters;
30001- op_arch_perfmon_spec.num_controls = num_counters;
30002+ pax_open_kernel();
30003+ *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
30004+ *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
30005+ pax_close_kernel();
30006 }
30007
30008 static int arch_perfmon_init(struct oprofile_operations *ignore)
30009diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
30010index 71e8a67..6a313bb 100644
30011--- a/arch/x86/oprofile/op_x86_model.h
30012+++ b/arch/x86/oprofile/op_x86_model.h
30013@@ -52,7 +52,7 @@ struct op_x86_model_spec {
30014 void (*switch_ctrl)(struct op_x86_model_spec const *model,
30015 struct op_msrs const * const msrs);
30016 #endif
30017-};
30018+} __do_const;
30019
30020 struct op_counter_config;
30021
30022diff --git a/arch/x86/pci/amd_bus.c b/arch/x86/pci/amd_bus.c
30023index e9e6ed5..e47ae67 100644
30024--- a/arch/x86/pci/amd_bus.c
30025+++ b/arch/x86/pci/amd_bus.c
30026@@ -337,7 +337,7 @@ static int __cpuinit amd_cpu_notify(struct notifier_block *self,
30027 return NOTIFY_OK;
30028 }
30029
30030-static struct notifier_block __cpuinitdata amd_cpu_notifier = {
30031+static struct notifier_block amd_cpu_notifier = {
30032 .notifier_call = amd_cpu_notify,
30033 };
30034
30035diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
30036index 372e9b8..e775a6c 100644
30037--- a/arch/x86/pci/irq.c
30038+++ b/arch/x86/pci/irq.c
30039@@ -50,7 +50,7 @@ struct irq_router {
30040 struct irq_router_handler {
30041 u16 vendor;
30042 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
30043-};
30044+} __do_const;
30045
30046 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
30047 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
30048@@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
30049 return 0;
30050 }
30051
30052-static __initdata struct irq_router_handler pirq_routers[] = {
30053+static __initconst const struct irq_router_handler pirq_routers[] = {
30054 { PCI_VENDOR_ID_INTEL, intel_router_probe },
30055 { PCI_VENDOR_ID_AL, ali_router_probe },
30056 { PCI_VENDOR_ID_ITE, ite_router_probe },
30057@@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
30058 static void __init pirq_find_router(struct irq_router *r)
30059 {
30060 struct irq_routing_table *rt = pirq_table;
30061- struct irq_router_handler *h;
30062+ const struct irq_router_handler *h;
30063
30064 #ifdef CONFIG_PCI_BIOS
30065 if (!rt->signature) {
30066@@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
30067 return 0;
30068 }
30069
30070-static struct dmi_system_id __initdata pciirq_dmi_table[] = {
30071+static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
30072 {
30073 .callback = fix_broken_hp_bios_irq9,
30074 .ident = "HP Pavilion N5400 Series Laptop",
30075diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
30076index 6eb18c4..20d83de 100644
30077--- a/arch/x86/pci/mrst.c
30078+++ b/arch/x86/pci/mrst.c
30079@@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
30080 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
30081 pci_mmcfg_late_init();
30082 pcibios_enable_irq = mrst_pci_irq_enable;
30083- pci_root_ops = pci_mrst_ops;
30084+ pax_open_kernel();
30085+ memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
30086+ pax_close_kernel();
30087 pci_soc_mode = 1;
30088 /* Continue with standard init */
30089 return 1;
30090diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
30091index c77b24a..c979855 100644
30092--- a/arch/x86/pci/pcbios.c
30093+++ b/arch/x86/pci/pcbios.c
30094@@ -79,7 +79,7 @@ union bios32 {
30095 static struct {
30096 unsigned long address;
30097 unsigned short segment;
30098-} bios32_indirect = { 0, __KERNEL_CS };
30099+} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
30100
30101 /*
30102 * Returns the entry point for the given service, NULL on error
30103@@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
30104 unsigned long length; /* %ecx */
30105 unsigned long entry; /* %edx */
30106 unsigned long flags;
30107+ struct desc_struct d, *gdt;
30108
30109 local_irq_save(flags);
30110- __asm__("lcall *(%%edi); cld"
30111+
30112+ gdt = get_cpu_gdt_table(smp_processor_id());
30113+
30114+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
30115+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30116+ pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
30117+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30118+
30119+ __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
30120 : "=a" (return_code),
30121 "=b" (address),
30122 "=c" (length),
30123 "=d" (entry)
30124 : "0" (service),
30125 "1" (0),
30126- "D" (&bios32_indirect));
30127+ "D" (&bios32_indirect),
30128+ "r"(__PCIBIOS_DS)
30129+ : "memory");
30130+
30131+ pax_open_kernel();
30132+ gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
30133+ gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
30134+ gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
30135+ gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
30136+ pax_close_kernel();
30137+
30138 local_irq_restore(flags);
30139
30140 switch (return_code) {
30141- case 0:
30142- return address + entry;
30143- case 0x80: /* Not present */
30144- printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30145- return 0;
30146- default: /* Shouldn't happen */
30147- printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30148- service, return_code);
30149+ case 0: {
30150+ int cpu;
30151+ unsigned char flags;
30152+
30153+ printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
30154+ if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
30155+ printk(KERN_WARNING "bios32_service: not valid\n");
30156 return 0;
30157+ }
30158+ address = address + PAGE_OFFSET;
30159+ length += 16UL; /* some BIOSs underreport this... */
30160+ flags = 4;
30161+ if (length >= 64*1024*1024) {
30162+ length >>= PAGE_SHIFT;
30163+ flags |= 8;
30164+ }
30165+
30166+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
30167+ gdt = get_cpu_gdt_table(cpu);
30168+ pack_descriptor(&d, address, length, 0x9b, flags);
30169+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
30170+ pack_descriptor(&d, address, length, 0x93, flags);
30171+ write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
30172+ }
30173+ return entry;
30174+ }
30175+ case 0x80: /* Not present */
30176+ printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
30177+ return 0;
30178+ default: /* Shouldn't happen */
30179+ printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
30180+ service, return_code);
30181+ return 0;
30182 }
30183 }
30184
30185 static struct {
30186 unsigned long address;
30187 unsigned short segment;
30188-} pci_indirect = { 0, __KERNEL_CS };
30189+} pci_indirect __read_only = { 0, __PCIBIOS_CS };
30190
30191-static int pci_bios_present;
30192+static int pci_bios_present __read_only;
30193
30194 static int check_pcibios(void)
30195 {
30196@@ -131,11 +174,13 @@ static int check_pcibios(void)
30197 unsigned long flags, pcibios_entry;
30198
30199 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
30200- pci_indirect.address = pcibios_entry + PAGE_OFFSET;
30201+ pci_indirect.address = pcibios_entry;
30202
30203 local_irq_save(flags);
30204- __asm__(
30205- "lcall *(%%edi); cld\n\t"
30206+ __asm__("movw %w6, %%ds\n\t"
30207+ "lcall *%%ss:(%%edi); cld\n\t"
30208+ "push %%ss\n\t"
30209+ "pop %%ds\n\t"
30210 "jc 1f\n\t"
30211 "xor %%ah, %%ah\n"
30212 "1:"
30213@@ -144,7 +189,8 @@ static int check_pcibios(void)
30214 "=b" (ebx),
30215 "=c" (ecx)
30216 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
30217- "D" (&pci_indirect)
30218+ "D" (&pci_indirect),
30219+ "r" (__PCIBIOS_DS)
30220 : "memory");
30221 local_irq_restore(flags);
30222
30223@@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30224
30225 switch (len) {
30226 case 1:
30227- __asm__("lcall *(%%esi); cld\n\t"
30228+ __asm__("movw %w6, %%ds\n\t"
30229+ "lcall *%%ss:(%%esi); cld\n\t"
30230+ "push %%ss\n\t"
30231+ "pop %%ds\n\t"
30232 "jc 1f\n\t"
30233 "xor %%ah, %%ah\n"
30234 "1:"
30235@@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30236 : "1" (PCIBIOS_READ_CONFIG_BYTE),
30237 "b" (bx),
30238 "D" ((long)reg),
30239- "S" (&pci_indirect));
30240+ "S" (&pci_indirect),
30241+ "r" (__PCIBIOS_DS));
30242 /*
30243 * Zero-extend the result beyond 8 bits, do not trust the
30244 * BIOS having done it:
30245@@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30246 *value &= 0xff;
30247 break;
30248 case 2:
30249- __asm__("lcall *(%%esi); cld\n\t"
30250+ __asm__("movw %w6, %%ds\n\t"
30251+ "lcall *%%ss:(%%esi); cld\n\t"
30252+ "push %%ss\n\t"
30253+ "pop %%ds\n\t"
30254 "jc 1f\n\t"
30255 "xor %%ah, %%ah\n"
30256 "1:"
30257@@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30258 : "1" (PCIBIOS_READ_CONFIG_WORD),
30259 "b" (bx),
30260 "D" ((long)reg),
30261- "S" (&pci_indirect));
30262+ "S" (&pci_indirect),
30263+ "r" (__PCIBIOS_DS));
30264 /*
30265 * Zero-extend the result beyond 16 bits, do not trust the
30266 * BIOS having done it:
30267@@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30268 *value &= 0xffff;
30269 break;
30270 case 4:
30271- __asm__("lcall *(%%esi); cld\n\t"
30272+ __asm__("movw %w6, %%ds\n\t"
30273+ "lcall *%%ss:(%%esi); cld\n\t"
30274+ "push %%ss\n\t"
30275+ "pop %%ds\n\t"
30276 "jc 1f\n\t"
30277 "xor %%ah, %%ah\n"
30278 "1:"
30279@@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
30280 : "1" (PCIBIOS_READ_CONFIG_DWORD),
30281 "b" (bx),
30282 "D" ((long)reg),
30283- "S" (&pci_indirect));
30284+ "S" (&pci_indirect),
30285+ "r" (__PCIBIOS_DS));
30286 break;
30287 }
30288
30289@@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30290
30291 switch (len) {
30292 case 1:
30293- __asm__("lcall *(%%esi); cld\n\t"
30294+ __asm__("movw %w6, %%ds\n\t"
30295+ "lcall *%%ss:(%%esi); cld\n\t"
30296+ "push %%ss\n\t"
30297+ "pop %%ds\n\t"
30298 "jc 1f\n\t"
30299 "xor %%ah, %%ah\n"
30300 "1:"
30301@@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30302 "c" (value),
30303 "b" (bx),
30304 "D" ((long)reg),
30305- "S" (&pci_indirect));
30306+ "S" (&pci_indirect),
30307+ "r" (__PCIBIOS_DS));
30308 break;
30309 case 2:
30310- __asm__("lcall *(%%esi); cld\n\t"
30311+ __asm__("movw %w6, %%ds\n\t"
30312+ "lcall *%%ss:(%%esi); cld\n\t"
30313+ "push %%ss\n\t"
30314+ "pop %%ds\n\t"
30315 "jc 1f\n\t"
30316 "xor %%ah, %%ah\n"
30317 "1:"
30318@@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30319 "c" (value),
30320 "b" (bx),
30321 "D" ((long)reg),
30322- "S" (&pci_indirect));
30323+ "S" (&pci_indirect),
30324+ "r" (__PCIBIOS_DS));
30325 break;
30326 case 4:
30327- __asm__("lcall *(%%esi); cld\n\t"
30328+ __asm__("movw %w6, %%ds\n\t"
30329+ "lcall *%%ss:(%%esi); cld\n\t"
30330+ "push %%ss\n\t"
30331+ "pop %%ds\n\t"
30332 "jc 1f\n\t"
30333 "xor %%ah, %%ah\n"
30334 "1:"
30335@@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
30336 "c" (value),
30337 "b" (bx),
30338 "D" ((long)reg),
30339- "S" (&pci_indirect));
30340+ "S" (&pci_indirect),
30341+ "r" (__PCIBIOS_DS));
30342 break;
30343 }
30344
30345@@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30346
30347 DBG("PCI: Fetching IRQ routing table... ");
30348 __asm__("push %%es\n\t"
30349+ "movw %w8, %%ds\n\t"
30350 "push %%ds\n\t"
30351 "pop %%es\n\t"
30352- "lcall *(%%esi); cld\n\t"
30353+ "lcall *%%ss:(%%esi); cld\n\t"
30354 "pop %%es\n\t"
30355+ "push %%ss\n\t"
30356+ "pop %%ds\n"
30357 "jc 1f\n\t"
30358 "xor %%ah, %%ah\n"
30359 "1:"
30360@@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
30361 "1" (0),
30362 "D" ((long) &opt),
30363 "S" (&pci_indirect),
30364- "m" (opt)
30365+ "m" (opt),
30366+ "r" (__PCIBIOS_DS)
30367 : "memory");
30368 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
30369 if (ret & 0xff00)
30370@@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30371 {
30372 int ret;
30373
30374- __asm__("lcall *(%%esi); cld\n\t"
30375+ __asm__("movw %w5, %%ds\n\t"
30376+ "lcall *%%ss:(%%esi); cld\n\t"
30377+ "push %%ss\n\t"
30378+ "pop %%ds\n"
30379 "jc 1f\n\t"
30380 "xor %%ah, %%ah\n"
30381 "1:"
30382@@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
30383 : "0" (PCIBIOS_SET_PCI_HW_INT),
30384 "b" ((dev->bus->number << 8) | dev->devfn),
30385 "c" ((irq << 8) | (pin + 10)),
30386- "S" (&pci_indirect));
30387+ "S" (&pci_indirect),
30388+ "r" (__PCIBIOS_DS));
30389 return !(ret & 0xff00);
30390 }
30391 EXPORT_SYMBOL(pcibios_set_irq_routing);
30392diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
30393index 40e4469..1ab536e 100644
30394--- a/arch/x86/platform/efi/efi_32.c
30395+++ b/arch/x86/platform/efi/efi_32.c
30396@@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
30397 {
30398 struct desc_ptr gdt_descr;
30399
30400+#ifdef CONFIG_PAX_KERNEXEC
30401+ struct desc_struct d;
30402+#endif
30403+
30404 local_irq_save(efi_rt_eflags);
30405
30406 load_cr3(initial_page_table);
30407 __flush_tlb_all();
30408
30409+#ifdef CONFIG_PAX_KERNEXEC
30410+ pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
30411+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30412+ pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
30413+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30414+#endif
30415+
30416 gdt_descr.address = __pa(get_cpu_gdt_table(0));
30417 gdt_descr.size = GDT_SIZE - 1;
30418 load_gdt(&gdt_descr);
30419@@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
30420 {
30421 struct desc_ptr gdt_descr;
30422
30423+#ifdef CONFIG_PAX_KERNEXEC
30424+ struct desc_struct d;
30425+
30426+ memset(&d, 0, sizeof d);
30427+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
30428+ write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
30429+#endif
30430+
30431 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
30432 gdt_descr.size = GDT_SIZE - 1;
30433 load_gdt(&gdt_descr);
30434diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
30435index fbe66e6..eae5e38 100644
30436--- a/arch/x86/platform/efi/efi_stub_32.S
30437+++ b/arch/x86/platform/efi/efi_stub_32.S
30438@@ -6,7 +6,9 @@
30439 */
30440
30441 #include <linux/linkage.h>
30442+#include <linux/init.h>
30443 #include <asm/page_types.h>
30444+#include <asm/segment.h>
30445
30446 /*
30447 * efi_call_phys(void *, ...) is a function with variable parameters.
30448@@ -20,7 +22,7 @@
30449 * service functions will comply with gcc calling convention, too.
30450 */
30451
30452-.text
30453+__INIT
30454 ENTRY(efi_call_phys)
30455 /*
30456 * 0. The function can only be called in Linux kernel. So CS has been
30457@@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
30458 * The mapping of lower virtual memory has been created in prelog and
30459 * epilog.
30460 */
30461- movl $1f, %edx
30462- subl $__PAGE_OFFSET, %edx
30463- jmp *%edx
30464+#ifdef CONFIG_PAX_KERNEXEC
30465+ movl $(__KERNEXEC_EFI_DS), %edx
30466+ mov %edx, %ds
30467+ mov %edx, %es
30468+ mov %edx, %ss
30469+ addl $2f,(1f)
30470+ ljmp *(1f)
30471+
30472+__INITDATA
30473+1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
30474+.previous
30475+
30476+2:
30477+ subl $2b,(1b)
30478+#else
30479+ jmp 1f-__PAGE_OFFSET
30480 1:
30481+#endif
30482
30483 /*
30484 * 2. Now on the top of stack is the return
30485@@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
30486 * parameter 2, ..., param n. To make things easy, we save the return
30487 * address of efi_call_phys in a global variable.
30488 */
30489- popl %edx
30490- movl %edx, saved_return_addr
30491- /* get the function pointer into ECX*/
30492- popl %ecx
30493- movl %ecx, efi_rt_function_ptr
30494- movl $2f, %edx
30495- subl $__PAGE_OFFSET, %edx
30496- pushl %edx
30497+ popl (saved_return_addr)
30498+ popl (efi_rt_function_ptr)
30499
30500 /*
30501 * 3. Clear PG bit in %CR0.
30502@@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
30503 /*
30504 * 5. Call the physical function.
30505 */
30506- jmp *%ecx
30507+ call *(efi_rt_function_ptr-__PAGE_OFFSET)
30508
30509-2:
30510 /*
30511 * 6. After EFI runtime service returns, control will return to
30512 * following instruction. We'd better readjust stack pointer first.
30513@@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
30514 movl %cr0, %edx
30515 orl $0x80000000, %edx
30516 movl %edx, %cr0
30517- jmp 1f
30518-1:
30519+
30520 /*
30521 * 8. Now restore the virtual mode from flat mode by
30522 * adding EIP with PAGE_OFFSET.
30523 */
30524- movl $1f, %edx
30525- jmp *%edx
30526+#ifdef CONFIG_PAX_KERNEXEC
30527+ movl $(__KERNEL_DS), %edx
30528+ mov %edx, %ds
30529+ mov %edx, %es
30530+ mov %edx, %ss
30531+ ljmp $(__KERNEL_CS),$1f
30532+#else
30533+ jmp 1f+__PAGE_OFFSET
30534+#endif
30535 1:
30536
30537 /*
30538 * 9. Balance the stack. And because EAX contain the return value,
30539 * we'd better not clobber it.
30540 */
30541- leal efi_rt_function_ptr, %edx
30542- movl (%edx), %ecx
30543- pushl %ecx
30544+ pushl (efi_rt_function_ptr)
30545
30546 /*
30547- * 10. Push the saved return address onto the stack and return.
30548+ * 10. Return to the saved return address.
30549 */
30550- leal saved_return_addr, %edx
30551- movl (%edx), %ecx
30552- pushl %ecx
30553- ret
30554+ jmpl *(saved_return_addr)
30555 ENDPROC(efi_call_phys)
30556 .previous
30557
30558-.data
30559+__INITDATA
30560 saved_return_addr:
30561 .long 0
30562 efi_rt_function_ptr:
30563diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
30564index 4c07cca..2c8427d 100644
30565--- a/arch/x86/platform/efi/efi_stub_64.S
30566+++ b/arch/x86/platform/efi/efi_stub_64.S
30567@@ -7,6 +7,7 @@
30568 */
30569
30570 #include <linux/linkage.h>
30571+#include <asm/alternative-asm.h>
30572
30573 #define SAVE_XMM \
30574 mov %rsp, %rax; \
30575@@ -40,6 +41,7 @@ ENTRY(efi_call0)
30576 call *%rdi
30577 addq $32, %rsp
30578 RESTORE_XMM
30579+ pax_force_retaddr 0, 1
30580 ret
30581 ENDPROC(efi_call0)
30582
30583@@ -50,6 +52,7 @@ ENTRY(efi_call1)
30584 call *%rdi
30585 addq $32, %rsp
30586 RESTORE_XMM
30587+ pax_force_retaddr 0, 1
30588 ret
30589 ENDPROC(efi_call1)
30590
30591@@ -60,6 +63,7 @@ ENTRY(efi_call2)
30592 call *%rdi
30593 addq $32, %rsp
30594 RESTORE_XMM
30595+ pax_force_retaddr 0, 1
30596 ret
30597 ENDPROC(efi_call2)
30598
30599@@ -71,6 +75,7 @@ ENTRY(efi_call3)
30600 call *%rdi
30601 addq $32, %rsp
30602 RESTORE_XMM
30603+ pax_force_retaddr 0, 1
30604 ret
30605 ENDPROC(efi_call3)
30606
30607@@ -83,6 +88,7 @@ ENTRY(efi_call4)
30608 call *%rdi
30609 addq $32, %rsp
30610 RESTORE_XMM
30611+ pax_force_retaddr 0, 1
30612 ret
30613 ENDPROC(efi_call4)
30614
30615@@ -96,6 +102,7 @@ ENTRY(efi_call5)
30616 call *%rdi
30617 addq $48, %rsp
30618 RESTORE_XMM
30619+ pax_force_retaddr 0, 1
30620 ret
30621 ENDPROC(efi_call5)
30622
30623@@ -112,5 +119,6 @@ ENTRY(efi_call6)
30624 call *%rdi
30625 addq $48, %rsp
30626 RESTORE_XMM
30627+ pax_force_retaddr 0, 1
30628 ret
30629 ENDPROC(efi_call6)
30630diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
30631index e31bcd8..f12dc46 100644
30632--- a/arch/x86/platform/mrst/mrst.c
30633+++ b/arch/x86/platform/mrst/mrst.c
30634@@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
30635 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
30636 int sfi_mrtc_num;
30637
30638-static void mrst_power_off(void)
30639+static __noreturn void mrst_power_off(void)
30640 {
30641+ BUG();
30642 }
30643
30644-static void mrst_reboot(void)
30645+static __noreturn void mrst_reboot(void)
30646 {
30647 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
30648+ BUG();
30649 }
30650
30651 /* parse all the mtimer info to a static mtimer array */
30652diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
30653index d6ee929..3637cb5 100644
30654--- a/arch/x86/platform/olpc/olpc_dt.c
30655+++ b/arch/x86/platform/olpc/olpc_dt.c
30656@@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
30657 return res;
30658 }
30659
30660-static struct of_pdt_ops prom_olpc_ops __initdata = {
30661+static struct of_pdt_ops prom_olpc_ops __initconst = {
30662 .nextprop = olpc_dt_nextprop,
30663 .getproplen = olpc_dt_getproplen,
30664 .getproperty = olpc_dt_getproperty,
30665diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
30666index 3c68768..07e82b8 100644
30667--- a/arch/x86/power/cpu.c
30668+++ b/arch/x86/power/cpu.c
30669@@ -134,7 +134,7 @@ static void do_fpu_end(void)
30670 static void fix_processor_context(void)
30671 {
30672 int cpu = smp_processor_id();
30673- struct tss_struct *t = &per_cpu(init_tss, cpu);
30674+ struct tss_struct *t = init_tss + cpu;
30675
30676 set_tss_desc(cpu, t); /*
30677 * This just modifies memory; should not be
30678@@ -144,8 +144,6 @@ static void fix_processor_context(void)
30679 */
30680
30681 #ifdef CONFIG_X86_64
30682- get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
30683-
30684 syscall_init(); /* This sets MSR_*STAR and related */
30685 #endif
30686 load_TR_desc(); /* This does ltr */
30687diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
30688index a44f457..9140171 100644
30689--- a/arch/x86/realmode/init.c
30690+++ b/arch/x86/realmode/init.c
30691@@ -70,7 +70,13 @@ void __init setup_real_mode(void)
30692 __va(real_mode_header->trampoline_header);
30693
30694 #ifdef CONFIG_X86_32
30695- trampoline_header->start = __pa_symbol(startup_32_smp);
30696+ trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
30697+
30698+#ifdef CONFIG_PAX_KERNEXEC
30699+ trampoline_header->start -= LOAD_PHYSICAL_ADDR;
30700+#endif
30701+
30702+ trampoline_header->boot_cs = __BOOT_CS;
30703 trampoline_header->gdt_limit = __BOOT_DS + 7;
30704 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
30705 #else
30706@@ -86,7 +92,7 @@ void __init setup_real_mode(void)
30707 *trampoline_cr4_features = read_cr4();
30708
30709 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
30710- trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
30711+ trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
30712 trampoline_pgd[511] = init_level4_pgt[511].pgd;
30713 #endif
30714 }
30715diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
30716index 8869287..d577672 100644
30717--- a/arch/x86/realmode/rm/Makefile
30718+++ b/arch/x86/realmode/rm/Makefile
30719@@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
30720 $(call cc-option, -fno-unit-at-a-time)) \
30721 $(call cc-option, -fno-stack-protector) \
30722 $(call cc-option, -mpreferred-stack-boundary=2)
30723+ifdef CONSTIFY_PLUGIN
30724+KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
30725+endif
30726 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
30727 GCOV_PROFILE := n
30728diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
30729index a28221d..93c40f1 100644
30730--- a/arch/x86/realmode/rm/header.S
30731+++ b/arch/x86/realmode/rm/header.S
30732@@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
30733 #endif
30734 /* APM/BIOS reboot */
30735 .long pa_machine_real_restart_asm
30736-#ifdef CONFIG_X86_64
30737+#ifdef CONFIG_X86_32
30738+ .long __KERNEL_CS
30739+#else
30740 .long __KERNEL32_CS
30741 #endif
30742 END(real_mode_header)
30743diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
30744index c1b2791..f9e31c7 100644
30745--- a/arch/x86/realmode/rm/trampoline_32.S
30746+++ b/arch/x86/realmode/rm/trampoline_32.S
30747@@ -25,6 +25,12 @@
30748 #include <asm/page_types.h>
30749 #include "realmode.h"
30750
30751+#ifdef CONFIG_PAX_KERNEXEC
30752+#define ta(X) (X)
30753+#else
30754+#define ta(X) (pa_ ## X)
30755+#endif
30756+
30757 .text
30758 .code16
30759
30760@@ -39,8 +45,6 @@ ENTRY(trampoline_start)
30761
30762 cli # We should be safe anyway
30763
30764- movl tr_start, %eax # where we need to go
30765-
30766 movl $0xA5A5A5A5, trampoline_status
30767 # write marker for master knows we're running
30768
30769@@ -56,7 +60,7 @@ ENTRY(trampoline_start)
30770 movw $1, %dx # protected mode (PE) bit
30771 lmsw %dx # into protected mode
30772
30773- ljmpl $__BOOT_CS, $pa_startup_32
30774+ ljmpl *(trampoline_header)
30775
30776 .section ".text32","ax"
30777 .code32
30778@@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
30779 .balign 8
30780 GLOBAL(trampoline_header)
30781 tr_start: .space 4
30782- tr_gdt_pad: .space 2
30783+ tr_boot_cs: .space 2
30784 tr_gdt: .space 6
30785 END(trampoline_header)
30786
30787diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
30788index bb360dc..3e5945f 100644
30789--- a/arch/x86/realmode/rm/trampoline_64.S
30790+++ b/arch/x86/realmode/rm/trampoline_64.S
30791@@ -107,7 +107,7 @@ ENTRY(startup_32)
30792 wrmsr
30793
30794 # Enable paging and in turn activate Long Mode
30795- movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
30796+ movl $(X86_CR0_PG | X86_CR0_PE), %eax
30797 movl %eax, %cr0
30798
30799 /*
30800diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
30801index 79d67bd..c7e1b90 100644
30802--- a/arch/x86/tools/relocs.c
30803+++ b/arch/x86/tools/relocs.c
30804@@ -12,10 +12,13 @@
30805 #include <regex.h>
30806 #include <tools/le_byteshift.h>
30807
30808+#include "../../../include/generated/autoconf.h"
30809+
30810 static void die(char *fmt, ...);
30811
30812 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
30813 static Elf32_Ehdr ehdr;
30814+static Elf32_Phdr *phdr;
30815 static unsigned long reloc_count, reloc_idx;
30816 static unsigned long *relocs;
30817 static unsigned long reloc16_count, reloc16_idx;
30818@@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
30819 }
30820 }
30821
30822+static void read_phdrs(FILE *fp)
30823+{
30824+ unsigned int i;
30825+
30826+ phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
30827+ if (!phdr) {
30828+ die("Unable to allocate %d program headers\n",
30829+ ehdr.e_phnum);
30830+ }
30831+ if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
30832+ die("Seek to %d failed: %s\n",
30833+ ehdr.e_phoff, strerror(errno));
30834+ }
30835+ if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
30836+ die("Cannot read ELF program headers: %s\n",
30837+ strerror(errno));
30838+ }
30839+ for(i = 0; i < ehdr.e_phnum; i++) {
30840+ phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
30841+ phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
30842+ phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
30843+ phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
30844+ phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
30845+ phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
30846+ phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
30847+ phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
30848+ }
30849+
30850+}
30851+
30852 static void read_shdrs(FILE *fp)
30853 {
30854- int i;
30855+ unsigned int i;
30856 Elf32_Shdr shdr;
30857
30858 secs = calloc(ehdr.e_shnum, sizeof(struct section));
30859@@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
30860
30861 static void read_strtabs(FILE *fp)
30862 {
30863- int i;
30864+ unsigned int i;
30865 for (i = 0; i < ehdr.e_shnum; i++) {
30866 struct section *sec = &secs[i];
30867 if (sec->shdr.sh_type != SHT_STRTAB) {
30868@@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
30869
30870 static void read_symtabs(FILE *fp)
30871 {
30872- int i,j;
30873+ unsigned int i,j;
30874 for (i = 0; i < ehdr.e_shnum; i++) {
30875 struct section *sec = &secs[i];
30876 if (sec->shdr.sh_type != SHT_SYMTAB) {
30877@@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
30878 }
30879
30880
30881-static void read_relocs(FILE *fp)
30882+static void read_relocs(FILE *fp, int use_real_mode)
30883 {
30884- int i,j;
30885+ unsigned int i,j;
30886+ uint32_t base;
30887+
30888 for (i = 0; i < ehdr.e_shnum; i++) {
30889 struct section *sec = &secs[i];
30890 if (sec->shdr.sh_type != SHT_REL) {
30891@@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
30892 die("Cannot read symbol table: %s\n",
30893 strerror(errno));
30894 }
30895+ base = 0;
30896+
30897+#ifdef CONFIG_X86_32
30898+ for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
30899+ if (phdr[j].p_type != PT_LOAD )
30900+ continue;
30901+ 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)
30902+ continue;
30903+ base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
30904+ break;
30905+ }
30906+#endif
30907+
30908 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
30909 Elf32_Rel *rel = &sec->reltab[j];
30910- rel->r_offset = elf32_to_cpu(rel->r_offset);
30911+ rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
30912 rel->r_info = elf32_to_cpu(rel->r_info);
30913 }
30914 }
30915@@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
30916
30917 static void print_absolute_symbols(void)
30918 {
30919- int i;
30920+ unsigned int i;
30921 printf("Absolute symbols\n");
30922 printf(" Num: Value Size Type Bind Visibility Name\n");
30923 for (i = 0; i < ehdr.e_shnum; i++) {
30924 struct section *sec = &secs[i];
30925 char *sym_strtab;
30926- int j;
30927+ unsigned int j;
30928
30929 if (sec->shdr.sh_type != SHT_SYMTAB) {
30930 continue;
30931@@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
30932
30933 static void print_absolute_relocs(void)
30934 {
30935- int i, printed = 0;
30936+ unsigned int i, printed = 0;
30937
30938 for (i = 0; i < ehdr.e_shnum; i++) {
30939 struct section *sec = &secs[i];
30940 struct section *sec_applies, *sec_symtab;
30941 char *sym_strtab;
30942 Elf32_Sym *sh_symtab;
30943- int j;
30944+ unsigned int j;
30945 if (sec->shdr.sh_type != SHT_REL) {
30946 continue;
30947 }
30948@@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
30949 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30950 int use_real_mode)
30951 {
30952- int i;
30953+ unsigned int i;
30954 /* Walk through the relocations */
30955 for (i = 0; i < ehdr.e_shnum; i++) {
30956 char *sym_strtab;
30957 Elf32_Sym *sh_symtab;
30958 struct section *sec_applies, *sec_symtab;
30959- int j;
30960+ unsigned int j;
30961 struct section *sec = &secs[i];
30962
30963 if (sec->shdr.sh_type != SHT_REL) {
30964@@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
30965 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
30966 r_type = ELF32_R_TYPE(rel->r_info);
30967
30968+ if (!use_real_mode) {
30969+ /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
30970+ if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
30971+ continue;
30972+
30973+#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
30974+ /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
30975+ if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
30976+ continue;
30977+ if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
30978+ continue;
30979+ if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
30980+ continue;
30981+ if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
30982+ continue;
30983+#endif
30984+ }
30985+
30986 shn_abs = sym->st_shndx == SHN_ABS;
30987
30988 switch (r_type) {
30989@@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
30990
30991 static void emit_relocs(int as_text, int use_real_mode)
30992 {
30993- int i;
30994+ unsigned int i;
30995 /* Count how many relocations I have and allocate space for them. */
30996 reloc_count = 0;
30997 walk_relocs(count_reloc, use_real_mode);
30998@@ -808,10 +874,11 @@ int main(int argc, char **argv)
30999 fname, strerror(errno));
31000 }
31001 read_ehdr(fp);
31002+ read_phdrs(fp);
31003 read_shdrs(fp);
31004 read_strtabs(fp);
31005 read_symtabs(fp);
31006- read_relocs(fp);
31007+ read_relocs(fp, use_real_mode);
31008 if (show_absolute_syms) {
31009 print_absolute_symbols();
31010 goto out;
31011diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
31012index fd14be1..e3c79c0 100644
31013--- a/arch/x86/vdso/Makefile
31014+++ b/arch/x86/vdso/Makefile
31015@@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
31016 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
31017 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
31018
31019-VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31020+VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
31021 GCOV_PROFILE := n
31022
31023 #
31024diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
31025index 0faad64..39ef157 100644
31026--- a/arch/x86/vdso/vdso32-setup.c
31027+++ b/arch/x86/vdso/vdso32-setup.c
31028@@ -25,6 +25,7 @@
31029 #include <asm/tlbflush.h>
31030 #include <asm/vdso.h>
31031 #include <asm/proto.h>
31032+#include <asm/mman.h>
31033
31034 enum {
31035 VDSO_DISABLED = 0,
31036@@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
31037 void enable_sep_cpu(void)
31038 {
31039 int cpu = get_cpu();
31040- struct tss_struct *tss = &per_cpu(init_tss, cpu);
31041+ struct tss_struct *tss = init_tss + cpu;
31042
31043 if (!boot_cpu_has(X86_FEATURE_SEP)) {
31044 put_cpu();
31045@@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
31046 gate_vma.vm_start = FIXADDR_USER_START;
31047 gate_vma.vm_end = FIXADDR_USER_END;
31048 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
31049- gate_vma.vm_page_prot = __P101;
31050+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
31051
31052 return 0;
31053 }
31054@@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31055 if (compat)
31056 addr = VDSO_HIGH_BASE;
31057 else {
31058- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
31059+ addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
31060 if (IS_ERR_VALUE(addr)) {
31061 ret = addr;
31062 goto up_fail;
31063 }
31064 }
31065
31066- current->mm->context.vdso = (void *)addr;
31067+ current->mm->context.vdso = addr;
31068
31069 if (compat_uses_vma || !compat) {
31070 /*
31071@@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31072 }
31073
31074 current_thread_info()->sysenter_return =
31075- VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31076+ (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
31077
31078 up_fail:
31079 if (ret)
31080- current->mm->context.vdso = NULL;
31081+ current->mm->context.vdso = 0;
31082
31083 up_write(&mm->mmap_sem);
31084
31085@@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
31086
31087 const char *arch_vma_name(struct vm_area_struct *vma)
31088 {
31089- if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
31090+ if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
31091 return "[vdso]";
31092+
31093+#ifdef CONFIG_PAX_SEGMEXEC
31094+ if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
31095+ return "[vdso]";
31096+#endif
31097+
31098 return NULL;
31099 }
31100
31101@@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
31102 * Check to see if the corresponding task was created in compat vdso
31103 * mode.
31104 */
31105- if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
31106+ if (mm && mm->context.vdso == VDSO_HIGH_BASE)
31107 return &gate_vma;
31108 return NULL;
31109 }
31110diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
31111index 431e875..cbb23f3 100644
31112--- a/arch/x86/vdso/vma.c
31113+++ b/arch/x86/vdso/vma.c
31114@@ -16,8 +16,6 @@
31115 #include <asm/vdso.h>
31116 #include <asm/page.h>
31117
31118-unsigned int __read_mostly vdso_enabled = 1;
31119-
31120 extern char vdso_start[], vdso_end[];
31121 extern unsigned short vdso_sync_cpuid;
31122
31123@@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
31124 * unaligned here as a result of stack start randomization.
31125 */
31126 addr = PAGE_ALIGN(addr);
31127- addr = align_vdso_addr(addr);
31128
31129 return addr;
31130 }
31131@@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
31132 unsigned size)
31133 {
31134 struct mm_struct *mm = current->mm;
31135- unsigned long addr;
31136+ unsigned long addr = 0;
31137 int ret;
31138
31139- if (!vdso_enabled)
31140- return 0;
31141-
31142 down_write(&mm->mmap_sem);
31143+
31144+#ifdef CONFIG_PAX_RANDMMAP
31145+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31146+#endif
31147+
31148 addr = vdso_addr(mm->start_stack, size);
31149+ addr = align_vdso_addr(addr);
31150 addr = get_unmapped_area(NULL, addr, size, 0, 0);
31151 if (IS_ERR_VALUE(addr)) {
31152 ret = addr;
31153 goto up_fail;
31154 }
31155
31156- current->mm->context.vdso = (void *)addr;
31157+ mm->context.vdso = addr;
31158
31159 ret = install_special_mapping(mm, addr, size,
31160 VM_READ|VM_EXEC|
31161 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
31162 pages);
31163- if (ret) {
31164- current->mm->context.vdso = NULL;
31165- goto up_fail;
31166- }
31167+ if (ret)
31168+ mm->context.vdso = 0;
31169
31170 up_fail:
31171 up_write(&mm->mmap_sem);
31172@@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
31173 vdsox32_size);
31174 }
31175 #endif
31176-
31177-static __init int vdso_setup(char *s)
31178-{
31179- vdso_enabled = simple_strtoul(s, NULL, 0);
31180- return 0;
31181-}
31182-__setup("vdso=", vdso_setup);
31183diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
31184index cf95e19..17e9f50 100644
31185--- a/arch/x86/xen/enlighten.c
31186+++ b/arch/x86/xen/enlighten.c
31187@@ -100,8 +100,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
31188
31189 struct shared_info xen_dummy_shared_info;
31190
31191-void *xen_initial_gdt;
31192-
31193 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
31194 __read_mostly int xen_have_vector_callback;
31195 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
31196@@ -511,8 +509,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
31197 {
31198 unsigned long va = dtr->address;
31199 unsigned int size = dtr->size + 1;
31200- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31201- unsigned long frames[pages];
31202+ unsigned long frames[65536 / PAGE_SIZE];
31203 int f;
31204
31205 /*
31206@@ -560,8 +557,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31207 {
31208 unsigned long va = dtr->address;
31209 unsigned int size = dtr->size + 1;
31210- unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
31211- unsigned long frames[pages];
31212+ unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
31213 int f;
31214
31215 /*
31216@@ -569,7 +565,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
31217 * 8-byte entries, or 16 4k pages..
31218 */
31219
31220- BUG_ON(size > 65536);
31221+ BUG_ON(size > GDT_SIZE);
31222 BUG_ON(va & ~PAGE_MASK);
31223
31224 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
31225@@ -954,7 +950,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
31226 return 0;
31227 }
31228
31229-static void set_xen_basic_apic_ops(void)
31230+static void __init set_xen_basic_apic_ops(void)
31231 {
31232 apic->read = xen_apic_read;
31233 apic->write = xen_apic_write;
31234@@ -1260,30 +1256,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
31235 #endif
31236 };
31237
31238-static void xen_reboot(int reason)
31239+static __noreturn void xen_reboot(int reason)
31240 {
31241 struct sched_shutdown r = { .reason = reason };
31242
31243- if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
31244- BUG();
31245+ HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
31246+ BUG();
31247 }
31248
31249-static void xen_restart(char *msg)
31250+static __noreturn void xen_restart(char *msg)
31251 {
31252 xen_reboot(SHUTDOWN_reboot);
31253 }
31254
31255-static void xen_emergency_restart(void)
31256+static __noreturn void xen_emergency_restart(void)
31257 {
31258 xen_reboot(SHUTDOWN_reboot);
31259 }
31260
31261-static void xen_machine_halt(void)
31262+static __noreturn void xen_machine_halt(void)
31263 {
31264 xen_reboot(SHUTDOWN_poweroff);
31265 }
31266
31267-static void xen_machine_power_off(void)
31268+static __noreturn void xen_machine_power_off(void)
31269 {
31270 if (pm_power_off)
31271 pm_power_off();
31272@@ -1385,7 +1381,17 @@ asmlinkage void __init xen_start_kernel(void)
31273 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
31274
31275 /* Work out if we support NX */
31276- x86_configure_nx();
31277+#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
31278+ if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
31279+ (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
31280+ unsigned l, h;
31281+
31282+ __supported_pte_mask |= _PAGE_NX;
31283+ rdmsr(MSR_EFER, l, h);
31284+ l |= EFER_NX;
31285+ wrmsr(MSR_EFER, l, h);
31286+ }
31287+#endif
31288
31289 xen_setup_features();
31290
31291@@ -1416,13 +1422,6 @@ asmlinkage void __init xen_start_kernel(void)
31292
31293 machine_ops = xen_machine_ops;
31294
31295- /*
31296- * The only reliable way to retain the initial address of the
31297- * percpu gdt_page is to remember it here, so we can go and
31298- * mark it RW later, when the initial percpu area is freed.
31299- */
31300- xen_initial_gdt = &per_cpu(gdt_page, 0);
31301-
31302 xen_smp_init();
31303
31304 #ifdef CONFIG_ACPI_NUMA
31305@@ -1616,7 +1615,7 @@ static int __cpuinit xen_hvm_cpu_notify(struct notifier_block *self,
31306 return NOTIFY_OK;
31307 }
31308
31309-static struct notifier_block xen_hvm_cpu_notifier __cpuinitdata = {
31310+static struct notifier_block xen_hvm_cpu_notifier = {
31311 .notifier_call = xen_hvm_cpu_notify,
31312 };
31313
31314diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
31315index e006c18..b9a7d6c 100644
31316--- a/arch/x86/xen/mmu.c
31317+++ b/arch/x86/xen/mmu.c
31318@@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31319 /* L3_k[510] -> level2_kernel_pgt
31320 * L3_i[511] -> level2_fixmap_pgt */
31321 convert_pfn_mfn(level3_kernel_pgt);
31322+ convert_pfn_mfn(level3_vmalloc_start_pgt);
31323+ convert_pfn_mfn(level3_vmalloc_end_pgt);
31324+ convert_pfn_mfn(level3_vmemmap_pgt);
31325
31326 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
31327 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
31328@@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
31329 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
31330 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
31331 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
31332+ set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
31333+ set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
31334+ set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
31335 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
31336 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
31337+ set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
31338 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
31339 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
31340
31341@@ -2110,6 +2117,7 @@ static void __init xen_post_allocator_init(void)
31342 pv_mmu_ops.set_pud = xen_set_pud;
31343 #if PAGETABLE_LEVELS == 4
31344 pv_mmu_ops.set_pgd = xen_set_pgd;
31345+ pv_mmu_ops.set_pgd_batched = xen_set_pgd;
31346 #endif
31347
31348 /* This will work as long as patching hasn't happened yet
31349@@ -2188,6 +2196,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
31350 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
31351 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
31352 .set_pgd = xen_set_pgd_hyper,
31353+ .set_pgd_batched = xen_set_pgd_hyper,
31354
31355 .alloc_pud = xen_alloc_pmd_init,
31356 .release_pud = xen_release_pmd_init,
31357diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
31358index 96c4e85..284fded 100644
31359--- a/arch/x86/xen/smp.c
31360+++ b/arch/x86/xen/smp.c
31361@@ -230,11 +230,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
31362 {
31363 BUG_ON(smp_processor_id() != 0);
31364 native_smp_prepare_boot_cpu();
31365-
31366- /* We've switched to the "real" per-cpu gdt, so make sure the
31367- old memory can be recycled */
31368- make_lowmem_page_readwrite(xen_initial_gdt);
31369-
31370 xen_filter_cpu_maps();
31371 xen_setup_vcpu_info_placement();
31372 }
31373@@ -304,7 +299,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31374 ctxt->user_regs.ss = __KERNEL_DS;
31375 #ifdef CONFIG_X86_32
31376 ctxt->user_regs.fs = __KERNEL_PERCPU;
31377- ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
31378+ savesegment(gs, ctxt->user_regs.gs);
31379 #else
31380 ctxt->gs_base_kernel = per_cpu_offset(cpu);
31381 #endif
31382@@ -314,8 +309,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
31383
31384 {
31385 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
31386- ctxt->user_regs.ds = __USER_DS;
31387- ctxt->user_regs.es = __USER_DS;
31388+ ctxt->user_regs.ds = __KERNEL_DS;
31389+ ctxt->user_regs.es = __KERNEL_DS;
31390
31391 xen_copy_trap_info(ctxt->trap_ctxt);
31392
31393@@ -360,13 +355,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
31394 int rc;
31395
31396 per_cpu(current_task, cpu) = idle;
31397+ per_cpu(current_tinfo, cpu) = &idle->tinfo;
31398 #ifdef CONFIG_X86_32
31399 irq_ctx_init(cpu);
31400 #else
31401 clear_tsk_thread_flag(idle, TIF_FORK);
31402- per_cpu(kernel_stack, cpu) =
31403- (unsigned long)task_stack_page(idle) -
31404- KERNEL_STACK_OFFSET + THREAD_SIZE;
31405+ per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
31406 #endif
31407 xen_setup_runstate_info(cpu);
31408 xen_setup_timer(cpu);
31409@@ -642,7 +636,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
31410
31411 void __init xen_smp_init(void)
31412 {
31413- smp_ops = xen_smp_ops;
31414+ memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
31415 xen_fill_possible_map();
31416 xen_init_spinlocks();
31417 }
31418diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
31419index 33ca6e4..0ded929 100644
31420--- a/arch/x86/xen/xen-asm_32.S
31421+++ b/arch/x86/xen/xen-asm_32.S
31422@@ -84,14 +84,14 @@ ENTRY(xen_iret)
31423 ESP_OFFSET=4 # bytes pushed onto stack
31424
31425 /*
31426- * Store vcpu_info pointer for easy access. Do it this way to
31427- * avoid having to reload %fs
31428+ * Store vcpu_info pointer for easy access.
31429 */
31430 #ifdef CONFIG_SMP
31431- GET_THREAD_INFO(%eax)
31432- movl %ss:TI_cpu(%eax), %eax
31433- movl %ss:__per_cpu_offset(,%eax,4), %eax
31434- mov %ss:xen_vcpu(%eax), %eax
31435+ push %fs
31436+ mov $(__KERNEL_PERCPU), %eax
31437+ mov %eax, %fs
31438+ mov PER_CPU_VAR(xen_vcpu), %eax
31439+ pop %fs
31440 #else
31441 movl %ss:xen_vcpu, %eax
31442 #endif
31443diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
31444index 7faed58..ba4427c 100644
31445--- a/arch/x86/xen/xen-head.S
31446+++ b/arch/x86/xen/xen-head.S
31447@@ -19,6 +19,17 @@ ENTRY(startup_xen)
31448 #ifdef CONFIG_X86_32
31449 mov %esi,xen_start_info
31450 mov $init_thread_union+THREAD_SIZE,%esp
31451+#ifdef CONFIG_SMP
31452+ movl $cpu_gdt_table,%edi
31453+ movl $__per_cpu_load,%eax
31454+ movw %ax,__KERNEL_PERCPU + 2(%edi)
31455+ rorl $16,%eax
31456+ movb %al,__KERNEL_PERCPU + 4(%edi)
31457+ movb %ah,__KERNEL_PERCPU + 7(%edi)
31458+ movl $__per_cpu_end - 1,%eax
31459+ subl $__per_cpu_start,%eax
31460+ movw %ax,__KERNEL_PERCPU + 0(%edi)
31461+#endif
31462 #else
31463 mov %rsi,xen_start_info
31464 mov $init_thread_union+THREAD_SIZE,%rsp
31465diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
31466index a95b417..b6dbd0b 100644
31467--- a/arch/x86/xen/xen-ops.h
31468+++ b/arch/x86/xen/xen-ops.h
31469@@ -10,8 +10,6 @@
31470 extern const char xen_hypervisor_callback[];
31471 extern const char xen_failsafe_callback[];
31472
31473-extern void *xen_initial_gdt;
31474-
31475 struct trap_info;
31476 void xen_copy_trap_info(struct trap_info *traps);
31477
31478diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
31479index 525bd3d..ef888b1 100644
31480--- a/arch/xtensa/variants/dc232b/include/variant/core.h
31481+++ b/arch/xtensa/variants/dc232b/include/variant/core.h
31482@@ -119,9 +119,9 @@
31483 ----------------------------------------------------------------------*/
31484
31485 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
31486-#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
31487 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
31488 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
31489+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31490
31491 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
31492 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
31493diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
31494index 2f33760..835e50a 100644
31495--- a/arch/xtensa/variants/fsf/include/variant/core.h
31496+++ b/arch/xtensa/variants/fsf/include/variant/core.h
31497@@ -11,6 +11,7 @@
31498 #ifndef _XTENSA_CORE_H
31499 #define _XTENSA_CORE_H
31500
31501+#include <linux/const.h>
31502
31503 /****************************************************************************
31504 Parameters Useful for Any Code, USER or PRIVILEGED
31505@@ -112,9 +113,9 @@
31506 ----------------------------------------------------------------------*/
31507
31508 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31509-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31510 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31511 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31512+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31513
31514 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
31515 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
31516diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
31517index af00795..2bb8105 100644
31518--- a/arch/xtensa/variants/s6000/include/variant/core.h
31519+++ b/arch/xtensa/variants/s6000/include/variant/core.h
31520@@ -11,6 +11,7 @@
31521 #ifndef _XTENSA_CORE_CONFIGURATION_H
31522 #define _XTENSA_CORE_CONFIGURATION_H
31523
31524+#include <linux/const.h>
31525
31526 /****************************************************************************
31527 Parameters Useful for Any Code, USER or PRIVILEGED
31528@@ -118,9 +119,9 @@
31529 ----------------------------------------------------------------------*/
31530
31531 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
31532-#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
31533 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
31534 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
31535+#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
31536
31537 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
31538 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
31539diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
31540index 58916af..eb9dbcf6 100644
31541--- a/block/blk-iopoll.c
31542+++ b/block/blk-iopoll.c
31543@@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
31544 }
31545 EXPORT_SYMBOL(blk_iopoll_complete);
31546
31547-static void blk_iopoll_softirq(struct softirq_action *h)
31548+static void blk_iopoll_softirq(void)
31549 {
31550 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
31551 int rearm = 0, budget = blk_iopoll_budget;
31552@@ -209,7 +209,7 @@ static int __cpuinit blk_iopoll_cpu_notify(struct notifier_block *self,
31553 return NOTIFY_OK;
31554 }
31555
31556-static struct notifier_block __cpuinitdata blk_iopoll_cpu_notifier = {
31557+static struct notifier_block blk_iopoll_cpu_notifier = {
31558 .notifier_call = blk_iopoll_cpu_notify,
31559 };
31560
31561diff --git a/block/blk-map.c b/block/blk-map.c
31562index 623e1cd..ca1e109 100644
31563--- a/block/blk-map.c
31564+++ b/block/blk-map.c
31565@@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
31566 if (!len || !kbuf)
31567 return -EINVAL;
31568
31569- do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
31570+ do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
31571 if (do_copy)
31572 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
31573 else
31574diff --git a/block/blk-softirq.c b/block/blk-softirq.c
31575index 467c8de..f3628c5 100644
31576--- a/block/blk-softirq.c
31577+++ b/block/blk-softirq.c
31578@@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
31579 * Softirq action handler - move entries to local list and loop over them
31580 * while passing them to the queue registered handler.
31581 */
31582-static void blk_done_softirq(struct softirq_action *h)
31583+static void blk_done_softirq(void)
31584 {
31585 struct list_head *cpu_list, local_list;
31586
31587@@ -98,7 +98,7 @@ static int __cpuinit blk_cpu_notify(struct notifier_block *self,
31588 return NOTIFY_OK;
31589 }
31590
31591-static struct notifier_block __cpuinitdata blk_cpu_notifier = {
31592+static struct notifier_block blk_cpu_notifier = {
31593 .notifier_call = blk_cpu_notify,
31594 };
31595
31596diff --git a/block/bsg.c b/block/bsg.c
31597index 420a5a9..23834aa 100644
31598--- a/block/bsg.c
31599+++ b/block/bsg.c
31600@@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
31601 struct sg_io_v4 *hdr, struct bsg_device *bd,
31602 fmode_t has_write_perm)
31603 {
31604+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31605+ unsigned char *cmdptr;
31606+
31607 if (hdr->request_len > BLK_MAX_CDB) {
31608 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
31609 if (!rq->cmd)
31610 return -ENOMEM;
31611- }
31612+ cmdptr = rq->cmd;
31613+ } else
31614+ cmdptr = tmpcmd;
31615
31616- if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
31617+ if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
31618 hdr->request_len))
31619 return -EFAULT;
31620
31621+ if (cmdptr != rq->cmd)
31622+ memcpy(rq->cmd, cmdptr, hdr->request_len);
31623+
31624 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
31625 if (blk_verify_command(rq->cmd, has_write_perm))
31626 return -EPERM;
31627diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
31628index 7c668c8..db3521c 100644
31629--- a/block/compat_ioctl.c
31630+++ b/block/compat_ioctl.c
31631@@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
31632 err |= __get_user(f->spec1, &uf->spec1);
31633 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
31634 err |= __get_user(name, &uf->name);
31635- f->name = compat_ptr(name);
31636+ f->name = (void __force_kernel *)compat_ptr(name);
31637 if (err) {
31638 err = -EFAULT;
31639 goto out;
31640diff --git a/block/genhd.c b/block/genhd.c
31641index 3c001fb..d15a9e8 100644
31642--- a/block/genhd.c
31643+++ b/block/genhd.c
31644@@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
31645
31646 /*
31647 * Register device numbers dev..(dev+range-1)
31648- * range must be nonzero
31649+ * Noop if @range is zero.
31650 * The hash chain is sorted on range, so that subranges can override.
31651 */
31652 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
31653 struct kobject *(*probe)(dev_t, int *, void *),
31654 int (*lock)(dev_t, void *), void *data)
31655 {
31656- kobj_map(bdev_map, devt, range, module, probe, lock, data);
31657+ if (range)
31658+ kobj_map(bdev_map, devt, range, module, probe, lock, data);
31659 }
31660
31661 EXPORT_SYMBOL(blk_register_region);
31662
31663+/* undo blk_register_region(), noop if @range is zero */
31664 void blk_unregister_region(dev_t devt, unsigned long range)
31665 {
31666- kobj_unmap(bdev_map, devt, range);
31667+ if (range)
31668+ kobj_unmap(bdev_map, devt, range);
31669 }
31670
31671 EXPORT_SYMBOL(blk_unregister_region);
31672@@ -512,7 +515,7 @@ static void register_disk(struct gendisk *disk)
31673
31674 ddev->parent = disk->driverfs_dev;
31675
31676- dev_set_name(ddev, disk->disk_name);
31677+ dev_set_name(ddev, "%s", disk->disk_name);
31678
31679 /* delay uevents, until we scanned partition table */
31680 dev_set_uevent_suppress(ddev, 1);
31681diff --git a/block/partitions/efi.c b/block/partitions/efi.c
31682index ff5804e..a88acad 100644
31683--- a/block/partitions/efi.c
31684+++ b/block/partitions/efi.c
31685@@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
31686 if (!gpt)
31687 return NULL;
31688
31689+ if (!le32_to_cpu(gpt->num_partition_entries))
31690+ return NULL;
31691+ pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
31692+ if (!pte)
31693+ return NULL;
31694+
31695 count = le32_to_cpu(gpt->num_partition_entries) *
31696 le32_to_cpu(gpt->sizeof_partition_entry);
31697- if (!count)
31698- return NULL;
31699- pte = kzalloc(count, GFP_KERNEL);
31700- if (!pte)
31701- return NULL;
31702-
31703 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
31704 (u8 *) pte,
31705 count) < count) {
31706diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
31707index 9a87daa..fb17486 100644
31708--- a/block/scsi_ioctl.c
31709+++ b/block/scsi_ioctl.c
31710@@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
31711 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
31712 struct sg_io_hdr *hdr, fmode_t mode)
31713 {
31714- if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
31715+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31716+ unsigned char *cmdptr;
31717+
31718+ if (rq->cmd != rq->__cmd)
31719+ cmdptr = rq->cmd;
31720+ else
31721+ cmdptr = tmpcmd;
31722+
31723+ if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
31724 return -EFAULT;
31725+
31726+ if (cmdptr != rq->cmd)
31727+ memcpy(rq->cmd, cmdptr, hdr->cmd_len);
31728+
31729 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
31730 return -EPERM;
31731
31732@@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31733 int err;
31734 unsigned int in_len, out_len, bytes, opcode, cmdlen;
31735 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
31736+ unsigned char tmpcmd[sizeof(rq->__cmd)];
31737+ unsigned char *cmdptr;
31738
31739 if (!sic)
31740 return -EINVAL;
31741@@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
31742 */
31743 err = -EFAULT;
31744 rq->cmd_len = cmdlen;
31745- if (copy_from_user(rq->cmd, sic->data, cmdlen))
31746+
31747+ if (rq->cmd != rq->__cmd)
31748+ cmdptr = rq->cmd;
31749+ else
31750+ cmdptr = tmpcmd;
31751+
31752+ if (copy_from_user(cmdptr, sic->data, cmdlen))
31753 goto error;
31754
31755+ if (rq->cmd != cmdptr)
31756+ memcpy(rq->cmd, cmdptr, cmdlen);
31757+
31758 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
31759 goto error;
31760
31761diff --git a/crypto/algapi.c b/crypto/algapi.c
31762index 6149a6e..55ed50d 100644
31763--- a/crypto/algapi.c
31764+++ b/crypto/algapi.c
31765@@ -495,7 +495,7 @@ static struct crypto_template *__crypto_lookup_template(const char *name)
31766
31767 struct crypto_template *crypto_lookup_template(const char *name)
31768 {
31769- return try_then_request_module(__crypto_lookup_template(name), name);
31770+ return try_then_request_module(__crypto_lookup_template(name), "%s", name);
31771 }
31772 EXPORT_SYMBOL_GPL(crypto_lookup_template);
31773
31774diff --git a/crypto/cryptd.c b/crypto/cryptd.c
31775index 7bdd61b..afec999 100644
31776--- a/crypto/cryptd.c
31777+++ b/crypto/cryptd.c
31778@@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
31779
31780 struct cryptd_blkcipher_request_ctx {
31781 crypto_completion_t complete;
31782-};
31783+} __no_const;
31784
31785 struct cryptd_hash_ctx {
31786 struct crypto_shash *child;
31787@@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
31788
31789 struct cryptd_aead_request_ctx {
31790 crypto_completion_t complete;
31791-};
31792+} __no_const;
31793
31794 static void cryptd_queue_worker(struct work_struct *work);
31795
31796diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
31797index b2c99dc..476c9fb 100644
31798--- a/crypto/pcrypt.c
31799+++ b/crypto/pcrypt.c
31800@@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
31801 int ret;
31802
31803 pinst->kobj.kset = pcrypt_kset;
31804- ret = kobject_add(&pinst->kobj, NULL, name);
31805+ ret = kobject_add(&pinst->kobj, NULL, "%s", name);
31806 if (!ret)
31807 kobject_uevent(&pinst->kobj, KOBJ_ADD);
31808
31809@@ -455,8 +455,8 @@ static int pcrypt_init_padata(struct padata_pcrypt *pcrypt,
31810
31811 get_online_cpus();
31812
31813- pcrypt->wq = alloc_workqueue(name,
31814- WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1);
31815+ pcrypt->wq = alloc_workqueue("%s",
31816+ WQ_MEM_RECLAIM | WQ_CPU_INTENSIVE, 1, name);
31817 if (!pcrypt->wq)
31818 goto err;
31819
31820diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
31821index f220d64..d359ad6 100644
31822--- a/drivers/acpi/apei/apei-internal.h
31823+++ b/drivers/acpi/apei/apei-internal.h
31824@@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
31825 struct apei_exec_ins_type {
31826 u32 flags;
31827 apei_exec_ins_func_t run;
31828-};
31829+} __do_const;
31830
31831 struct apei_exec_context {
31832 u32 ip;
31833diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
31834index fefc2ca..12a535d 100644
31835--- a/drivers/acpi/apei/cper.c
31836+++ b/drivers/acpi/apei/cper.c
31837@@ -39,12 +39,12 @@
31838 */
31839 u64 cper_next_record_id(void)
31840 {
31841- static atomic64_t seq;
31842+ static atomic64_unchecked_t seq;
31843
31844- if (!atomic64_read(&seq))
31845- atomic64_set(&seq, ((u64)get_seconds()) << 32);
31846+ if (!atomic64_read_unchecked(&seq))
31847+ atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
31848
31849- return atomic64_inc_return(&seq);
31850+ return atomic64_inc_return_unchecked(&seq);
31851 }
31852 EXPORT_SYMBOL_GPL(cper_next_record_id);
31853
31854diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
31855index be60399..778b33e8 100644
31856--- a/drivers/acpi/bgrt.c
31857+++ b/drivers/acpi/bgrt.c
31858@@ -87,8 +87,10 @@ static int __init bgrt_init(void)
31859 return -ENODEV;
31860
31861 sysfs_bin_attr_init(&image_attr);
31862- image_attr.private = bgrt_image;
31863- image_attr.size = bgrt_image_size;
31864+ pax_open_kernel();
31865+ *(void **)&image_attr.private = bgrt_image;
31866+ *(size_t *)&image_attr.size = bgrt_image_size;
31867+ pax_close_kernel();
31868
31869 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
31870 if (!bgrt_kobj)
31871diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
31872index cb96296..b81293b 100644
31873--- a/drivers/acpi/blacklist.c
31874+++ b/drivers/acpi/blacklist.c
31875@@ -52,7 +52,7 @@ struct acpi_blacklist_item {
31876 u32 is_critical_error;
31877 };
31878
31879-static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
31880+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
31881
31882 /*
31883 * POLICY: If *anything* doesn't work, put it on the blacklist.
31884@@ -193,7 +193,7 @@ static int __init dmi_disable_osi_win7(const struct dmi_system_id *d)
31885 return 0;
31886 }
31887
31888-static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
31889+static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
31890 {
31891 .callback = dmi_disable_osi_vista,
31892 .ident = "Fujitsu Siemens",
31893diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
31894index 7586544..636a2f0 100644
31895--- a/drivers/acpi/ec_sys.c
31896+++ b/drivers/acpi/ec_sys.c
31897@@ -12,6 +12,7 @@
31898 #include <linux/acpi.h>
31899 #include <linux/debugfs.h>
31900 #include <linux/module.h>
31901+#include <linux/uaccess.h>
31902 #include "internal.h"
31903
31904 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
31905@@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31906 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
31907 */
31908 unsigned int size = EC_SPACE_SIZE;
31909- u8 *data = (u8 *) buf;
31910+ u8 data;
31911 loff_t init_off = *off;
31912 int err = 0;
31913
31914@@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
31915 size = count;
31916
31917 while (size) {
31918- err = ec_read(*off, &data[*off - init_off]);
31919+ err = ec_read(*off, &data);
31920 if (err)
31921 return err;
31922+ if (put_user(data, &buf[*off - init_off]))
31923+ return -EFAULT;
31924 *off += 1;
31925 size--;
31926 }
31927@@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31928
31929 unsigned int size = count;
31930 loff_t init_off = *off;
31931- u8 *data = (u8 *) buf;
31932 int err = 0;
31933
31934 if (*off >= EC_SPACE_SIZE)
31935@@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
31936 }
31937
31938 while (size) {
31939- u8 byte_write = data[*off - init_off];
31940+ u8 byte_write;
31941+ if (get_user(byte_write, &buf[*off - init_off]))
31942+ return -EFAULT;
31943 err = ec_write(*off, byte_write);
31944 if (err)
31945 return err;
31946diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
31947index ee255c6..747c68b 100644
31948--- a/drivers/acpi/processor_idle.c
31949+++ b/drivers/acpi/processor_idle.c
31950@@ -986,7 +986,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
31951 {
31952 int i, count = CPUIDLE_DRIVER_STATE_START;
31953 struct acpi_processor_cx *cx;
31954- struct cpuidle_state *state;
31955+ cpuidle_state_no_const *state;
31956 struct cpuidle_driver *drv = &acpi_idle_driver;
31957
31958 if (!pr->flags.power_setup_done)
31959diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
31960index 41c0504..f8c0836 100644
31961--- a/drivers/acpi/sysfs.c
31962+++ b/drivers/acpi/sysfs.c
31963@@ -420,11 +420,11 @@ static u32 num_counters;
31964 static struct attribute **all_attrs;
31965 static u32 acpi_gpe_count;
31966
31967-static struct attribute_group interrupt_stats_attr_group = {
31968+static attribute_group_no_const interrupt_stats_attr_group = {
31969 .name = "interrupts",
31970 };
31971
31972-static struct kobj_attribute *counter_attrs;
31973+static kobj_attribute_no_const *counter_attrs;
31974
31975 static void delete_gpe_attr_array(void)
31976 {
31977diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
31978index 34c8216..f56c828 100644
31979--- a/drivers/ata/libahci.c
31980+++ b/drivers/ata/libahci.c
31981@@ -1230,7 +1230,7 @@ int ahci_kick_engine(struct ata_port *ap)
31982 }
31983 EXPORT_SYMBOL_GPL(ahci_kick_engine);
31984
31985-static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31986+static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
31987 struct ata_taskfile *tf, int is_cmd, u16 flags,
31988 unsigned long timeout_msec)
31989 {
31990diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
31991index cf15aee..e0b7078 100644
31992--- a/drivers/ata/libata-core.c
31993+++ b/drivers/ata/libata-core.c
31994@@ -4792,7 +4792,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
31995 struct ata_port *ap;
31996 unsigned int tag;
31997
31998- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
31999+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32000 ap = qc->ap;
32001
32002 qc->flags = 0;
32003@@ -4808,7 +4808,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
32004 struct ata_port *ap;
32005 struct ata_link *link;
32006
32007- WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32008+ BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
32009 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
32010 ap = qc->ap;
32011 link = qc->dev->link;
32012@@ -5926,6 +5926,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32013 return;
32014
32015 spin_lock(&lock);
32016+ pax_open_kernel();
32017
32018 for (cur = ops->inherits; cur; cur = cur->inherits) {
32019 void **inherit = (void **)cur;
32020@@ -5939,8 +5940,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
32021 if (IS_ERR(*pp))
32022 *pp = NULL;
32023
32024- ops->inherits = NULL;
32025+ *(struct ata_port_operations **)&ops->inherits = NULL;
32026
32027+ pax_close_kernel();
32028 spin_unlock(&lock);
32029 }
32030
32031diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
32032index 405022d..fb70e53 100644
32033--- a/drivers/ata/pata_arasan_cf.c
32034+++ b/drivers/ata/pata_arasan_cf.c
32035@@ -864,7 +864,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
32036 /* Handle platform specific quirks */
32037 if (pdata->quirk) {
32038 if (pdata->quirk & CF_BROKEN_PIO) {
32039- ap->ops->set_piomode = NULL;
32040+ pax_open_kernel();
32041+ *(void **)&ap->ops->set_piomode = NULL;
32042+ pax_close_kernel();
32043 ap->pio_mask = 0;
32044 }
32045 if (pdata->quirk & CF_BROKEN_MWDMA)
32046diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
32047index f9b983a..887b9d8 100644
32048--- a/drivers/atm/adummy.c
32049+++ b/drivers/atm/adummy.c
32050@@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
32051 vcc->pop(vcc, skb);
32052 else
32053 dev_kfree_skb_any(skb);
32054- atomic_inc(&vcc->stats->tx);
32055+ atomic_inc_unchecked(&vcc->stats->tx);
32056
32057 return 0;
32058 }
32059diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
32060index 77a7480d..05cde58 100644
32061--- a/drivers/atm/ambassador.c
32062+++ b/drivers/atm/ambassador.c
32063@@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
32064 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
32065
32066 // VC layer stats
32067- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32068+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32069
32070 // free the descriptor
32071 kfree (tx_descr);
32072@@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32073 dump_skb ("<<<", vc, skb);
32074
32075 // VC layer stats
32076- atomic_inc(&atm_vcc->stats->rx);
32077+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32078 __net_timestamp(skb);
32079 // end of our responsibility
32080 atm_vcc->push (atm_vcc, skb);
32081@@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
32082 } else {
32083 PRINTK (KERN_INFO, "dropped over-size frame");
32084 // should we count this?
32085- atomic_inc(&atm_vcc->stats->rx_drop);
32086+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32087 }
32088
32089 } else {
32090@@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
32091 }
32092
32093 if (check_area (skb->data, skb->len)) {
32094- atomic_inc(&atm_vcc->stats->tx_err);
32095+ atomic_inc_unchecked(&atm_vcc->stats->tx_err);
32096 return -ENOMEM; // ?
32097 }
32098
32099diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
32100index 0e3f8f9..765a7a5 100644
32101--- a/drivers/atm/atmtcp.c
32102+++ b/drivers/atm/atmtcp.c
32103@@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32104 if (vcc->pop) vcc->pop(vcc,skb);
32105 else dev_kfree_skb(skb);
32106 if (dev_data) return 0;
32107- atomic_inc(&vcc->stats->tx_err);
32108+ atomic_inc_unchecked(&vcc->stats->tx_err);
32109 return -ENOLINK;
32110 }
32111 size = skb->len+sizeof(struct atmtcp_hdr);
32112@@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32113 if (!new_skb) {
32114 if (vcc->pop) vcc->pop(vcc,skb);
32115 else dev_kfree_skb(skb);
32116- atomic_inc(&vcc->stats->tx_err);
32117+ atomic_inc_unchecked(&vcc->stats->tx_err);
32118 return -ENOBUFS;
32119 }
32120 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
32121@@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
32122 if (vcc->pop) vcc->pop(vcc,skb);
32123 else dev_kfree_skb(skb);
32124 out_vcc->push(out_vcc,new_skb);
32125- atomic_inc(&vcc->stats->tx);
32126- atomic_inc(&out_vcc->stats->rx);
32127+ atomic_inc_unchecked(&vcc->stats->tx);
32128+ atomic_inc_unchecked(&out_vcc->stats->rx);
32129 return 0;
32130 }
32131
32132@@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32133 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
32134 read_unlock(&vcc_sklist_lock);
32135 if (!out_vcc) {
32136- atomic_inc(&vcc->stats->tx_err);
32137+ atomic_inc_unchecked(&vcc->stats->tx_err);
32138 goto done;
32139 }
32140 skb_pull(skb,sizeof(struct atmtcp_hdr));
32141@@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
32142 __net_timestamp(new_skb);
32143 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
32144 out_vcc->push(out_vcc,new_skb);
32145- atomic_inc(&vcc->stats->tx);
32146- atomic_inc(&out_vcc->stats->rx);
32147+ atomic_inc_unchecked(&vcc->stats->tx);
32148+ atomic_inc_unchecked(&out_vcc->stats->rx);
32149 done:
32150 if (vcc->pop) vcc->pop(vcc,skb);
32151 else dev_kfree_skb(skb);
32152diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
32153index b1955ba..b179940 100644
32154--- a/drivers/atm/eni.c
32155+++ b/drivers/atm/eni.c
32156@@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
32157 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
32158 vcc->dev->number);
32159 length = 0;
32160- atomic_inc(&vcc->stats->rx_err);
32161+ atomic_inc_unchecked(&vcc->stats->rx_err);
32162 }
32163 else {
32164 length = ATM_CELL_SIZE-1; /* no HEC */
32165@@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32166 size);
32167 }
32168 eff = length = 0;
32169- atomic_inc(&vcc->stats->rx_err);
32170+ atomic_inc_unchecked(&vcc->stats->rx_err);
32171 }
32172 else {
32173 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
32174@@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
32175 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
32176 vcc->dev->number,vcc->vci,length,size << 2,descr);
32177 length = eff = 0;
32178- atomic_inc(&vcc->stats->rx_err);
32179+ atomic_inc_unchecked(&vcc->stats->rx_err);
32180 }
32181 }
32182 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
32183@@ -767,7 +767,7 @@ rx_dequeued++;
32184 vcc->push(vcc,skb);
32185 pushed++;
32186 }
32187- atomic_inc(&vcc->stats->rx);
32188+ atomic_inc_unchecked(&vcc->stats->rx);
32189 }
32190 wake_up(&eni_dev->rx_wait);
32191 }
32192@@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
32193 PCI_DMA_TODEVICE);
32194 if (vcc->pop) vcc->pop(vcc,skb);
32195 else dev_kfree_skb_irq(skb);
32196- atomic_inc(&vcc->stats->tx);
32197+ atomic_inc_unchecked(&vcc->stats->tx);
32198 wake_up(&eni_dev->tx_wait);
32199 dma_complete++;
32200 }
32201diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
32202index b41c948..a002b17 100644
32203--- a/drivers/atm/firestream.c
32204+++ b/drivers/atm/firestream.c
32205@@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
32206 }
32207 }
32208
32209- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32210+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32211
32212 fs_dprintk (FS_DEBUG_TXMEM, "i");
32213 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
32214@@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32215 #endif
32216 skb_put (skb, qe->p1 & 0xffff);
32217 ATM_SKB(skb)->vcc = atm_vcc;
32218- atomic_inc(&atm_vcc->stats->rx);
32219+ atomic_inc_unchecked(&atm_vcc->stats->rx);
32220 __net_timestamp(skb);
32221 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
32222 atm_vcc->push (atm_vcc, skb);
32223@@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
32224 kfree (pe);
32225 }
32226 if (atm_vcc)
32227- atomic_inc(&atm_vcc->stats->rx_drop);
32228+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32229 break;
32230 case 0x1f: /* Reassembly abort: no buffers. */
32231 /* Silently increment error counter. */
32232 if (atm_vcc)
32233- atomic_inc(&atm_vcc->stats->rx_drop);
32234+ atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
32235 break;
32236 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
32237 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
32238diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
32239index 204814e..cede831 100644
32240--- a/drivers/atm/fore200e.c
32241+++ b/drivers/atm/fore200e.c
32242@@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
32243 #endif
32244 /* check error condition */
32245 if (*entry->status & STATUS_ERROR)
32246- atomic_inc(&vcc->stats->tx_err);
32247+ atomic_inc_unchecked(&vcc->stats->tx_err);
32248 else
32249- atomic_inc(&vcc->stats->tx);
32250+ atomic_inc_unchecked(&vcc->stats->tx);
32251 }
32252 }
32253
32254@@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32255 if (skb == NULL) {
32256 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
32257
32258- atomic_inc(&vcc->stats->rx_drop);
32259+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32260 return -ENOMEM;
32261 }
32262
32263@@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
32264
32265 dev_kfree_skb_any(skb);
32266
32267- atomic_inc(&vcc->stats->rx_drop);
32268+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32269 return -ENOMEM;
32270 }
32271
32272 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32273
32274 vcc->push(vcc, skb);
32275- atomic_inc(&vcc->stats->rx);
32276+ atomic_inc_unchecked(&vcc->stats->rx);
32277
32278 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
32279
32280@@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
32281 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
32282 fore200e->atm_dev->number,
32283 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
32284- atomic_inc(&vcc->stats->rx_err);
32285+ atomic_inc_unchecked(&vcc->stats->rx_err);
32286 }
32287 }
32288
32289@@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
32290 goto retry_here;
32291 }
32292
32293- atomic_inc(&vcc->stats->tx_err);
32294+ atomic_inc_unchecked(&vcc->stats->tx_err);
32295
32296 fore200e->tx_sat++;
32297 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
32298diff --git a/drivers/atm/he.c b/drivers/atm/he.c
32299index d689126..e78e412 100644
32300--- a/drivers/atm/he.c
32301+++ b/drivers/atm/he.c
32302@@ -1698,7 +1698,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32303
32304 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
32305 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
32306- atomic_inc(&vcc->stats->rx_drop);
32307+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32308 goto return_host_buffers;
32309 }
32310
32311@@ -1725,7 +1725,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32312 RBRQ_LEN_ERR(he_dev->rbrq_head)
32313 ? "LEN_ERR" : "",
32314 vcc->vpi, vcc->vci);
32315- atomic_inc(&vcc->stats->rx_err);
32316+ atomic_inc_unchecked(&vcc->stats->rx_err);
32317 goto return_host_buffers;
32318 }
32319
32320@@ -1777,7 +1777,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
32321 vcc->push(vcc, skb);
32322 spin_lock(&he_dev->global_lock);
32323
32324- atomic_inc(&vcc->stats->rx);
32325+ atomic_inc_unchecked(&vcc->stats->rx);
32326
32327 return_host_buffers:
32328 ++pdus_assembled;
32329@@ -2103,7 +2103,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
32330 tpd->vcc->pop(tpd->vcc, tpd->skb);
32331 else
32332 dev_kfree_skb_any(tpd->skb);
32333- atomic_inc(&tpd->vcc->stats->tx_err);
32334+ atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
32335 }
32336 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
32337 return;
32338@@ -2515,7 +2515,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32339 vcc->pop(vcc, skb);
32340 else
32341 dev_kfree_skb_any(skb);
32342- atomic_inc(&vcc->stats->tx_err);
32343+ atomic_inc_unchecked(&vcc->stats->tx_err);
32344 return -EINVAL;
32345 }
32346
32347@@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32348 vcc->pop(vcc, skb);
32349 else
32350 dev_kfree_skb_any(skb);
32351- atomic_inc(&vcc->stats->tx_err);
32352+ atomic_inc_unchecked(&vcc->stats->tx_err);
32353 return -EINVAL;
32354 }
32355 #endif
32356@@ -2538,7 +2538,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32357 vcc->pop(vcc, skb);
32358 else
32359 dev_kfree_skb_any(skb);
32360- atomic_inc(&vcc->stats->tx_err);
32361+ atomic_inc_unchecked(&vcc->stats->tx_err);
32362 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32363 return -ENOMEM;
32364 }
32365@@ -2580,7 +2580,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32366 vcc->pop(vcc, skb);
32367 else
32368 dev_kfree_skb_any(skb);
32369- atomic_inc(&vcc->stats->tx_err);
32370+ atomic_inc_unchecked(&vcc->stats->tx_err);
32371 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32372 return -ENOMEM;
32373 }
32374@@ -2611,7 +2611,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
32375 __enqueue_tpd(he_dev, tpd, cid);
32376 spin_unlock_irqrestore(&he_dev->global_lock, flags);
32377
32378- atomic_inc(&vcc->stats->tx);
32379+ atomic_inc_unchecked(&vcc->stats->tx);
32380
32381 return 0;
32382 }
32383diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
32384index 1dc0519..1aadaf7 100644
32385--- a/drivers/atm/horizon.c
32386+++ b/drivers/atm/horizon.c
32387@@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
32388 {
32389 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
32390 // VC layer stats
32391- atomic_inc(&vcc->stats->rx);
32392+ atomic_inc_unchecked(&vcc->stats->rx);
32393 __net_timestamp(skb);
32394 // end of our responsibility
32395 vcc->push (vcc, skb);
32396@@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
32397 dev->tx_iovec = NULL;
32398
32399 // VC layer stats
32400- atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
32401+ atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
32402
32403 // free the skb
32404 hrz_kfree_skb (skb);
32405diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
32406index 272f009..a18ba55 100644
32407--- a/drivers/atm/idt77252.c
32408+++ b/drivers/atm/idt77252.c
32409@@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
32410 else
32411 dev_kfree_skb(skb);
32412
32413- atomic_inc(&vcc->stats->tx);
32414+ atomic_inc_unchecked(&vcc->stats->tx);
32415 }
32416
32417 atomic_dec(&scq->used);
32418@@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32419 if ((sb = dev_alloc_skb(64)) == NULL) {
32420 printk("%s: Can't allocate buffers for aal0.\n",
32421 card->name);
32422- atomic_add(i, &vcc->stats->rx_drop);
32423+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32424 break;
32425 }
32426 if (!atm_charge(vcc, sb->truesize)) {
32427 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
32428 card->name);
32429- atomic_add(i - 1, &vcc->stats->rx_drop);
32430+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
32431 dev_kfree_skb(sb);
32432 break;
32433 }
32434@@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32435 ATM_SKB(sb)->vcc = vcc;
32436 __net_timestamp(sb);
32437 vcc->push(vcc, sb);
32438- atomic_inc(&vcc->stats->rx);
32439+ atomic_inc_unchecked(&vcc->stats->rx);
32440
32441 cell += ATM_CELL_PAYLOAD;
32442 }
32443@@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32444 "(CDC: %08x)\n",
32445 card->name, len, rpp->len, readl(SAR_REG_CDC));
32446 recycle_rx_pool_skb(card, rpp);
32447- atomic_inc(&vcc->stats->rx_err);
32448+ atomic_inc_unchecked(&vcc->stats->rx_err);
32449 return;
32450 }
32451 if (stat & SAR_RSQE_CRC) {
32452 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
32453 recycle_rx_pool_skb(card, rpp);
32454- atomic_inc(&vcc->stats->rx_err);
32455+ atomic_inc_unchecked(&vcc->stats->rx_err);
32456 return;
32457 }
32458 if (skb_queue_len(&rpp->queue) > 1) {
32459@@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32460 RXPRINTK("%s: Can't alloc RX skb.\n",
32461 card->name);
32462 recycle_rx_pool_skb(card, rpp);
32463- atomic_inc(&vcc->stats->rx_err);
32464+ atomic_inc_unchecked(&vcc->stats->rx_err);
32465 return;
32466 }
32467 if (!atm_charge(vcc, skb->truesize)) {
32468@@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32469 __net_timestamp(skb);
32470
32471 vcc->push(vcc, skb);
32472- atomic_inc(&vcc->stats->rx);
32473+ atomic_inc_unchecked(&vcc->stats->rx);
32474
32475 return;
32476 }
32477@@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
32478 __net_timestamp(skb);
32479
32480 vcc->push(vcc, skb);
32481- atomic_inc(&vcc->stats->rx);
32482+ atomic_inc_unchecked(&vcc->stats->rx);
32483
32484 if (skb->truesize > SAR_FB_SIZE_3)
32485 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
32486@@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
32487 if (vcc->qos.aal != ATM_AAL0) {
32488 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
32489 card->name, vpi, vci);
32490- atomic_inc(&vcc->stats->rx_drop);
32491+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32492 goto drop;
32493 }
32494
32495 if ((sb = dev_alloc_skb(64)) == NULL) {
32496 printk("%s: Can't allocate buffers for AAL0.\n",
32497 card->name);
32498- atomic_inc(&vcc->stats->rx_err);
32499+ atomic_inc_unchecked(&vcc->stats->rx_err);
32500 goto drop;
32501 }
32502
32503@@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
32504 ATM_SKB(sb)->vcc = vcc;
32505 __net_timestamp(sb);
32506 vcc->push(vcc, sb);
32507- atomic_inc(&vcc->stats->rx);
32508+ atomic_inc_unchecked(&vcc->stats->rx);
32509
32510 drop:
32511 skb_pull(queue, 64);
32512@@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32513
32514 if (vc == NULL) {
32515 printk("%s: NULL connection in send().\n", card->name);
32516- atomic_inc(&vcc->stats->tx_err);
32517+ atomic_inc_unchecked(&vcc->stats->tx_err);
32518 dev_kfree_skb(skb);
32519 return -EINVAL;
32520 }
32521 if (!test_bit(VCF_TX, &vc->flags)) {
32522 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
32523- atomic_inc(&vcc->stats->tx_err);
32524+ atomic_inc_unchecked(&vcc->stats->tx_err);
32525 dev_kfree_skb(skb);
32526 return -EINVAL;
32527 }
32528@@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32529 break;
32530 default:
32531 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
32532- atomic_inc(&vcc->stats->tx_err);
32533+ atomic_inc_unchecked(&vcc->stats->tx_err);
32534 dev_kfree_skb(skb);
32535 return -EINVAL;
32536 }
32537
32538 if (skb_shinfo(skb)->nr_frags != 0) {
32539 printk("%s: No scatter-gather yet.\n", card->name);
32540- atomic_inc(&vcc->stats->tx_err);
32541+ atomic_inc_unchecked(&vcc->stats->tx_err);
32542 dev_kfree_skb(skb);
32543 return -EINVAL;
32544 }
32545@@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
32546
32547 err = queue_skb(card, vc, skb, oam);
32548 if (err) {
32549- atomic_inc(&vcc->stats->tx_err);
32550+ atomic_inc_unchecked(&vcc->stats->tx_err);
32551 dev_kfree_skb(skb);
32552 return err;
32553 }
32554@@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
32555 skb = dev_alloc_skb(64);
32556 if (!skb) {
32557 printk("%s: Out of memory in send_oam().\n", card->name);
32558- atomic_inc(&vcc->stats->tx_err);
32559+ atomic_inc_unchecked(&vcc->stats->tx_err);
32560 return -ENOMEM;
32561 }
32562 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
32563diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
32564index 4217f29..88f547a 100644
32565--- a/drivers/atm/iphase.c
32566+++ b/drivers/atm/iphase.c
32567@@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
32568 status = (u_short) (buf_desc_ptr->desc_mode);
32569 if (status & (RX_CER | RX_PTE | RX_OFL))
32570 {
32571- atomic_inc(&vcc->stats->rx_err);
32572+ atomic_inc_unchecked(&vcc->stats->rx_err);
32573 IF_ERR(printk("IA: bad packet, dropping it");)
32574 if (status & RX_CER) {
32575 IF_ERR(printk(" cause: packet CRC error\n");)
32576@@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
32577 len = dma_addr - buf_addr;
32578 if (len > iadev->rx_buf_sz) {
32579 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
32580- atomic_inc(&vcc->stats->rx_err);
32581+ atomic_inc_unchecked(&vcc->stats->rx_err);
32582 goto out_free_desc;
32583 }
32584
32585@@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32586 ia_vcc = INPH_IA_VCC(vcc);
32587 if (ia_vcc == NULL)
32588 {
32589- atomic_inc(&vcc->stats->rx_err);
32590+ atomic_inc_unchecked(&vcc->stats->rx_err);
32591 atm_return(vcc, skb->truesize);
32592 dev_kfree_skb_any(skb);
32593 goto INCR_DLE;
32594@@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32595 if ((length > iadev->rx_buf_sz) || (length >
32596 (skb->len - sizeof(struct cpcs_trailer))))
32597 {
32598- atomic_inc(&vcc->stats->rx_err);
32599+ atomic_inc_unchecked(&vcc->stats->rx_err);
32600 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
32601 length, skb->len);)
32602 atm_return(vcc, skb->truesize);
32603@@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
32604
32605 IF_RX(printk("rx_dle_intr: skb push");)
32606 vcc->push(vcc,skb);
32607- atomic_inc(&vcc->stats->rx);
32608+ atomic_inc_unchecked(&vcc->stats->rx);
32609 iadev->rx_pkt_cnt++;
32610 }
32611 INCR_DLE:
32612@@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
32613 {
32614 struct k_sonet_stats *stats;
32615 stats = &PRIV(_ia_dev[board])->sonet_stats;
32616- printk("section_bip: %d\n", atomic_read(&stats->section_bip));
32617- printk("line_bip : %d\n", atomic_read(&stats->line_bip));
32618- printk("path_bip : %d\n", atomic_read(&stats->path_bip));
32619- printk("line_febe : %d\n", atomic_read(&stats->line_febe));
32620- printk("path_febe : %d\n", atomic_read(&stats->path_febe));
32621- printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
32622- printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
32623- printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
32624- printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
32625+ printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
32626+ printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
32627+ printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
32628+ printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
32629+ printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
32630+ printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
32631+ printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
32632+ printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
32633+ printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
32634 }
32635 ia_cmds.status = 0;
32636 break;
32637@@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32638 if ((desc == 0) || (desc > iadev->num_tx_desc))
32639 {
32640 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
32641- atomic_inc(&vcc->stats->tx);
32642+ atomic_inc_unchecked(&vcc->stats->tx);
32643 if (vcc->pop)
32644 vcc->pop(vcc, skb);
32645 else
32646@@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
32647 ATM_DESC(skb) = vcc->vci;
32648 skb_queue_tail(&iadev->tx_dma_q, skb);
32649
32650- atomic_inc(&vcc->stats->tx);
32651+ atomic_inc_unchecked(&vcc->stats->tx);
32652 iadev->tx_pkt_cnt++;
32653 /* Increment transaction counter */
32654 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
32655
32656 #if 0
32657 /* add flow control logic */
32658- if (atomic_read(&vcc->stats->tx) % 20 == 0) {
32659+ if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
32660 if (iavcc->vc_desc_cnt > 10) {
32661 vcc->tx_quota = vcc->tx_quota * 3 / 4;
32662 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
32663diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
32664index fa7d701..1e404c7 100644
32665--- a/drivers/atm/lanai.c
32666+++ b/drivers/atm/lanai.c
32667@@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
32668 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
32669 lanai_endtx(lanai, lvcc);
32670 lanai_free_skb(lvcc->tx.atmvcc, skb);
32671- atomic_inc(&lvcc->tx.atmvcc->stats->tx);
32672+ atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
32673 }
32674
32675 /* Try to fill the buffer - don't call unless there is backlog */
32676@@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
32677 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
32678 __net_timestamp(skb);
32679 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
32680- atomic_inc(&lvcc->rx.atmvcc->stats->rx);
32681+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
32682 out:
32683 lvcc->rx.buf.ptr = end;
32684 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
32685@@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32686 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
32687 "vcc %d\n", lanai->number, (unsigned int) s, vci);
32688 lanai->stats.service_rxnotaal5++;
32689- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32690+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32691 return 0;
32692 }
32693 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
32694@@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32695 int bytes;
32696 read_unlock(&vcc_sklist_lock);
32697 DPRINTK("got trashed rx pdu on vci %d\n", vci);
32698- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32699+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32700 lvcc->stats.x.aal5.service_trash++;
32701 bytes = (SERVICE_GET_END(s) * 16) -
32702 (((unsigned long) lvcc->rx.buf.ptr) -
32703@@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32704 }
32705 if (s & SERVICE_STREAM) {
32706 read_unlock(&vcc_sklist_lock);
32707- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32708+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32709 lvcc->stats.x.aal5.service_stream++;
32710 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
32711 "PDU on VCI %d!\n", lanai->number, vci);
32712@@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
32713 return 0;
32714 }
32715 DPRINTK("got rx crc error on vci %d\n", vci);
32716- atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
32717+ atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
32718 lvcc->stats.x.aal5.service_rxcrc++;
32719 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
32720 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
32721diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
32722index 6587dc2..149833d 100644
32723--- a/drivers/atm/nicstar.c
32724+++ b/drivers/atm/nicstar.c
32725@@ -1641,7 +1641,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32726 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
32727 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
32728 card->index);
32729- atomic_inc(&vcc->stats->tx_err);
32730+ atomic_inc_unchecked(&vcc->stats->tx_err);
32731 dev_kfree_skb_any(skb);
32732 return -EINVAL;
32733 }
32734@@ -1649,7 +1649,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32735 if (!vc->tx) {
32736 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
32737 card->index);
32738- atomic_inc(&vcc->stats->tx_err);
32739+ atomic_inc_unchecked(&vcc->stats->tx_err);
32740 dev_kfree_skb_any(skb);
32741 return -EINVAL;
32742 }
32743@@ -1657,14 +1657,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32744 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
32745 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
32746 card->index);
32747- atomic_inc(&vcc->stats->tx_err);
32748+ atomic_inc_unchecked(&vcc->stats->tx_err);
32749 dev_kfree_skb_any(skb);
32750 return -EINVAL;
32751 }
32752
32753 if (skb_shinfo(skb)->nr_frags != 0) {
32754 printk("nicstar%d: No scatter-gather yet.\n", card->index);
32755- atomic_inc(&vcc->stats->tx_err);
32756+ atomic_inc_unchecked(&vcc->stats->tx_err);
32757 dev_kfree_skb_any(skb);
32758 return -EINVAL;
32759 }
32760@@ -1712,11 +1712,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
32761 }
32762
32763 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
32764- atomic_inc(&vcc->stats->tx_err);
32765+ atomic_inc_unchecked(&vcc->stats->tx_err);
32766 dev_kfree_skb_any(skb);
32767 return -EIO;
32768 }
32769- atomic_inc(&vcc->stats->tx);
32770+ atomic_inc_unchecked(&vcc->stats->tx);
32771
32772 return 0;
32773 }
32774@@ -2033,14 +2033,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32775 printk
32776 ("nicstar%d: Can't allocate buffers for aal0.\n",
32777 card->index);
32778- atomic_add(i, &vcc->stats->rx_drop);
32779+ atomic_add_unchecked(i, &vcc->stats->rx_drop);
32780 break;
32781 }
32782 if (!atm_charge(vcc, sb->truesize)) {
32783 RXPRINTK
32784 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
32785 card->index);
32786- atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32787+ atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
32788 dev_kfree_skb_any(sb);
32789 break;
32790 }
32791@@ -2055,7 +2055,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32792 ATM_SKB(sb)->vcc = vcc;
32793 __net_timestamp(sb);
32794 vcc->push(vcc, sb);
32795- atomic_inc(&vcc->stats->rx);
32796+ atomic_inc_unchecked(&vcc->stats->rx);
32797 cell += ATM_CELL_PAYLOAD;
32798 }
32799
32800@@ -2072,7 +2072,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32801 if (iovb == NULL) {
32802 printk("nicstar%d: Out of iovec buffers.\n",
32803 card->index);
32804- atomic_inc(&vcc->stats->rx_drop);
32805+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32806 recycle_rx_buf(card, skb);
32807 return;
32808 }
32809@@ -2096,7 +2096,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32810 small or large buffer itself. */
32811 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
32812 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
32813- atomic_inc(&vcc->stats->rx_err);
32814+ atomic_inc_unchecked(&vcc->stats->rx_err);
32815 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32816 NS_MAX_IOVECS);
32817 NS_PRV_IOVCNT(iovb) = 0;
32818@@ -2116,7 +2116,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32819 ("nicstar%d: Expected a small buffer, and this is not one.\n",
32820 card->index);
32821 which_list(card, skb);
32822- atomic_inc(&vcc->stats->rx_err);
32823+ atomic_inc_unchecked(&vcc->stats->rx_err);
32824 recycle_rx_buf(card, skb);
32825 vc->rx_iov = NULL;
32826 recycle_iov_buf(card, iovb);
32827@@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32828 ("nicstar%d: Expected a large buffer, and this is not one.\n",
32829 card->index);
32830 which_list(card, skb);
32831- atomic_inc(&vcc->stats->rx_err);
32832+ atomic_inc_unchecked(&vcc->stats->rx_err);
32833 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32834 NS_PRV_IOVCNT(iovb));
32835 vc->rx_iov = NULL;
32836@@ -2152,7 +2152,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32837 printk(" - PDU size mismatch.\n");
32838 else
32839 printk(".\n");
32840- atomic_inc(&vcc->stats->rx_err);
32841+ atomic_inc_unchecked(&vcc->stats->rx_err);
32842 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
32843 NS_PRV_IOVCNT(iovb));
32844 vc->rx_iov = NULL;
32845@@ -2166,7 +2166,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32846 /* skb points to a small buffer */
32847 if (!atm_charge(vcc, skb->truesize)) {
32848 push_rxbufs(card, skb);
32849- atomic_inc(&vcc->stats->rx_drop);
32850+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32851 } else {
32852 skb_put(skb, len);
32853 dequeue_sm_buf(card, skb);
32854@@ -2176,7 +2176,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32855 ATM_SKB(skb)->vcc = vcc;
32856 __net_timestamp(skb);
32857 vcc->push(vcc, skb);
32858- atomic_inc(&vcc->stats->rx);
32859+ atomic_inc_unchecked(&vcc->stats->rx);
32860 }
32861 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
32862 struct sk_buff *sb;
32863@@ -2187,7 +2187,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32864 if (len <= NS_SMBUFSIZE) {
32865 if (!atm_charge(vcc, sb->truesize)) {
32866 push_rxbufs(card, sb);
32867- atomic_inc(&vcc->stats->rx_drop);
32868+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32869 } else {
32870 skb_put(sb, len);
32871 dequeue_sm_buf(card, sb);
32872@@ -2197,7 +2197,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32873 ATM_SKB(sb)->vcc = vcc;
32874 __net_timestamp(sb);
32875 vcc->push(vcc, sb);
32876- atomic_inc(&vcc->stats->rx);
32877+ atomic_inc_unchecked(&vcc->stats->rx);
32878 }
32879
32880 push_rxbufs(card, skb);
32881@@ -2206,7 +2206,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32882
32883 if (!atm_charge(vcc, skb->truesize)) {
32884 push_rxbufs(card, skb);
32885- atomic_inc(&vcc->stats->rx_drop);
32886+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32887 } else {
32888 dequeue_lg_buf(card, skb);
32889 #ifdef NS_USE_DESTRUCTORS
32890@@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32891 ATM_SKB(skb)->vcc = vcc;
32892 __net_timestamp(skb);
32893 vcc->push(vcc, skb);
32894- atomic_inc(&vcc->stats->rx);
32895+ atomic_inc_unchecked(&vcc->stats->rx);
32896 }
32897
32898 push_rxbufs(card, sb);
32899@@ -2240,7 +2240,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32900 printk
32901 ("nicstar%d: Out of huge buffers.\n",
32902 card->index);
32903- atomic_inc(&vcc->stats->rx_drop);
32904+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32905 recycle_iovec_rx_bufs(card,
32906 (struct iovec *)
32907 iovb->data,
32908@@ -2291,7 +2291,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32909 card->hbpool.count++;
32910 } else
32911 dev_kfree_skb_any(hb);
32912- atomic_inc(&vcc->stats->rx_drop);
32913+ atomic_inc_unchecked(&vcc->stats->rx_drop);
32914 } else {
32915 /* Copy the small buffer to the huge buffer */
32916 sb = (struct sk_buff *)iov->iov_base;
32917@@ -2328,7 +2328,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
32918 #endif /* NS_USE_DESTRUCTORS */
32919 __net_timestamp(hb);
32920 vcc->push(vcc, hb);
32921- atomic_inc(&vcc->stats->rx);
32922+ atomic_inc_unchecked(&vcc->stats->rx);
32923 }
32924 }
32925
32926diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
32927index 32784d1..4a8434a 100644
32928--- a/drivers/atm/solos-pci.c
32929+++ b/drivers/atm/solos-pci.c
32930@@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
32931 }
32932 atm_charge(vcc, skb->truesize);
32933 vcc->push(vcc, skb);
32934- atomic_inc(&vcc->stats->rx);
32935+ atomic_inc_unchecked(&vcc->stats->rx);
32936 break;
32937
32938 case PKT_STATUS:
32939@@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
32940 vcc = SKB_CB(oldskb)->vcc;
32941
32942 if (vcc) {
32943- atomic_inc(&vcc->stats->tx);
32944+ atomic_inc_unchecked(&vcc->stats->tx);
32945 solos_pop(vcc, oldskb);
32946 } else {
32947 dev_kfree_skb_irq(oldskb);
32948diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
32949index 0215934..ce9f5b1 100644
32950--- a/drivers/atm/suni.c
32951+++ b/drivers/atm/suni.c
32952@@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
32953
32954
32955 #define ADD_LIMITED(s,v) \
32956- atomic_add((v),&stats->s); \
32957- if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
32958+ atomic_add_unchecked((v),&stats->s); \
32959+ if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
32960
32961
32962 static void suni_hz(unsigned long from_timer)
32963diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
32964index 5120a96..e2572bd 100644
32965--- a/drivers/atm/uPD98402.c
32966+++ b/drivers/atm/uPD98402.c
32967@@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
32968 struct sonet_stats tmp;
32969 int error = 0;
32970
32971- atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32972+ atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
32973 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
32974 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
32975 if (zero && !error) {
32976@@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
32977
32978
32979 #define ADD_LIMITED(s,v) \
32980- { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
32981- if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
32982- atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32983+ { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
32984+ if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
32985+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
32986
32987
32988 static void stat_event(struct atm_dev *dev)
32989@@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
32990 if (reason & uPD98402_INT_PFM) stat_event(dev);
32991 if (reason & uPD98402_INT_PCO) {
32992 (void) GET(PCOCR); /* clear interrupt cause */
32993- atomic_add(GET(HECCT),
32994+ atomic_add_unchecked(GET(HECCT),
32995 &PRIV(dev)->sonet_stats.uncorr_hcs);
32996 }
32997 if ((reason & uPD98402_INT_RFO) &&
32998@@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
32999 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
33000 uPD98402_INT_LOS),PIMR); /* enable them */
33001 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
33002- atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33003- atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
33004- atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
33005+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
33006+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
33007+ atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
33008 return 0;
33009 }
33010
33011diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
33012index 969c3c2..9b72956 100644
33013--- a/drivers/atm/zatm.c
33014+++ b/drivers/atm/zatm.c
33015@@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33016 }
33017 if (!size) {
33018 dev_kfree_skb_irq(skb);
33019- if (vcc) atomic_inc(&vcc->stats->rx_err);
33020+ if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
33021 continue;
33022 }
33023 if (!atm_charge(vcc,skb->truesize)) {
33024@@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
33025 skb->len = size;
33026 ATM_SKB(skb)->vcc = vcc;
33027 vcc->push(vcc,skb);
33028- atomic_inc(&vcc->stats->rx);
33029+ atomic_inc_unchecked(&vcc->stats->rx);
33030 }
33031 zout(pos & 0xffff,MTA(mbx));
33032 #if 0 /* probably a stupid idea */
33033@@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
33034 skb_queue_head(&zatm_vcc->backlog,skb);
33035 break;
33036 }
33037- atomic_inc(&vcc->stats->tx);
33038+ atomic_inc_unchecked(&vcc->stats->tx);
33039 wake_up(&zatm_vcc->tx_wait);
33040 }
33041
33042diff --git a/drivers/base/attribute_container.c b/drivers/base/attribute_container.c
33043index d78b204..ecc1929 100644
33044--- a/drivers/base/attribute_container.c
33045+++ b/drivers/base/attribute_container.c
33046@@ -167,7 +167,7 @@ attribute_container_add_device(struct device *dev,
33047 ic->classdev.parent = get_device(dev);
33048 ic->classdev.class = cont->class;
33049 cont->class->dev_release = attribute_container_release;
33050- dev_set_name(&ic->classdev, dev_name(dev));
33051+ dev_set_name(&ic->classdev, "%s", dev_name(dev));
33052 if (fn)
33053 fn(cont, dev, &ic->classdev);
33054 else
33055diff --git a/drivers/base/bus.c b/drivers/base/bus.c
33056index 519865b..e540db3 100644
33057--- a/drivers/base/bus.c
33058+++ b/drivers/base/bus.c
33059@@ -1163,7 +1163,7 @@ int subsys_interface_register(struct subsys_interface *sif)
33060 return -EINVAL;
33061
33062 mutex_lock(&subsys->p->mutex);
33063- list_add_tail(&sif->node, &subsys->p->interfaces);
33064+ pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
33065 if (sif->add_dev) {
33066 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33067 while ((dev = subsys_dev_iter_next(&iter)))
33068@@ -1188,7 +1188,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
33069 subsys = sif->subsys;
33070
33071 mutex_lock(&subsys->p->mutex);
33072- list_del_init(&sif->node);
33073+ pax_list_del_init((struct list_head *)&sif->node);
33074 if (sif->remove_dev) {
33075 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
33076 while ((dev = subsys_dev_iter_next(&iter)))
33077diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
33078index 01fc5b0..917801f 100644
33079--- a/drivers/base/devtmpfs.c
33080+++ b/drivers/base/devtmpfs.c
33081@@ -348,7 +348,7 @@ int devtmpfs_mount(const char *mntdir)
33082 if (!thread)
33083 return 0;
33084
33085- err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
33086+ err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
33087 if (err)
33088 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
33089 else
33090@@ -373,11 +373,11 @@ static int devtmpfsd(void *p)
33091 *err = sys_unshare(CLONE_NEWNS);
33092 if (*err)
33093 goto out;
33094- *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
33095+ *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
33096 if (*err)
33097 goto out;
33098- sys_chdir("/.."); /* will traverse into overmounted root */
33099- sys_chroot(".");
33100+ sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
33101+ sys_chroot((char __force_user *)".");
33102 complete(&setup_done);
33103 while (1) {
33104 spin_lock(&req_lock);
33105diff --git a/drivers/base/node.c b/drivers/base/node.c
33106index fac124a..66bd4ab 100644
33107--- a/drivers/base/node.c
33108+++ b/drivers/base/node.c
33109@@ -625,7 +625,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
33110 struct node_attr {
33111 struct device_attribute attr;
33112 enum node_states state;
33113-};
33114+} __do_const;
33115
33116 static ssize_t show_node_state(struct device *dev,
33117 struct device_attribute *attr, char *buf)
33118diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
33119index 9a6b05a..2fc8fb9 100644
33120--- a/drivers/base/power/domain.c
33121+++ b/drivers/base/power/domain.c
33122@@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
33123 {
33124 struct cpuidle_driver *cpuidle_drv;
33125 struct gpd_cpu_data *cpu_data;
33126- struct cpuidle_state *idle_state;
33127+ cpuidle_state_no_const *idle_state;
33128 int ret = 0;
33129
33130 if (IS_ERR_OR_NULL(genpd) || state < 0)
33131@@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
33132 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
33133 {
33134 struct gpd_cpu_data *cpu_data;
33135- struct cpuidle_state *idle_state;
33136+ cpuidle_state_no_const *idle_state;
33137 int ret = 0;
33138
33139 if (IS_ERR_OR_NULL(genpd))
33140diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
33141index a53ebd2..8f73eeb 100644
33142--- a/drivers/base/power/sysfs.c
33143+++ b/drivers/base/power/sysfs.c
33144@@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
33145 return -EIO;
33146 }
33147 }
33148- return sprintf(buf, p);
33149+ return sprintf(buf, "%s", p);
33150 }
33151
33152 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
33153diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
33154index 79715e7..df06b3b 100644
33155--- a/drivers/base/power/wakeup.c
33156+++ b/drivers/base/power/wakeup.c
33157@@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
33158 * They need to be modified together atomically, so it's better to use one
33159 * atomic variable to hold them both.
33160 */
33161-static atomic_t combined_event_count = ATOMIC_INIT(0);
33162+static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
33163
33164 #define IN_PROGRESS_BITS (sizeof(int) * 4)
33165 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
33166
33167 static void split_counters(unsigned int *cnt, unsigned int *inpr)
33168 {
33169- unsigned int comb = atomic_read(&combined_event_count);
33170+ unsigned int comb = atomic_read_unchecked(&combined_event_count);
33171
33172 *cnt = (comb >> IN_PROGRESS_BITS);
33173 *inpr = comb & MAX_IN_PROGRESS;
33174@@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
33175 ws->start_prevent_time = ws->last_time;
33176
33177 /* Increment the counter of events in progress. */
33178- cec = atomic_inc_return(&combined_event_count);
33179+ cec = atomic_inc_return_unchecked(&combined_event_count);
33180
33181 trace_wakeup_source_activate(ws->name, cec);
33182 }
33183@@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
33184 * Increment the counter of registered wakeup events and decrement the
33185 * couter of wakeup events in progress simultaneously.
33186 */
33187- cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
33188+ cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
33189 trace_wakeup_source_deactivate(ws->name, cec);
33190
33191 split_counters(&cnt, &inpr);
33192diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
33193index e8d11b6..7b1b36f 100644
33194--- a/drivers/base/syscore.c
33195+++ b/drivers/base/syscore.c
33196@@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
33197 void register_syscore_ops(struct syscore_ops *ops)
33198 {
33199 mutex_lock(&syscore_ops_lock);
33200- list_add_tail(&ops->node, &syscore_ops_list);
33201+ pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
33202 mutex_unlock(&syscore_ops_lock);
33203 }
33204 EXPORT_SYMBOL_GPL(register_syscore_ops);
33205@@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
33206 void unregister_syscore_ops(struct syscore_ops *ops)
33207 {
33208 mutex_lock(&syscore_ops_lock);
33209- list_del(&ops->node);
33210+ pax_list_del((struct list_head *)&ops->node);
33211 mutex_unlock(&syscore_ops_lock);
33212 }
33213 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
33214diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
33215index dadea48..a1f3835 100644
33216--- a/drivers/block/cciss.c
33217+++ b/drivers/block/cciss.c
33218@@ -1184,6 +1184,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
33219 int err;
33220 u32 cp;
33221
33222+ memset(&arg64, 0, sizeof(arg64));
33223+
33224 err = 0;
33225 err |=
33226 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
33227@@ -3005,7 +3007,7 @@ static void start_io(ctlr_info_t *h)
33228 while (!list_empty(&h->reqQ)) {
33229 c = list_entry(h->reqQ.next, CommandList_struct, list);
33230 /* can't do anything if fifo is full */
33231- if ((h->access.fifo_full(h))) {
33232+ if ((h->access->fifo_full(h))) {
33233 dev_warn(&h->pdev->dev, "fifo full\n");
33234 break;
33235 }
33236@@ -3015,7 +3017,7 @@ static void start_io(ctlr_info_t *h)
33237 h->Qdepth--;
33238
33239 /* Tell the controller execute command */
33240- h->access.submit_command(h, c);
33241+ h->access->submit_command(h, c);
33242
33243 /* Put job onto the completed Q */
33244 addQ(&h->cmpQ, c);
33245@@ -3441,17 +3443,17 @@ startio:
33246
33247 static inline unsigned long get_next_completion(ctlr_info_t *h)
33248 {
33249- return h->access.command_completed(h);
33250+ return h->access->command_completed(h);
33251 }
33252
33253 static inline int interrupt_pending(ctlr_info_t *h)
33254 {
33255- return h->access.intr_pending(h);
33256+ return h->access->intr_pending(h);
33257 }
33258
33259 static inline long interrupt_not_for_us(ctlr_info_t *h)
33260 {
33261- return ((h->access.intr_pending(h) == 0) ||
33262+ return ((h->access->intr_pending(h) == 0) ||
33263 (h->interrupts_enabled == 0));
33264 }
33265
33266@@ -3484,7 +3486,7 @@ static inline u32 next_command(ctlr_info_t *h)
33267 u32 a;
33268
33269 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
33270- return h->access.command_completed(h);
33271+ return h->access->command_completed(h);
33272
33273 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
33274 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
33275@@ -4041,7 +4043,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
33276 trans_support & CFGTBL_Trans_use_short_tags);
33277
33278 /* Change the access methods to the performant access methods */
33279- h->access = SA5_performant_access;
33280+ h->access = &SA5_performant_access;
33281 h->transMethod = CFGTBL_Trans_Performant;
33282
33283 return;
33284@@ -4310,7 +4312,7 @@ static int cciss_pci_init(ctlr_info_t *h)
33285 if (prod_index < 0)
33286 return -ENODEV;
33287 h->product_name = products[prod_index].product_name;
33288- h->access = *(products[prod_index].access);
33289+ h->access = products[prod_index].access;
33290
33291 if (cciss_board_disabled(h)) {
33292 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
33293@@ -5032,7 +5034,7 @@ reinit_after_soft_reset:
33294 }
33295
33296 /* make sure the board interrupts are off */
33297- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33298+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33299 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
33300 if (rc)
33301 goto clean2;
33302@@ -5082,7 +5084,7 @@ reinit_after_soft_reset:
33303 * fake ones to scoop up any residual completions.
33304 */
33305 spin_lock_irqsave(&h->lock, flags);
33306- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33307+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33308 spin_unlock_irqrestore(&h->lock, flags);
33309 free_irq(h->intr[h->intr_mode], h);
33310 rc = cciss_request_irq(h, cciss_msix_discard_completions,
33311@@ -5102,9 +5104,9 @@ reinit_after_soft_reset:
33312 dev_info(&h->pdev->dev, "Board READY.\n");
33313 dev_info(&h->pdev->dev,
33314 "Waiting for stale completions to drain.\n");
33315- h->access.set_intr_mask(h, CCISS_INTR_ON);
33316+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33317 msleep(10000);
33318- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33319+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33320
33321 rc = controller_reset_failed(h->cfgtable);
33322 if (rc)
33323@@ -5127,7 +5129,7 @@ reinit_after_soft_reset:
33324 cciss_scsi_setup(h);
33325
33326 /* Turn the interrupts on so we can service requests */
33327- h->access.set_intr_mask(h, CCISS_INTR_ON);
33328+ h->access->set_intr_mask(h, CCISS_INTR_ON);
33329
33330 /* Get the firmware version */
33331 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
33332@@ -5199,7 +5201,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
33333 kfree(flush_buf);
33334 if (return_code != IO_OK)
33335 dev_warn(&h->pdev->dev, "Error flushing cache\n");
33336- h->access.set_intr_mask(h, CCISS_INTR_OFF);
33337+ h->access->set_intr_mask(h, CCISS_INTR_OFF);
33338 free_irq(h->intr[h->intr_mode], h);
33339 }
33340
33341diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
33342index 7fda30e..eb5dfe0 100644
33343--- a/drivers/block/cciss.h
33344+++ b/drivers/block/cciss.h
33345@@ -101,7 +101,7 @@ struct ctlr_info
33346 /* information about each logical volume */
33347 drive_info_struct *drv[CISS_MAX_LUN];
33348
33349- struct access_method access;
33350+ struct access_method *access;
33351
33352 /* queue and queue Info */
33353 struct list_head reqQ;
33354diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
33355index 3f08713..87d4b4a 100644
33356--- a/drivers/block/cpqarray.c
33357+++ b/drivers/block/cpqarray.c
33358@@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33359 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
33360 goto Enomem4;
33361 }
33362- hba[i]->access.set_intr_mask(hba[i], 0);
33363+ hba[i]->access->set_intr_mask(hba[i], 0);
33364 if (request_irq(hba[i]->intr, do_ida_intr,
33365 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
33366 {
33367@@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
33368 add_timer(&hba[i]->timer);
33369
33370 /* Enable IRQ now that spinlock and rate limit timer are set up */
33371- hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33372+ hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
33373
33374 for(j=0; j<NWD; j++) {
33375 struct gendisk *disk = ida_gendisk[i][j];
33376@@ -694,7 +694,7 @@ DBGINFO(
33377 for(i=0; i<NR_PRODUCTS; i++) {
33378 if (board_id == products[i].board_id) {
33379 c->product_name = products[i].product_name;
33380- c->access = *(products[i].access);
33381+ c->access = products[i].access;
33382 break;
33383 }
33384 }
33385@@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
33386 hba[ctlr]->intr = intr;
33387 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
33388 hba[ctlr]->product_name = products[j].product_name;
33389- hba[ctlr]->access = *(products[j].access);
33390+ hba[ctlr]->access = products[j].access;
33391 hba[ctlr]->ctlr = ctlr;
33392 hba[ctlr]->board_id = board_id;
33393 hba[ctlr]->pci_dev = NULL; /* not PCI */
33394@@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
33395
33396 while((c = h->reqQ) != NULL) {
33397 /* Can't do anything if we're busy */
33398- if (h->access.fifo_full(h) == 0)
33399+ if (h->access->fifo_full(h) == 0)
33400 return;
33401
33402 /* Get the first entry from the request Q */
33403@@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
33404 h->Qdepth--;
33405
33406 /* Tell the controller to do our bidding */
33407- h->access.submit_command(h, c);
33408+ h->access->submit_command(h, c);
33409
33410 /* Get onto the completion Q */
33411 addQ(&h->cmpQ, c);
33412@@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33413 unsigned long flags;
33414 __u32 a,a1;
33415
33416- istat = h->access.intr_pending(h);
33417+ istat = h->access->intr_pending(h);
33418 /* Is this interrupt for us? */
33419 if (istat == 0)
33420 return IRQ_NONE;
33421@@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
33422 */
33423 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
33424 if (istat & FIFO_NOT_EMPTY) {
33425- while((a = h->access.command_completed(h))) {
33426+ while((a = h->access->command_completed(h))) {
33427 a1 = a; a &= ~3;
33428 if ((c = h->cmpQ) == NULL)
33429 {
33430@@ -1195,6 +1195,7 @@ out_passthru:
33431 ida_pci_info_struct pciinfo;
33432
33433 if (!arg) return -EINVAL;
33434+ memset(&pciinfo, 0, sizeof(pciinfo));
33435 pciinfo.bus = host->pci_dev->bus->number;
33436 pciinfo.dev_fn = host->pci_dev->devfn;
33437 pciinfo.board_id = host->board_id;
33438@@ -1449,11 +1450,11 @@ static int sendcmd(
33439 /*
33440 * Disable interrupt
33441 */
33442- info_p->access.set_intr_mask(info_p, 0);
33443+ info_p->access->set_intr_mask(info_p, 0);
33444 /* Make sure there is room in the command FIFO */
33445 /* Actually it should be completely empty at this time. */
33446 for (i = 200000; i > 0; i--) {
33447- temp = info_p->access.fifo_full(info_p);
33448+ temp = info_p->access->fifo_full(info_p);
33449 if (temp != 0) {
33450 break;
33451 }
33452@@ -1466,7 +1467,7 @@ DBG(
33453 /*
33454 * Send the cmd
33455 */
33456- info_p->access.submit_command(info_p, c);
33457+ info_p->access->submit_command(info_p, c);
33458 complete = pollcomplete(ctlr);
33459
33460 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
33461@@ -1549,9 +1550,9 @@ static int revalidate_allvol(ctlr_info_t *host)
33462 * we check the new geometry. Then turn interrupts back on when
33463 * we're done.
33464 */
33465- host->access.set_intr_mask(host, 0);
33466+ host->access->set_intr_mask(host, 0);
33467 getgeometry(ctlr);
33468- host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
33469+ host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
33470
33471 for(i=0; i<NWD; i++) {
33472 struct gendisk *disk = ida_gendisk[ctlr][i];
33473@@ -1591,7 +1592,7 @@ static int pollcomplete(int ctlr)
33474 /* Wait (up to 2 seconds) for a command to complete */
33475
33476 for (i = 200000; i > 0; i--) {
33477- done = hba[ctlr]->access.command_completed(hba[ctlr]);
33478+ done = hba[ctlr]->access->command_completed(hba[ctlr]);
33479 if (done == 0) {
33480 udelay(10); /* a short fixed delay */
33481 } else
33482diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
33483index be73e9d..7fbf140 100644
33484--- a/drivers/block/cpqarray.h
33485+++ b/drivers/block/cpqarray.h
33486@@ -99,7 +99,7 @@ struct ctlr_info {
33487 drv_info_t drv[NWD];
33488 struct proc_dir_entry *proc;
33489
33490- struct access_method access;
33491+ struct access_method *access;
33492
33493 cmdlist_t *reqQ;
33494 cmdlist_t *cmpQ;
33495diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
33496index 6b51afa..17e1191 100644
33497--- a/drivers/block/drbd/drbd_int.h
33498+++ b/drivers/block/drbd/drbd_int.h
33499@@ -582,7 +582,7 @@ struct drbd_epoch {
33500 struct drbd_tconn *tconn;
33501 struct list_head list;
33502 unsigned int barrier_nr;
33503- atomic_t epoch_size; /* increased on every request added. */
33504+ atomic_unchecked_t epoch_size; /* increased on every request added. */
33505 atomic_t active; /* increased on every req. added, and dec on every finished. */
33506 unsigned long flags;
33507 };
33508@@ -1011,7 +1011,7 @@ struct drbd_conf {
33509 int al_tr_cycle;
33510 int al_tr_pos; /* position of the next transaction in the journal */
33511 wait_queue_head_t seq_wait;
33512- atomic_t packet_seq;
33513+ atomic_unchecked_t packet_seq;
33514 unsigned int peer_seq;
33515 spinlock_t peer_seq_lock;
33516 unsigned int minor;
33517@@ -1527,7 +1527,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
33518 char __user *uoptval;
33519 int err;
33520
33521- uoptval = (char __user __force *)optval;
33522+ uoptval = (char __force_user *)optval;
33523
33524 set_fs(KERNEL_DS);
33525 if (level == SOL_SOCKET)
33526diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
33527index 54d03d4..332f311 100644
33528--- a/drivers/block/drbd/drbd_main.c
33529+++ b/drivers/block/drbd/drbd_main.c
33530@@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
33531 p->sector = sector;
33532 p->block_id = block_id;
33533 p->blksize = blksize;
33534- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33535+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33536 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
33537 }
33538
33539@@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
33540 return -EIO;
33541 p->sector = cpu_to_be64(req->i.sector);
33542 p->block_id = (unsigned long)req;
33543- p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
33544+ p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
33545 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
33546 if (mdev->state.conn >= C_SYNC_SOURCE &&
33547 mdev->state.conn <= C_PAUSED_SYNC_T)
33548@@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
33549 {
33550 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
33551
33552- if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
33553- conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
33554+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
33555+ conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
33556 kfree(tconn->current_epoch);
33557
33558 idr_destroy(&tconn->volumes);
33559diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
33560index 2f5fffd..b22a1ae 100644
33561--- a/drivers/block/drbd/drbd_receiver.c
33562+++ b/drivers/block/drbd/drbd_receiver.c
33563@@ -833,7 +833,7 @@ int drbd_connected(struct drbd_conf *mdev)
33564 {
33565 int err;
33566
33567- atomic_set(&mdev->packet_seq, 0);
33568+ atomic_set_unchecked(&mdev->packet_seq, 0);
33569 mdev->peer_seq = 0;
33570
33571 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
33572@@ -1191,7 +1191,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33573 do {
33574 next_epoch = NULL;
33575
33576- epoch_size = atomic_read(&epoch->epoch_size);
33577+ epoch_size = atomic_read_unchecked(&epoch->epoch_size);
33578
33579 switch (ev & ~EV_CLEANUP) {
33580 case EV_PUT:
33581@@ -1231,7 +1231,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
33582 rv = FE_DESTROYED;
33583 } else {
33584 epoch->flags = 0;
33585- atomic_set(&epoch->epoch_size, 0);
33586+ atomic_set_unchecked(&epoch->epoch_size, 0);
33587 /* atomic_set(&epoch->active, 0); is already zero */
33588 if (rv == FE_STILL_LIVE)
33589 rv = FE_RECYCLED;
33590@@ -1449,7 +1449,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33591 conn_wait_active_ee_empty(tconn);
33592 drbd_flush(tconn);
33593
33594- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33595+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33596 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
33597 if (epoch)
33598 break;
33599@@ -1462,11 +1462,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
33600 }
33601
33602 epoch->flags = 0;
33603- atomic_set(&epoch->epoch_size, 0);
33604+ atomic_set_unchecked(&epoch->epoch_size, 0);
33605 atomic_set(&epoch->active, 0);
33606
33607 spin_lock(&tconn->epoch_lock);
33608- if (atomic_read(&tconn->current_epoch->epoch_size)) {
33609+ if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
33610 list_add(&epoch->list, &tconn->current_epoch->list);
33611 tconn->current_epoch = epoch;
33612 tconn->epochs++;
33613@@ -2170,7 +2170,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33614
33615 err = wait_for_and_update_peer_seq(mdev, peer_seq);
33616 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
33617- atomic_inc(&tconn->current_epoch->epoch_size);
33618+ atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
33619 err2 = drbd_drain_block(mdev, pi->size);
33620 if (!err)
33621 err = err2;
33622@@ -2204,7 +2204,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
33623
33624 spin_lock(&tconn->epoch_lock);
33625 peer_req->epoch = tconn->current_epoch;
33626- atomic_inc(&peer_req->epoch->epoch_size);
33627+ atomic_inc_unchecked(&peer_req->epoch->epoch_size);
33628 atomic_inc(&peer_req->epoch->active);
33629 spin_unlock(&tconn->epoch_lock);
33630
33631@@ -4345,7 +4345,7 @@ struct data_cmd {
33632 int expect_payload;
33633 size_t pkt_size;
33634 int (*fn)(struct drbd_tconn *, struct packet_info *);
33635-};
33636+} __do_const;
33637
33638 static struct data_cmd drbd_cmd_handler[] = {
33639 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
33640@@ -4465,7 +4465,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
33641 if (!list_empty(&tconn->current_epoch->list))
33642 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
33643 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
33644- atomic_set(&tconn->current_epoch->epoch_size, 0);
33645+ atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
33646 tconn->send.seen_any_write_yet = false;
33647
33648 conn_info(tconn, "Connection closed\n");
33649@@ -5221,7 +5221,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
33650 struct asender_cmd {
33651 size_t pkt_size;
33652 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
33653-};
33654+} __do_const;
33655
33656 static struct asender_cmd asender_tbl[] = {
33657 [P_PING] = { 0, got_Ping },
33658diff --git a/drivers/block/loop.c b/drivers/block/loop.c
33659index dfe7583..83768bb 100644
33660--- a/drivers/block/loop.c
33661+++ b/drivers/block/loop.c
33662@@ -231,7 +231,7 @@ static int __do_lo_send_write(struct file *file,
33663 mm_segment_t old_fs = get_fs();
33664
33665 set_fs(get_ds());
33666- bw = file->f_op->write(file, buf, len, &pos);
33667+ bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
33668 set_fs(old_fs);
33669 if (likely(bw == len))
33670 return 0;
33671diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c
33672index 7fecc78..84d217c 100644
33673--- a/drivers/block/nbd.c
33674+++ b/drivers/block/nbd.c
33675@@ -714,7 +714,7 @@ static int __nbd_ioctl(struct block_device *bdev, struct nbd_device *nbd,
33676 else
33677 blk_queue_flush(nbd->disk->queue, 0);
33678
33679- thread = kthread_create(nbd_thread, nbd, nbd->disk->disk_name);
33680+ thread = kthread_create(nbd_thread, nbd, "%s", nbd->disk->disk_name);
33681 if (IS_ERR(thread)) {
33682 mutex_lock(&nbd->tx_lock);
33683 return PTR_ERR(thread);
33684diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
33685index 2e7de7a..ed86dc0 100644
33686--- a/drivers/block/pktcdvd.c
33687+++ b/drivers/block/pktcdvd.c
33688@@ -83,7 +83,7 @@
33689
33690 #define MAX_SPEED 0xffff
33691
33692-#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1))
33693+#define ZONE(sector, pd) (((sector) + (pd)->offset) & ~((pd)->settings.size - 1UL))
33694
33695 static DEFINE_MUTEX(pktcdvd_mutex);
33696 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
33697diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
33698index d620b44..d7538c2 100644
33699--- a/drivers/cdrom/cdrom.c
33700+++ b/drivers/cdrom/cdrom.c
33701@@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
33702 ENSURE(reset, CDC_RESET);
33703 ENSURE(generic_packet, CDC_GENERIC_PACKET);
33704 cdi->mc_flags = 0;
33705- cdo->n_minors = 0;
33706 cdi->options = CDO_USE_FFLAGS;
33707
33708 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
33709@@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
33710 else
33711 cdi->cdda_method = CDDA_OLD;
33712
33713- if (!cdo->generic_packet)
33714- cdo->generic_packet = cdrom_dummy_generic_packet;
33715+ if (!cdo->generic_packet) {
33716+ pax_open_kernel();
33717+ *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
33718+ pax_close_kernel();
33719+ }
33720
33721 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
33722 mutex_lock(&cdrom_mutex);
33723@@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
33724 if (cdi->exit)
33725 cdi->exit(cdi);
33726
33727- cdi->ops->n_minors--;
33728 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
33729 }
33730
33731@@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
33732 */
33733 nr = nframes;
33734 do {
33735- cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33736+ cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
33737 if (cgc.buffer)
33738 break;
33739
33740@@ -2882,7 +2883,7 @@ static noinline int mmc_ioctl_cdrom_read_data(struct cdrom_device_info *cdi,
33741 if (lba < 0)
33742 return -EINVAL;
33743
33744- cgc->buffer = kmalloc(blocksize, GFP_KERNEL);
33745+ cgc->buffer = kzalloc(blocksize, GFP_KERNEL);
33746 if (cgc->buffer == NULL)
33747 return -ENOMEM;
33748
33749@@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
33750 struct cdrom_device_info *cdi;
33751 int ret;
33752
33753- ret = scnprintf(info + *pos, max_size - *pos, header);
33754+ ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
33755 if (!ret)
33756 return 1;
33757
33758diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
33759index d59cdcb..11afddf 100644
33760--- a/drivers/cdrom/gdrom.c
33761+++ b/drivers/cdrom/gdrom.c
33762@@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
33763 .audio_ioctl = gdrom_audio_ioctl,
33764 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
33765 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
33766- .n_minors = 1,
33767 };
33768
33769 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
33770diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
33771index 3bb6fa3..34013fb 100644
33772--- a/drivers/char/Kconfig
33773+++ b/drivers/char/Kconfig
33774@@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
33775
33776 config DEVKMEM
33777 bool "/dev/kmem virtual device support"
33778- default y
33779+ default n
33780+ depends on !GRKERNSEC_KMEM
33781 help
33782 Say Y here if you want to support the /dev/kmem device. The
33783 /dev/kmem device is rarely used, but can be used for certain
33784@@ -582,6 +583,7 @@ config DEVPORT
33785 bool
33786 depends on !M68K
33787 depends on ISA || PCI
33788+ depends on !GRKERNSEC_KMEM
33789 default y
33790
33791 source "drivers/s390/char/Kconfig"
33792diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
33793index a48e05b..6bac831 100644
33794--- a/drivers/char/agp/compat_ioctl.c
33795+++ b/drivers/char/agp/compat_ioctl.c
33796@@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
33797 return -ENOMEM;
33798 }
33799
33800- if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
33801+ if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
33802 sizeof(*usegment) * ureserve.seg_count)) {
33803 kfree(usegment);
33804 kfree(ksegment);
33805diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
33806index 2e04433..771f2cc 100644
33807--- a/drivers/char/agp/frontend.c
33808+++ b/drivers/char/agp/frontend.c
33809@@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33810 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
33811 return -EFAULT;
33812
33813- if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
33814+ if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
33815 return -EFAULT;
33816
33817 client = agp_find_client_by_pid(reserve.pid);
33818@@ -847,7 +847,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
33819 if (segment == NULL)
33820 return -ENOMEM;
33821
33822- if (copy_from_user(segment, (void __user *) reserve.seg_list,
33823+ if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
33824 sizeof(struct agp_segment) * reserve.seg_count)) {
33825 kfree(segment);
33826 return -EFAULT;
33827diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
33828index 21cb980..f15107c 100644
33829--- a/drivers/char/genrtc.c
33830+++ b/drivers/char/genrtc.c
33831@@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
33832 switch (cmd) {
33833
33834 case RTC_PLL_GET:
33835+ memset(&pll, 0, sizeof(pll));
33836 if (get_rtc_pll(&pll))
33837 return -EINVAL;
33838 else
33839diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
33840index d784650..e8bfd69 100644
33841--- a/drivers/char/hpet.c
33842+++ b/drivers/char/hpet.c
33843@@ -559,7 +559,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
33844 }
33845
33846 static int
33847-hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
33848+hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
33849 struct hpet_info *info)
33850 {
33851 struct hpet_timer __iomem *timer;
33852diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
33853index 86fe45c..c0ea948 100644
33854--- a/drivers/char/hw_random/intel-rng.c
33855+++ b/drivers/char/hw_random/intel-rng.c
33856@@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
33857
33858 if (no_fwh_detect)
33859 return -ENODEV;
33860- printk(warning);
33861+ printk("%s", warning);
33862 return -EBUSY;
33863 }
33864
33865diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
33866index 053201b0..8335cce 100644
33867--- a/drivers/char/ipmi/ipmi_msghandler.c
33868+++ b/drivers/char/ipmi/ipmi_msghandler.c
33869@@ -420,7 +420,7 @@ struct ipmi_smi {
33870 struct proc_dir_entry *proc_dir;
33871 char proc_dir_name[10];
33872
33873- atomic_t stats[IPMI_NUM_STATS];
33874+ atomic_unchecked_t stats[IPMI_NUM_STATS];
33875
33876 /*
33877 * run_to_completion duplicate of smb_info, smi_info
33878@@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
33879
33880
33881 #define ipmi_inc_stat(intf, stat) \
33882- atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
33883+ atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
33884 #define ipmi_get_stat(intf, stat) \
33885- ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
33886+ ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
33887
33888 static int is_lan_addr(struct ipmi_addr *addr)
33889 {
33890@@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
33891 INIT_LIST_HEAD(&intf->cmd_rcvrs);
33892 init_waitqueue_head(&intf->waitq);
33893 for (i = 0; i < IPMI_NUM_STATS; i++)
33894- atomic_set(&intf->stats[i], 0);
33895+ atomic_set_unchecked(&intf->stats[i], 0);
33896
33897 intf->proc_dir = NULL;
33898
33899diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
33900index 0ac9b45..6179fb5 100644
33901--- a/drivers/char/ipmi/ipmi_si_intf.c
33902+++ b/drivers/char/ipmi/ipmi_si_intf.c
33903@@ -275,7 +275,7 @@ struct smi_info {
33904 unsigned char slave_addr;
33905
33906 /* Counters and things for the proc filesystem. */
33907- atomic_t stats[SI_NUM_STATS];
33908+ atomic_unchecked_t stats[SI_NUM_STATS];
33909
33910 struct task_struct *thread;
33911
33912@@ -284,9 +284,9 @@ struct smi_info {
33913 };
33914
33915 #define smi_inc_stat(smi, stat) \
33916- atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
33917+ atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
33918 #define smi_get_stat(smi, stat) \
33919- ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
33920+ ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
33921
33922 #define SI_MAX_PARMS 4
33923
33924@@ -3254,7 +3254,7 @@ static int try_smi_init(struct smi_info *new_smi)
33925 atomic_set(&new_smi->req_events, 0);
33926 new_smi->run_to_completion = 0;
33927 for (i = 0; i < SI_NUM_STATS; i++)
33928- atomic_set(&new_smi->stats[i], 0);
33929+ atomic_set_unchecked(&new_smi->stats[i], 0);
33930
33931 new_smi->interrupt_disabled = 1;
33932 atomic_set(&new_smi->stop_operation, 0);
33933diff --git a/drivers/char/mem.c b/drivers/char/mem.c
33934index 2c644af..4b7aede 100644
33935--- a/drivers/char/mem.c
33936+++ b/drivers/char/mem.c
33937@@ -18,6 +18,7 @@
33938 #include <linux/raw.h>
33939 #include <linux/tty.h>
33940 #include <linux/capability.h>
33941+#include <linux/security.h>
33942 #include <linux/ptrace.h>
33943 #include <linux/device.h>
33944 #include <linux/highmem.h>
33945@@ -37,6 +38,10 @@
33946
33947 #define DEVPORT_MINOR 4
33948
33949+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
33950+extern const struct file_operations grsec_fops;
33951+#endif
33952+
33953 static inline unsigned long size_inside_page(unsigned long start,
33954 unsigned long size)
33955 {
33956@@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33957
33958 while (cursor < to) {
33959 if (!devmem_is_allowed(pfn)) {
33960+#ifdef CONFIG_GRKERNSEC_KMEM
33961+ gr_handle_mem_readwrite(from, to);
33962+#else
33963 printk(KERN_INFO
33964 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
33965 current->comm, from, to);
33966+#endif
33967 return 0;
33968 }
33969 cursor += PAGE_SIZE;
33970@@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33971 }
33972 return 1;
33973 }
33974+#elif defined(CONFIG_GRKERNSEC_KMEM)
33975+static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33976+{
33977+ return 0;
33978+}
33979 #else
33980 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33981 {
33982@@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33983
33984 while (count > 0) {
33985 unsigned long remaining;
33986+ char *temp;
33987
33988 sz = size_inside_page(p, count);
33989
33990@@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
33991 if (!ptr)
33992 return -EFAULT;
33993
33994- remaining = copy_to_user(buf, ptr, sz);
33995+#ifdef CONFIG_PAX_USERCOPY
33996+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
33997+ if (!temp) {
33998+ unxlate_dev_mem_ptr(p, ptr);
33999+ return -ENOMEM;
34000+ }
34001+ memcpy(temp, ptr, sz);
34002+#else
34003+ temp = ptr;
34004+#endif
34005+
34006+ remaining = copy_to_user(buf, temp, sz);
34007+
34008+#ifdef CONFIG_PAX_USERCOPY
34009+ kfree(temp);
34010+#endif
34011+
34012 unxlate_dev_mem_ptr(p, ptr);
34013 if (remaining)
34014 return -EFAULT;
34015@@ -378,7 +409,7 @@ static ssize_t read_oldmem(struct file *file, char __user *buf,
34016 else
34017 csize = count;
34018
34019- rc = copy_oldmem_page(pfn, buf, csize, offset, 1);
34020+ rc = copy_oldmem_page(pfn, (char __force_kernel *)buf, csize, offset, 1);
34021 if (rc < 0)
34022 return rc;
34023 buf += csize;
34024@@ -398,9 +429,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34025 size_t count, loff_t *ppos)
34026 {
34027 unsigned long p = *ppos;
34028- ssize_t low_count, read, sz;
34029+ ssize_t low_count, read, sz, err = 0;
34030 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
34031- int err = 0;
34032
34033 read = 0;
34034 if (p < (unsigned long) high_memory) {
34035@@ -422,6 +452,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34036 }
34037 #endif
34038 while (low_count > 0) {
34039+ char *temp;
34040+
34041 sz = size_inside_page(p, low_count);
34042
34043 /*
34044@@ -431,7 +463,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
34045 */
34046 kbuf = xlate_dev_kmem_ptr((char *)p);
34047
34048- if (copy_to_user(buf, kbuf, sz))
34049+#ifdef CONFIG_PAX_USERCOPY
34050+ temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
34051+ if (!temp)
34052+ return -ENOMEM;
34053+ memcpy(temp, kbuf, sz);
34054+#else
34055+ temp = kbuf;
34056+#endif
34057+
34058+ err = copy_to_user(buf, temp, sz);
34059+
34060+#ifdef CONFIG_PAX_USERCOPY
34061+ kfree(temp);
34062+#endif
34063+
34064+ if (err)
34065 return -EFAULT;
34066 buf += sz;
34067 p += sz;
34068@@ -833,6 +880,9 @@ static const struct memdev {
34069 #ifdef CONFIG_CRASH_DUMP
34070 [12] = { "oldmem", 0, &oldmem_fops, NULL },
34071 #endif
34072+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
34073+ [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
34074+#endif
34075 };
34076
34077 static int memory_open(struct inode *inode, struct file *filp)
34078@@ -904,7 +954,7 @@ static int __init chr_dev_init(void)
34079 continue;
34080
34081 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
34082- NULL, devlist[minor].name);
34083+ NULL, "%s", devlist[minor].name);
34084 }
34085
34086 return tty_init();
34087diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
34088index c689697..04e6d6a2 100644
34089--- a/drivers/char/mwave/tp3780i.c
34090+++ b/drivers/char/mwave/tp3780i.c
34091@@ -479,6 +479,7 @@ int tp3780I_QueryAbilities(THINKPAD_BD_DATA * pBDData, MW_ABILITIES * pAbilities
34092 PRINTK_2(TRACE_TP3780I,
34093 "tp3780i::tp3780I_QueryAbilities entry pBDData %p\n", pBDData);
34094
34095+ memset(pAbilities, 0, sizeof(*pAbilities));
34096 /* fill out standard constant fields */
34097 pAbilities->instr_per_sec = pBDData->rDspSettings.uIps;
34098 pAbilities->data_size = pBDData->rDspSettings.uDStoreSize;
34099diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
34100index 9df78e2..01ba9ae 100644
34101--- a/drivers/char/nvram.c
34102+++ b/drivers/char/nvram.c
34103@@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
34104
34105 spin_unlock_irq(&rtc_lock);
34106
34107- if (copy_to_user(buf, contents, tmp - contents))
34108+ if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
34109 return -EFAULT;
34110
34111 *ppos = i;
34112diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
34113index 5c5cc00..ac9edb7 100644
34114--- a/drivers/char/pcmcia/synclink_cs.c
34115+++ b/drivers/char/pcmcia/synclink_cs.c
34116@@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34117
34118 if (debug_level >= DEBUG_LEVEL_INFO)
34119 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
34120- __FILE__, __LINE__, info->device_name, port->count);
34121+ __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
34122
34123- WARN_ON(!port->count);
34124+ WARN_ON(!atomic_read(&port->count));
34125
34126 if (tty_port_close_start(port, tty, filp) == 0)
34127 goto cleanup;
34128@@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
34129 cleanup:
34130 if (debug_level >= DEBUG_LEVEL_INFO)
34131 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
34132- tty->driver->name, port->count);
34133+ tty->driver->name, atomic_read(&port->count));
34134 }
34135
34136 /* Wait until the transmitter is empty.
34137@@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34138
34139 if (debug_level >= DEBUG_LEVEL_INFO)
34140 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
34141- __FILE__, __LINE__, tty->driver->name, port->count);
34142+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
34143
34144 /* If port is closing, signal caller to try again */
34145 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
34146@@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
34147 goto cleanup;
34148 }
34149 spin_lock(&port->lock);
34150- port->count++;
34151+ atomic_inc(&port->count);
34152 spin_unlock(&port->lock);
34153 spin_unlock_irqrestore(&info->netlock, flags);
34154
34155- if (port->count == 1) {
34156+ if (atomic_read(&port->count) == 1) {
34157 /* 1st open on this device, init hardware */
34158 retval = startup(info, tty);
34159 if (retval < 0)
34160@@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
34161 unsigned short new_crctype;
34162
34163 /* return error if TTY interface open */
34164- if (info->port.count)
34165+ if (atomic_read(&info->port.count))
34166 return -EBUSY;
34167
34168 switch (encoding)
34169@@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
34170
34171 /* arbitrate between network and tty opens */
34172 spin_lock_irqsave(&info->netlock, flags);
34173- if (info->port.count != 0 || info->netcount != 0) {
34174+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
34175 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
34176 spin_unlock_irqrestore(&info->netlock, flags);
34177 return -EBUSY;
34178@@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
34179 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
34180
34181 /* return error if TTY interface open */
34182- if (info->port.count)
34183+ if (atomic_read(&info->port.count))
34184 return -EBUSY;
34185
34186 if (cmd != SIOCWANDEV)
34187diff --git a/drivers/char/random.c b/drivers/char/random.c
34188index eccd7cc..98038d5 100644
34189--- a/drivers/char/random.c
34190+++ b/drivers/char/random.c
34191@@ -272,8 +272,13 @@
34192 /*
34193 * Configuration information
34194 */
34195+#ifdef CONFIG_GRKERNSEC_RANDNET
34196+#define INPUT_POOL_WORDS 512
34197+#define OUTPUT_POOL_WORDS 128
34198+#else
34199 #define INPUT_POOL_WORDS 128
34200 #define OUTPUT_POOL_WORDS 32
34201+#endif
34202 #define SEC_XFER_SIZE 512
34203 #define EXTRACT_SIZE 10
34204
34205@@ -313,10 +318,17 @@ static struct poolinfo {
34206 int poolwords;
34207 int tap1, tap2, tap3, tap4, tap5;
34208 } poolinfo_table[] = {
34209+#ifdef CONFIG_GRKERNSEC_RANDNET
34210+ /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
34211+ { 512, 411, 308, 208, 104, 1 },
34212+ /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
34213+ { 128, 103, 76, 51, 25, 1 },
34214+#else
34215 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
34216 { 128, 103, 76, 51, 25, 1 },
34217 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
34218 { 32, 26, 20, 14, 7, 1 },
34219+#endif
34220 #if 0
34221 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
34222 { 2048, 1638, 1231, 819, 411, 1 },
34223@@ -524,8 +536,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
34224 input_rotate += i ? 7 : 14;
34225 }
34226
34227- ACCESS_ONCE(r->input_rotate) = input_rotate;
34228- ACCESS_ONCE(r->add_ptr) = i;
34229+ ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
34230+ ACCESS_ONCE_RW(r->add_ptr) = i;
34231 smp_wmb();
34232
34233 if (out)
34234@@ -1032,7 +1044,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
34235
34236 extract_buf(r, tmp);
34237 i = min_t(int, nbytes, EXTRACT_SIZE);
34238- if (copy_to_user(buf, tmp, i)) {
34239+ if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
34240 ret = -EFAULT;
34241 break;
34242 }
34243@@ -1368,7 +1380,7 @@ EXPORT_SYMBOL(generate_random_uuid);
34244 #include <linux/sysctl.h>
34245
34246 static int min_read_thresh = 8, min_write_thresh;
34247-static int max_read_thresh = INPUT_POOL_WORDS * 32;
34248+static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
34249 static int max_write_thresh = INPUT_POOL_WORDS * 32;
34250 static char sysctl_bootid[16];
34251
34252@@ -1384,7 +1396,7 @@ static char sysctl_bootid[16];
34253 static int proc_do_uuid(ctl_table *table, int write,
34254 void __user *buffer, size_t *lenp, loff_t *ppos)
34255 {
34256- ctl_table fake_table;
34257+ ctl_table_no_const fake_table;
34258 unsigned char buf[64], tmp_uuid[16], *uuid;
34259
34260 uuid = table->data;
34261diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
34262index bf2349db..5456d53 100644
34263--- a/drivers/char/sonypi.c
34264+++ b/drivers/char/sonypi.c
34265@@ -54,6 +54,7 @@
34266
34267 #include <asm/uaccess.h>
34268 #include <asm/io.h>
34269+#include <asm/local.h>
34270
34271 #include <linux/sonypi.h>
34272
34273@@ -490,7 +491,7 @@ static struct sonypi_device {
34274 spinlock_t fifo_lock;
34275 wait_queue_head_t fifo_proc_list;
34276 struct fasync_struct *fifo_async;
34277- int open_count;
34278+ local_t open_count;
34279 int model;
34280 struct input_dev *input_jog_dev;
34281 struct input_dev *input_key_dev;
34282@@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
34283 static int sonypi_misc_release(struct inode *inode, struct file *file)
34284 {
34285 mutex_lock(&sonypi_device.lock);
34286- sonypi_device.open_count--;
34287+ local_dec(&sonypi_device.open_count);
34288 mutex_unlock(&sonypi_device.lock);
34289 return 0;
34290 }
34291@@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
34292 {
34293 mutex_lock(&sonypi_device.lock);
34294 /* Flush input queue on first open */
34295- if (!sonypi_device.open_count)
34296+ if (!local_read(&sonypi_device.open_count))
34297 kfifo_reset(&sonypi_device.fifo);
34298- sonypi_device.open_count++;
34299+ local_inc(&sonypi_device.open_count);
34300 mutex_unlock(&sonypi_device.lock);
34301
34302 return 0;
34303diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
34304index 64420b3..5c40b56 100644
34305--- a/drivers/char/tpm/tpm_acpi.c
34306+++ b/drivers/char/tpm/tpm_acpi.c
34307@@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
34308 virt = acpi_os_map_memory(start, len);
34309 if (!virt) {
34310 kfree(log->bios_event_log);
34311+ log->bios_event_log = NULL;
34312 printk("%s: ERROR - Unable to map memory\n", __func__);
34313 return -EIO;
34314 }
34315
34316- memcpy_fromio(log->bios_event_log, virt, len);
34317+ memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
34318
34319 acpi_os_unmap_memory(virt, len);
34320 return 0;
34321diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
34322index 84ddc55..1d32f1e 100644
34323--- a/drivers/char/tpm/tpm_eventlog.c
34324+++ b/drivers/char/tpm/tpm_eventlog.c
34325@@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
34326 event = addr;
34327
34328 if ((event->event_type == 0 && event->event_size == 0) ||
34329- ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
34330+ (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
34331 return NULL;
34332
34333 return addr;
34334@@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
34335 return NULL;
34336
34337 if ((event->event_type == 0 && event->event_size == 0) ||
34338- ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
34339+ (event->event_size >= limit - v - sizeof(struct tcpa_event)))
34340 return NULL;
34341
34342 (*pos)++;
34343@@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
34344 int i;
34345
34346 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
34347- seq_putc(m, data[i]);
34348+ if (!seq_putc(m, data[i]))
34349+ return -EFAULT;
34350
34351 return 0;
34352 }
34353diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
34354index ce5f3fc..e2d3e55 100644
34355--- a/drivers/char/virtio_console.c
34356+++ b/drivers/char/virtio_console.c
34357@@ -679,7 +679,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
34358 if (to_user) {
34359 ssize_t ret;
34360
34361- ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
34362+ ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
34363 if (ret)
34364 return -EFAULT;
34365 } else {
34366@@ -778,7 +778,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
34367 if (!port_has_data(port) && !port->host_connected)
34368 return 0;
34369
34370- return fill_readbuf(port, ubuf, count, true);
34371+ return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
34372 }
34373
34374 static int wait_port_writable(struct port *port, bool nonblock)
34375diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
34376index d7ad425..3e3f81f 100644
34377--- a/drivers/clocksource/arm_arch_timer.c
34378+++ b/drivers/clocksource/arm_arch_timer.c
34379@@ -262,7 +262,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34380 return NOTIFY_OK;
34381 }
34382
34383-static struct notifier_block arch_timer_cpu_nb __cpuinitdata = {
34384+static struct notifier_block arch_timer_cpu_nb = {
34385 .notifier_call = arch_timer_cpu_notify,
34386 };
34387
34388diff --git a/drivers/clocksource/metag_generic.c b/drivers/clocksource/metag_generic.c
34389index ade7513..069445f 100644
34390--- a/drivers/clocksource/metag_generic.c
34391+++ b/drivers/clocksource/metag_generic.c
34392@@ -169,7 +169,7 @@ static int __cpuinit arch_timer_cpu_notify(struct notifier_block *self,
34393 return NOTIFY_OK;
34394 }
34395
34396-static struct notifier_block __cpuinitdata arch_timer_cpu_nb = {
34397+static struct notifier_block arch_timer_cpu_nb = {
34398 .notifier_call = arch_timer_cpu_notify,
34399 };
34400
34401diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
34402index bb5939b..d9accb7 100644
34403--- a/drivers/cpufreq/acpi-cpufreq.c
34404+++ b/drivers/cpufreq/acpi-cpufreq.c
34405@@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
34406 return sprintf(buf, "%u\n", boost_enabled);
34407 }
34408
34409-static struct global_attr global_boost = __ATTR(boost, 0644,
34410+static global_attr_no_const global_boost = __ATTR(boost, 0644,
34411 show_global_boost,
34412 store_global_boost);
34413
34414@@ -712,8 +712,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34415 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
34416 per_cpu(acfreq_data, cpu) = data;
34417
34418- if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
34419- acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34420+ if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
34421+ pax_open_kernel();
34422+ *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
34423+ pax_close_kernel();
34424+ }
34425
34426 result = acpi_processor_register_performance(data->acpi_data, cpu);
34427 if (result)
34428@@ -839,7 +842,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34429 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
34430 break;
34431 case ACPI_ADR_SPACE_FIXED_HARDWARE:
34432- acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34433+ pax_open_kernel();
34434+ *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
34435+ pax_close_kernel();
34436 policy->cur = get_cur_freq_on_cpu(cpu);
34437 break;
34438 default:
34439@@ -850,8 +855,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
34440 acpi_processor_notify_smm(THIS_MODULE);
34441
34442 /* Check for APERF/MPERF support in hardware */
34443- if (boot_cpu_has(X86_FEATURE_APERFMPERF))
34444- acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34445+ if (boot_cpu_has(X86_FEATURE_APERFMPERF)) {
34446+ pax_open_kernel();
34447+ *(void **)&acpi_cpufreq_driver.getavg = cpufreq_get_measured_perf;
34448+ pax_close_kernel();
34449+ }
34450
34451 pr_debug("CPU%u - ACPI performance management activated.\n", cpu);
34452 for (i = 0; i < perf->state_count; i++)
34453diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
34454index b02824d..51e44aa 100644
34455--- a/drivers/cpufreq/cpufreq.c
34456+++ b/drivers/cpufreq/cpufreq.c
34457@@ -1813,7 +1813,7 @@ static int __cpuinit cpufreq_cpu_callback(struct notifier_block *nfb,
34458 return NOTIFY_OK;
34459 }
34460
34461-static struct notifier_block __refdata cpufreq_cpu_notifier = {
34462+static struct notifier_block cpufreq_cpu_notifier = {
34463 .notifier_call = cpufreq_cpu_callback,
34464 };
34465
34466@@ -1845,8 +1845,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
34467
34468 pr_debug("trying to register driver %s\n", driver_data->name);
34469
34470- if (driver_data->setpolicy)
34471- driver_data->flags |= CPUFREQ_CONST_LOOPS;
34472+ if (driver_data->setpolicy) {
34473+ pax_open_kernel();
34474+ *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
34475+ pax_close_kernel();
34476+ }
34477
34478 spin_lock_irqsave(&cpufreq_driver_lock, flags);
34479 if (cpufreq_driver) {
34480diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
34481index 5a76086..0f4d394 100644
34482--- a/drivers/cpufreq/cpufreq_governor.c
34483+++ b/drivers/cpufreq/cpufreq_governor.c
34484@@ -201,8 +201,8 @@ int cpufreq_governor_dbs(struct dbs_data *dbs_data,
34485 {
34486 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
34487 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
34488- struct cs_ops *cs_ops = NULL;
34489- struct od_ops *od_ops = NULL;
34490+ const struct cs_ops *cs_ops = NULL;
34491+ const struct od_ops *od_ops = NULL;
34492 struct od_dbs_tuners *od_tuners = dbs_data->tuners;
34493 struct cs_dbs_tuners *cs_tuners = dbs_data->tuners;
34494 struct cpu_dbs_common_info *cpu_cdbs;
34495diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
34496index cc4bd2f..ad142bc 100644
34497--- a/drivers/cpufreq/cpufreq_governor.h
34498+++ b/drivers/cpufreq/cpufreq_governor.h
34499@@ -142,7 +142,7 @@ struct dbs_data {
34500 void (*gov_check_cpu)(int cpu, unsigned int load);
34501
34502 /* Governor specific ops, see below */
34503- void *gov_ops;
34504+ const void *gov_ops;
34505 };
34506
34507 /* Governor specific ops, will be passed to dbs_data->gov_ops */
34508diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
34509index bfd6273..e39dd63 100644
34510--- a/drivers/cpufreq/cpufreq_stats.c
34511+++ b/drivers/cpufreq/cpufreq_stats.c
34512@@ -365,7 +365,7 @@ static int __cpuinit cpufreq_stat_cpu_callback(struct notifier_block *nfb,
34513 }
34514
34515 /* priority=1 so this will get called before cpufreq_remove_dev */
34516-static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
34517+static struct notifier_block cpufreq_stat_cpu_notifier = {
34518 .notifier_call = cpufreq_stat_cpu_callback,
34519 .priority = 1,
34520 };
34521diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
34522index 827629c9..0bc6a03 100644
34523--- a/drivers/cpufreq/p4-clockmod.c
34524+++ b/drivers/cpufreq/p4-clockmod.c
34525@@ -167,10 +167,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34526 case 0x0F: /* Core Duo */
34527 case 0x16: /* Celeron Core */
34528 case 0x1C: /* Atom */
34529- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34530+ pax_open_kernel();
34531+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34532+ pax_close_kernel();
34533 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
34534 case 0x0D: /* Pentium M (Dothan) */
34535- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34536+ pax_open_kernel();
34537+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34538+ pax_close_kernel();
34539 /* fall through */
34540 case 0x09: /* Pentium M (Banias) */
34541 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
34542@@ -182,7 +186,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
34543
34544 /* on P-4s, the TSC runs with constant frequency independent whether
34545 * throttling is active or not. */
34546- p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34547+ pax_open_kernel();
34548+ *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
34549+ pax_close_kernel();
34550
34551 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
34552 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
34553diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
34554index 3a953d5..f5993f6 100644
34555--- a/drivers/cpufreq/speedstep-centrino.c
34556+++ b/drivers/cpufreq/speedstep-centrino.c
34557@@ -353,8 +353,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
34558 !cpu_has(cpu, X86_FEATURE_EST))
34559 return -ENODEV;
34560
34561- if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
34562- centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34563+ if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
34564+ pax_open_kernel();
34565+ *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
34566+ pax_close_kernel();
34567+ }
34568
34569 if (policy->cpu != 0)
34570 return -ENODEV;
34571diff --git a/drivers/cpuidle/cpuidle.c b/drivers/cpuidle/cpuidle.c
34572index eba6929..0f53baf 100644
34573--- a/drivers/cpuidle/cpuidle.c
34574+++ b/drivers/cpuidle/cpuidle.c
34575@@ -277,7 +277,7 @@ static int poll_idle(struct cpuidle_device *dev,
34576
34577 static void poll_idle_init(struct cpuidle_driver *drv)
34578 {
34579- struct cpuidle_state *state = &drv->states[0];
34580+ cpuidle_state_no_const *state = &drv->states[0];
34581
34582 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
34583 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
34584diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
34585index ea2f8e7..70ac501 100644
34586--- a/drivers/cpuidle/governor.c
34587+++ b/drivers/cpuidle/governor.c
34588@@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
34589 mutex_lock(&cpuidle_lock);
34590 if (__cpuidle_find_governor(gov->name) == NULL) {
34591 ret = 0;
34592- list_add_tail(&gov->governor_list, &cpuidle_governors);
34593+ pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
34594 if (!cpuidle_curr_governor ||
34595 cpuidle_curr_governor->rating < gov->rating)
34596 cpuidle_switch_governor(gov);
34597@@ -135,7 +135,7 @@ void cpuidle_unregister_governor(struct cpuidle_governor *gov)
34598 new_gov = cpuidle_replace_governor(gov->rating);
34599 cpuidle_switch_governor(new_gov);
34600 }
34601- list_del(&gov->governor_list);
34602+ pax_list_del((struct list_head *)&gov->governor_list);
34603 mutex_unlock(&cpuidle_lock);
34604 }
34605
34606diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
34607index 428754a..8bdf9cc 100644
34608--- a/drivers/cpuidle/sysfs.c
34609+++ b/drivers/cpuidle/sysfs.c
34610@@ -131,7 +131,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
34611 NULL
34612 };
34613
34614-static struct attribute_group cpuidle_attr_group = {
34615+static attribute_group_no_const cpuidle_attr_group = {
34616 .attrs = cpuidle_default_attrs,
34617 .name = "cpuidle",
34618 };
34619diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
34620index 3b36797..db0b0c0 100644
34621--- a/drivers/devfreq/devfreq.c
34622+++ b/drivers/devfreq/devfreq.c
34623@@ -477,7 +477,7 @@ struct devfreq *devfreq_add_device(struct device *dev,
34624 GFP_KERNEL);
34625 devfreq->last_stat_updated = jiffies;
34626
34627- dev_set_name(&devfreq->dev, dev_name(dev));
34628+ dev_set_name(&devfreq->dev, "%s", dev_name(dev));
34629 err = device_register(&devfreq->dev);
34630 if (err) {
34631 put_device(&devfreq->dev);
34632@@ -588,7 +588,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
34633 goto err_out;
34634 }
34635
34636- list_add(&governor->node, &devfreq_governor_list);
34637+ pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
34638
34639 list_for_each_entry(devfreq, &devfreq_list, node) {
34640 int ret = 0;
34641@@ -676,7 +676,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
34642 }
34643 }
34644
34645- list_del(&governor->node);
34646+ pax_list_del((struct list_head *)&governor->node);
34647 err_out:
34648 mutex_unlock(&devfreq_list_lock);
34649
34650diff --git a/drivers/dma/sh/shdma.c b/drivers/dma/sh/shdma.c
34651index b70709b..1d8d02a 100644
34652--- a/drivers/dma/sh/shdma.c
34653+++ b/drivers/dma/sh/shdma.c
34654@@ -476,7 +476,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
34655 return ret;
34656 }
34657
34658-static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
34659+static struct notifier_block sh_dmae_nmi_notifier = {
34660 .notifier_call = sh_dmae_nmi_handler,
34661
34662 /* Run before NMI debug handler and KGDB */
34663diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
34664index 769d92e..a3dcc1e 100644
34665--- a/drivers/edac/edac_mc_sysfs.c
34666+++ b/drivers/edac/edac_mc_sysfs.c
34667@@ -148,7 +148,7 @@ static const char *edac_caps[] = {
34668 struct dev_ch_attribute {
34669 struct device_attribute attr;
34670 int channel;
34671-};
34672+} __do_const;
34673
34674 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
34675 struct dev_ch_attribute dev_attr_legacy_##_name = \
34676@@ -1003,14 +1003,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
34677 }
34678
34679 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
34680+ pax_open_kernel();
34681 if (mci->get_sdram_scrub_rate) {
34682- dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34683- dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34684+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
34685+ *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
34686 }
34687 if (mci->set_sdram_scrub_rate) {
34688- dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34689- dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34690+ *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
34691+ *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
34692 }
34693+ pax_close_kernel();
34694 err = device_create_file(&mci->dev,
34695 &dev_attr_sdram_scrub_rate);
34696 if (err) {
34697diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
34698index e8658e4..22746d6 100644
34699--- a/drivers/edac/edac_pci_sysfs.c
34700+++ b/drivers/edac/edac_pci_sysfs.c
34701@@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
34702 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
34703 static int edac_pci_poll_msec = 1000; /* one second workq period */
34704
34705-static atomic_t pci_parity_count = ATOMIC_INIT(0);
34706-static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
34707+static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
34708+static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
34709
34710 static struct kobject *edac_pci_top_main_kobj;
34711 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
34712@@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
34713 void *value;
34714 ssize_t(*show) (void *, char *);
34715 ssize_t(*store) (void *, const char *, size_t);
34716-};
34717+} __do_const;
34718
34719 /* Set of show/store abstract level functions for PCI Parity object */
34720 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
34721@@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34722 edac_printk(KERN_CRIT, EDAC_PCI,
34723 "Signaled System Error on %s\n",
34724 pci_name(dev));
34725- atomic_inc(&pci_nonparity_count);
34726+ atomic_inc_unchecked(&pci_nonparity_count);
34727 }
34728
34729 if (status & (PCI_STATUS_PARITY)) {
34730@@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34731 "Master Data Parity Error on %s\n",
34732 pci_name(dev));
34733
34734- atomic_inc(&pci_parity_count);
34735+ atomic_inc_unchecked(&pci_parity_count);
34736 }
34737
34738 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34739@@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34740 "Detected Parity Error on %s\n",
34741 pci_name(dev));
34742
34743- atomic_inc(&pci_parity_count);
34744+ atomic_inc_unchecked(&pci_parity_count);
34745 }
34746 }
34747
34748@@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34749 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
34750 "Signaled System Error on %s\n",
34751 pci_name(dev));
34752- atomic_inc(&pci_nonparity_count);
34753+ atomic_inc_unchecked(&pci_nonparity_count);
34754 }
34755
34756 if (status & (PCI_STATUS_PARITY)) {
34757@@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34758 "Master Data Parity Error on "
34759 "%s\n", pci_name(dev));
34760
34761- atomic_inc(&pci_parity_count);
34762+ atomic_inc_unchecked(&pci_parity_count);
34763 }
34764
34765 if (status & (PCI_STATUS_DETECTED_PARITY)) {
34766@@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
34767 "Detected Parity Error on %s\n",
34768 pci_name(dev));
34769
34770- atomic_inc(&pci_parity_count);
34771+ atomic_inc_unchecked(&pci_parity_count);
34772 }
34773 }
34774 }
34775@@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
34776 if (!check_pci_errors)
34777 return;
34778
34779- before_count = atomic_read(&pci_parity_count);
34780+ before_count = atomic_read_unchecked(&pci_parity_count);
34781
34782 /* scan all PCI devices looking for a Parity Error on devices and
34783 * bridges.
34784@@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
34785 /* Only if operator has selected panic on PCI Error */
34786 if (edac_pci_get_panic_on_pe()) {
34787 /* If the count is different 'after' from 'before' */
34788- if (before_count != atomic_read(&pci_parity_count))
34789+ if (before_count != atomic_read_unchecked(&pci_parity_count))
34790 panic("EDAC: PCI Parity Error");
34791 }
34792 }
34793diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
34794index 51b7e3a..aa8a3e8 100644
34795--- a/drivers/edac/mce_amd.h
34796+++ b/drivers/edac/mce_amd.h
34797@@ -77,7 +77,7 @@ struct amd_decoder_ops {
34798 bool (*mc0_mce)(u16, u8);
34799 bool (*mc1_mce)(u16, u8);
34800 bool (*mc2_mce)(u16, u8);
34801-};
34802+} __no_const;
34803
34804 void amd_report_gart_errors(bool);
34805 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
34806diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
34807index 57ea7f4..789e3c3 100644
34808--- a/drivers/firewire/core-card.c
34809+++ b/drivers/firewire/core-card.c
34810@@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
34811
34812 void fw_core_remove_card(struct fw_card *card)
34813 {
34814- struct fw_card_driver dummy_driver = dummy_driver_template;
34815+ fw_card_driver_no_const dummy_driver = dummy_driver_template;
34816
34817 card->driver->update_phy_reg(card, 4,
34818 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
34819diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
34820index 27ac423..13573e8 100644
34821--- a/drivers/firewire/core-cdev.c
34822+++ b/drivers/firewire/core-cdev.c
34823@@ -1366,8 +1366,7 @@ static int init_iso_resource(struct client *client,
34824 int ret;
34825
34826 if ((request->channels == 0 && request->bandwidth == 0) ||
34827- request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
34828- request->bandwidth < 0)
34829+ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
34830 return -EINVAL;
34831
34832 r = kmalloc(sizeof(*r), GFP_KERNEL);
34833diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
34834index 03ce7d9..b70f5da 100644
34835--- a/drivers/firewire/core-device.c
34836+++ b/drivers/firewire/core-device.c
34837@@ -232,7 +232,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
34838 struct config_rom_attribute {
34839 struct device_attribute attr;
34840 u32 key;
34841-};
34842+} __do_const;
34843
34844 static ssize_t show_immediate(struct device *dev,
34845 struct device_attribute *dattr, char *buf)
34846diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
34847index 28a94c7..58da63a 100644
34848--- a/drivers/firewire/core-transaction.c
34849+++ b/drivers/firewire/core-transaction.c
34850@@ -38,6 +38,7 @@
34851 #include <linux/timer.h>
34852 #include <linux/types.h>
34853 #include <linux/workqueue.h>
34854+#include <linux/sched.h>
34855
34856 #include <asm/byteorder.h>
34857
34858diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
34859index 515a42c..5ecf3ba 100644
34860--- a/drivers/firewire/core.h
34861+++ b/drivers/firewire/core.h
34862@@ -111,6 +111,7 @@ struct fw_card_driver {
34863
34864 int (*stop_iso)(struct fw_iso_context *ctx);
34865 };
34866+typedef struct fw_card_driver __no_const fw_card_driver_no_const;
34867
34868 void fw_card_initialize(struct fw_card *card,
34869 const struct fw_card_driver *driver, struct device *device);
34870diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
34871index 94a58a0..f5eba42 100644
34872--- a/drivers/firmware/dmi-id.c
34873+++ b/drivers/firmware/dmi-id.c
34874@@ -16,7 +16,7 @@
34875 struct dmi_device_attribute{
34876 struct device_attribute dev_attr;
34877 int field;
34878-};
34879+} __do_const;
34880 #define to_dmi_dev_attr(_dev_attr) \
34881 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
34882
34883diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
34884index 4cd392d..4b629e1 100644
34885--- a/drivers/firmware/dmi_scan.c
34886+++ b/drivers/firmware/dmi_scan.c
34887@@ -490,11 +490,6 @@ void __init dmi_scan_machine(void)
34888 }
34889 }
34890 else {
34891- /*
34892- * no iounmap() for that ioremap(); it would be a no-op, but
34893- * it's so early in setup that sucker gets confused into doing
34894- * what it shouldn't if we actually call it.
34895- */
34896 p = dmi_ioremap(0xF0000, 0x10000);
34897 if (p == NULL)
34898 goto error;
34899@@ -769,7 +764,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
34900 if (buf == NULL)
34901 return -1;
34902
34903- dmi_table(buf, dmi_len, dmi_num, decode, private_data);
34904+ dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
34905
34906 iounmap(buf);
34907 return 0;
34908diff --git a/drivers/firmware/efivars.c b/drivers/firmware/efivars.c
34909index f4baa11..7970c3a 100644
34910--- a/drivers/firmware/efivars.c
34911+++ b/drivers/firmware/efivars.c
34912@@ -139,7 +139,7 @@ struct efivar_attribute {
34913 };
34914
34915 static struct efivars __efivars;
34916-static struct efivar_operations ops;
34917+static efivar_operations_no_const ops __read_only;
34918
34919 #define PSTORE_EFI_ATTRIBUTES \
34920 (EFI_VARIABLE_NON_VOLATILE | \
34921@@ -1844,7 +1844,7 @@ efivar_create_sysfs_entry(struct efivars *efivars,
34922 static int
34923 create_efivars_bin_attributes(struct efivars *efivars)
34924 {
34925- struct bin_attribute *attr;
34926+ bin_attribute_no_const *attr;
34927 int error;
34928
34929 /* new_var */
34930diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
34931index 2a90ba6..07f3733 100644
34932--- a/drivers/firmware/google/memconsole.c
34933+++ b/drivers/firmware/google/memconsole.c
34934@@ -147,7 +147,9 @@ static int __init memconsole_init(void)
34935 if (!found_memconsole())
34936 return -ENODEV;
34937
34938- memconsole_bin_attr.size = memconsole_length;
34939+ pax_open_kernel();
34940+ *(size_t *)&memconsole_bin_attr.size = memconsole_length;
34941+ pax_close_kernel();
34942
34943 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
34944
34945diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
34946index de3c317..b7cd029 100644
34947--- a/drivers/gpio/gpio-ich.c
34948+++ b/drivers/gpio/gpio-ich.c
34949@@ -69,7 +69,7 @@ struct ichx_desc {
34950 /* Some chipsets have quirks, let these use their own request/get */
34951 int (*request)(struct gpio_chip *chip, unsigned offset);
34952 int (*get)(struct gpio_chip *chip, unsigned offset);
34953-};
34954+} __do_const;
34955
34956 static struct {
34957 spinlock_t lock;
34958diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
34959index 9902732..64b62dd 100644
34960--- a/drivers/gpio/gpio-vr41xx.c
34961+++ b/drivers/gpio/gpio-vr41xx.c
34962@@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
34963 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
34964 maskl, pendl, maskh, pendh);
34965
34966- atomic_inc(&irq_err_count);
34967+ atomic_inc_unchecked(&irq_err_count);
34968
34969 return -EINVAL;
34970 }
34971diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
34972index 7b2d378..cc947ea 100644
34973--- a/drivers/gpu/drm/drm_crtc_helper.c
34974+++ b/drivers/gpu/drm/drm_crtc_helper.c
34975@@ -319,7 +319,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
34976 struct drm_crtc *tmp;
34977 int crtc_mask = 1;
34978
34979- WARN(!crtc, "checking null crtc?\n");
34980+ BUG_ON(!crtc);
34981
34982 dev = crtc->dev;
34983
34984diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
34985index 25f91cd..a376f55 100644
34986--- a/drivers/gpu/drm/drm_drv.c
34987+++ b/drivers/gpu/drm/drm_drv.c
34988@@ -306,7 +306,7 @@ module_exit(drm_core_exit);
34989 /**
34990 * Copy and IOCTL return string to user space
34991 */
34992-static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
34993+static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
34994 {
34995 int len;
34996
34997@@ -376,7 +376,7 @@ long drm_ioctl(struct file *filp,
34998 struct drm_file *file_priv = filp->private_data;
34999 struct drm_device *dev;
35000 struct drm_ioctl_desc *ioctl;
35001- drm_ioctl_t *func;
35002+ drm_ioctl_no_const_t func;
35003 unsigned int nr = DRM_IOCTL_NR(cmd);
35004 int retcode = -EINVAL;
35005 char stack_kdata[128];
35006@@ -389,7 +389,7 @@ long drm_ioctl(struct file *filp,
35007 return -ENODEV;
35008
35009 atomic_inc(&dev->ioctl_count);
35010- atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
35011+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
35012 ++file_priv->ioctl_count;
35013
35014 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
35015diff --git a/drivers/gpu/drm/drm_encoder_slave.c b/drivers/gpu/drm/drm_encoder_slave.c
35016index 48c52f7..0cfb60f 100644
35017--- a/drivers/gpu/drm/drm_encoder_slave.c
35018+++ b/drivers/gpu/drm/drm_encoder_slave.c
35019@@ -54,16 +54,12 @@ int drm_i2c_encoder_init(struct drm_device *dev,
35020 struct i2c_adapter *adap,
35021 const struct i2c_board_info *info)
35022 {
35023- char modalias[sizeof(I2C_MODULE_PREFIX)
35024- + I2C_NAME_SIZE];
35025 struct module *module = NULL;
35026 struct i2c_client *client;
35027 struct drm_i2c_encoder_driver *encoder_drv;
35028 int err = 0;
35029
35030- snprintf(modalias, sizeof(modalias),
35031- "%s%s", I2C_MODULE_PREFIX, info->type);
35032- request_module(modalias);
35033+ request_module("%s%s", I2C_MODULE_PREFIX, info->type);
35034
35035 client = i2c_new_device(adap, info);
35036 if (!client) {
35037diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
35038index 429e07d..e681a2c 100644
35039--- a/drivers/gpu/drm/drm_fops.c
35040+++ b/drivers/gpu/drm/drm_fops.c
35041@@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
35042 }
35043
35044 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
35045- atomic_set(&dev->counts[i], 0);
35046+ atomic_set_unchecked(&dev->counts[i], 0);
35047
35048 dev->sigdata.lock = NULL;
35049
35050@@ -135,7 +135,7 @@ int drm_open(struct inode *inode, struct file *filp)
35051 if (drm_device_is_unplugged(dev))
35052 return -ENODEV;
35053
35054- if (!dev->open_count++)
35055+ if (local_inc_return(&dev->open_count) == 1)
35056 need_setup = 1;
35057 mutex_lock(&dev->struct_mutex);
35058 old_imapping = inode->i_mapping;
35059@@ -151,7 +151,7 @@ int drm_open(struct inode *inode, struct file *filp)
35060 retcode = drm_open_helper(inode, filp, dev);
35061 if (retcode)
35062 goto err_undo;
35063- atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
35064+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
35065 if (need_setup) {
35066 retcode = drm_setup(dev);
35067 if (retcode)
35068@@ -166,7 +166,7 @@ err_undo:
35069 iput(container_of(dev->dev_mapping, struct inode, i_data));
35070 dev->dev_mapping = old_mapping;
35071 mutex_unlock(&dev->struct_mutex);
35072- dev->open_count--;
35073+ local_dec(&dev->open_count);
35074 return retcode;
35075 }
35076 EXPORT_SYMBOL(drm_open);
35077@@ -441,7 +441,7 @@ int drm_release(struct inode *inode, struct file *filp)
35078
35079 mutex_lock(&drm_global_mutex);
35080
35081- DRM_DEBUG("open_count = %d\n", dev->open_count);
35082+ DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
35083
35084 if (dev->driver->preclose)
35085 dev->driver->preclose(dev, file_priv);
35086@@ -450,10 +450,10 @@ int drm_release(struct inode *inode, struct file *filp)
35087 * Begin inline drm_release
35088 */
35089
35090- DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
35091+ DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
35092 task_pid_nr(current),
35093 (long)old_encode_dev(file_priv->minor->device),
35094- dev->open_count);
35095+ local_read(&dev->open_count));
35096
35097 /* Release any auth tokens that might point to this file_priv,
35098 (do that under the drm_global_mutex) */
35099@@ -550,8 +550,8 @@ int drm_release(struct inode *inode, struct file *filp)
35100 * End inline drm_release
35101 */
35102
35103- atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
35104- if (!--dev->open_count) {
35105+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
35106+ if (local_dec_and_test(&dev->open_count)) {
35107 if (atomic_read(&dev->ioctl_count)) {
35108 DRM_ERROR("Device busy: %d\n",
35109 atomic_read(&dev->ioctl_count));
35110diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
35111index f731116..629842c 100644
35112--- a/drivers/gpu/drm/drm_global.c
35113+++ b/drivers/gpu/drm/drm_global.c
35114@@ -36,7 +36,7 @@
35115 struct drm_global_item {
35116 struct mutex mutex;
35117 void *object;
35118- int refcount;
35119+ atomic_t refcount;
35120 };
35121
35122 static struct drm_global_item glob[DRM_GLOBAL_NUM];
35123@@ -49,7 +49,7 @@ void drm_global_init(void)
35124 struct drm_global_item *item = &glob[i];
35125 mutex_init(&item->mutex);
35126 item->object = NULL;
35127- item->refcount = 0;
35128+ atomic_set(&item->refcount, 0);
35129 }
35130 }
35131
35132@@ -59,7 +59,7 @@ void drm_global_release(void)
35133 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
35134 struct drm_global_item *item = &glob[i];
35135 BUG_ON(item->object != NULL);
35136- BUG_ON(item->refcount != 0);
35137+ BUG_ON(atomic_read(&item->refcount) != 0);
35138 }
35139 }
35140
35141@@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35142 void *object;
35143
35144 mutex_lock(&item->mutex);
35145- if (item->refcount == 0) {
35146+ if (atomic_read(&item->refcount) == 0) {
35147 item->object = kzalloc(ref->size, GFP_KERNEL);
35148 if (unlikely(item->object == NULL)) {
35149 ret = -ENOMEM;
35150@@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
35151 goto out_err;
35152
35153 }
35154- ++item->refcount;
35155+ atomic_inc(&item->refcount);
35156 ref->object = item->object;
35157 object = item->object;
35158 mutex_unlock(&item->mutex);
35159@@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
35160 struct drm_global_item *item = &glob[ref->global_type];
35161
35162 mutex_lock(&item->mutex);
35163- BUG_ON(item->refcount == 0);
35164+ BUG_ON(atomic_read(&item->refcount) == 0);
35165 BUG_ON(ref->object != item->object);
35166- if (--item->refcount == 0) {
35167+ if (atomic_dec_and_test(&item->refcount)) {
35168 ref->release(ref);
35169 item->object = NULL;
35170 }
35171diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
35172index d4b20ce..77a8d41 100644
35173--- a/drivers/gpu/drm/drm_info.c
35174+++ b/drivers/gpu/drm/drm_info.c
35175@@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
35176 struct drm_local_map *map;
35177 struct drm_map_list *r_list;
35178
35179- /* Hardcoded from _DRM_FRAME_BUFFER,
35180- _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
35181- _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
35182- const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
35183+ static const char * const types[] = {
35184+ [_DRM_FRAME_BUFFER] = "FB",
35185+ [_DRM_REGISTERS] = "REG",
35186+ [_DRM_SHM] = "SHM",
35187+ [_DRM_AGP] = "AGP",
35188+ [_DRM_SCATTER_GATHER] = "SG",
35189+ [_DRM_CONSISTENT] = "PCI",
35190+ [_DRM_GEM] = "GEM" };
35191 const char *type;
35192 int i;
35193
35194@@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
35195 map = r_list->map;
35196 if (!map)
35197 continue;
35198- if (map->type < 0 || map->type > 5)
35199+ if (map->type >= ARRAY_SIZE(types))
35200 type = "??";
35201 else
35202 type = types[map->type];
35203@@ -253,7 +257,11 @@ int drm_vma_info(struct seq_file *m, void *data)
35204 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
35205 vma->vm_flags & VM_LOCKED ? 'l' : '-',
35206 vma->vm_flags & VM_IO ? 'i' : '-',
35207+#ifdef CONFIG_GRKERNSEC_HIDESYM
35208+ 0);
35209+#else
35210 vma->vm_pgoff);
35211+#endif
35212
35213 #if defined(__i386__)
35214 pgprot = pgprot_val(vma->vm_page_prot);
35215diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
35216index 2f4c434..dd12cd2 100644
35217--- a/drivers/gpu/drm/drm_ioc32.c
35218+++ b/drivers/gpu/drm/drm_ioc32.c
35219@@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
35220 request = compat_alloc_user_space(nbytes);
35221 if (!access_ok(VERIFY_WRITE, request, nbytes))
35222 return -EFAULT;
35223- list = (struct drm_buf_desc *) (request + 1);
35224+ list = (struct drm_buf_desc __user *) (request + 1);
35225
35226 if (__put_user(count, &request->count)
35227 || __put_user(list, &request->list))
35228@@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
35229 request = compat_alloc_user_space(nbytes);
35230 if (!access_ok(VERIFY_WRITE, request, nbytes))
35231 return -EFAULT;
35232- list = (struct drm_buf_pub *) (request + 1);
35233+ list = (struct drm_buf_pub __user *) (request + 1);
35234
35235 if (__put_user(count, &request->count)
35236 || __put_user(list, &request->list))
35237@@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
35238 return 0;
35239 }
35240
35241-drm_ioctl_compat_t *drm_compat_ioctls[] = {
35242+drm_ioctl_compat_t drm_compat_ioctls[] = {
35243 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
35244 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
35245 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
35246@@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
35247 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35248 {
35249 unsigned int nr = DRM_IOCTL_NR(cmd);
35250- drm_ioctl_compat_t *fn;
35251 int ret;
35252
35253 /* Assume that ioctls without an explicit compat routine will just
35254@@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35255 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
35256 return drm_ioctl(filp, cmd, arg);
35257
35258- fn = drm_compat_ioctls[nr];
35259-
35260- if (fn != NULL)
35261- ret = (*fn) (filp, cmd, arg);
35262+ if (drm_compat_ioctls[nr] != NULL)
35263+ ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
35264 else
35265 ret = drm_ioctl(filp, cmd, arg);
35266
35267diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
35268index e77bd8b..1571b85 100644
35269--- a/drivers/gpu/drm/drm_ioctl.c
35270+++ b/drivers/gpu/drm/drm_ioctl.c
35271@@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
35272 stats->data[i].value =
35273 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
35274 else
35275- stats->data[i].value = atomic_read(&dev->counts[i]);
35276+ stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
35277 stats->data[i].type = dev->types[i];
35278 }
35279
35280diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
35281index d752c96..fe08455 100644
35282--- a/drivers/gpu/drm/drm_lock.c
35283+++ b/drivers/gpu/drm/drm_lock.c
35284@@ -86,7 +86,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35285 if (drm_lock_take(&master->lock, lock->context)) {
35286 master->lock.file_priv = file_priv;
35287 master->lock.lock_time = jiffies;
35288- atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
35289+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
35290 break; /* Got lock */
35291 }
35292
35293@@ -157,7 +157,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
35294 return -EINVAL;
35295 }
35296
35297- atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
35298+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
35299
35300 if (drm_lock_free(&master->lock, lock->context)) {
35301 /* FIXME: Should really bail out here. */
35302diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
35303index 7d30802..42c6cbb 100644
35304--- a/drivers/gpu/drm/drm_stub.c
35305+++ b/drivers/gpu/drm/drm_stub.c
35306@@ -501,7 +501,7 @@ void drm_unplug_dev(struct drm_device *dev)
35307
35308 drm_device_set_unplugged(dev);
35309
35310- if (dev->open_count == 0) {
35311+ if (local_read(&dev->open_count) == 0) {
35312 drm_put_dev(dev);
35313 }
35314 mutex_unlock(&drm_global_mutex);
35315diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
35316index 0229665..f61329c 100644
35317--- a/drivers/gpu/drm/drm_sysfs.c
35318+++ b/drivers/gpu/drm/drm_sysfs.c
35319@@ -499,7 +499,7 @@ EXPORT_SYMBOL(drm_sysfs_hotplug_event);
35320 int drm_sysfs_device_add(struct drm_minor *minor)
35321 {
35322 int err;
35323- char *minor_str;
35324+ const char *minor_str;
35325
35326 minor->kdev.parent = minor->dev->dev;
35327
35328diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
35329index 004ecdf..db1f6e0 100644
35330--- a/drivers/gpu/drm/i810/i810_dma.c
35331+++ b/drivers/gpu/drm/i810/i810_dma.c
35332@@ -945,8 +945,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
35333 dma->buflist[vertex->idx],
35334 vertex->discard, vertex->used);
35335
35336- atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35337- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35338+ atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
35339+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35340 sarea_priv->last_enqueue = dev_priv->counter - 1;
35341 sarea_priv->last_dispatch = (int)hw_status[5];
35342
35343@@ -1106,8 +1106,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
35344 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
35345 mc->last_render);
35346
35347- atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35348- atomic_inc(&dev->counts[_DRM_STAT_DMA]);
35349+ atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
35350+ atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
35351 sarea_priv->last_enqueue = dev_priv->counter - 1;
35352 sarea_priv->last_dispatch = (int)hw_status[5];
35353
35354diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
35355index 6e0acad..93c8289 100644
35356--- a/drivers/gpu/drm/i810/i810_drv.h
35357+++ b/drivers/gpu/drm/i810/i810_drv.h
35358@@ -108,8 +108,8 @@ typedef struct drm_i810_private {
35359 int page_flipping;
35360
35361 wait_queue_head_t irq_queue;
35362- atomic_t irq_received;
35363- atomic_t irq_emitted;
35364+ atomic_unchecked_t irq_received;
35365+ atomic_unchecked_t irq_emitted;
35366
35367 int front_offset;
35368 } drm_i810_private_t;
35369diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
35370index 7299ea4..5314487 100644
35371--- a/drivers/gpu/drm/i915/i915_debugfs.c
35372+++ b/drivers/gpu/drm/i915/i915_debugfs.c
35373@@ -499,7 +499,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
35374 I915_READ(GTIMR));
35375 }
35376 seq_printf(m, "Interrupts received: %d\n",
35377- atomic_read(&dev_priv->irq_received));
35378+ atomic_read_unchecked(&dev_priv->irq_received));
35379 for_each_ring(ring, dev_priv, i) {
35380 if (IS_GEN6(dev) || IS_GEN7(dev)) {
35381 seq_printf(m,
35382diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
35383index 4fa6beb..f930fec 100644
35384--- a/drivers/gpu/drm/i915/i915_dma.c
35385+++ b/drivers/gpu/drm/i915/i915_dma.c
35386@@ -1259,7 +1259,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
35387 bool can_switch;
35388
35389 spin_lock(&dev->count_lock);
35390- can_switch = (dev->open_count == 0);
35391+ can_switch = (local_read(&dev->open_count) == 0);
35392 spin_unlock(&dev->count_lock);
35393 return can_switch;
35394 }
35395diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
35396index ef99b1c..09ce7fb 100644
35397--- a/drivers/gpu/drm/i915/i915_drv.h
35398+++ b/drivers/gpu/drm/i915/i915_drv.h
35399@@ -893,7 +893,7 @@ typedef struct drm_i915_private {
35400 drm_dma_handle_t *status_page_dmah;
35401 struct resource mch_res;
35402
35403- atomic_t irq_received;
35404+ atomic_unchecked_t irq_received;
35405
35406 /* protects the irq masks */
35407 spinlock_t irq_lock;
35408@@ -1775,7 +1775,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
35409 struct drm_i915_private *dev_priv, unsigned port);
35410 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
35411 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
35412-extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35413+static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
35414 {
35415 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
35416 }
35417diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35418index 9a48e1a..f0cbc3e 100644
35419--- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35420+++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
35421@@ -729,9 +729,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
35422
35423 static int
35424 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
35425- int count)
35426+ unsigned int count)
35427 {
35428- int i;
35429+ unsigned int i;
35430 int relocs_total = 0;
35431 int relocs_max = INT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
35432
35433@@ -1195,7 +1195,7 @@ i915_gem_execbuffer2(struct drm_device *dev, void *data,
35434 return -ENOMEM;
35435 }
35436 ret = copy_from_user(exec2_list,
35437- (struct drm_i915_relocation_entry __user *)
35438+ (struct drm_i915_gem_exec_object2 __user *)
35439 (uintptr_t) args->buffers_ptr,
35440 sizeof(*exec2_list) * args->buffer_count);
35441 if (ret != 0) {
35442diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
35443index 3c59584..500f2e9 100644
35444--- a/drivers/gpu/drm/i915/i915_ioc32.c
35445+++ b/drivers/gpu/drm/i915/i915_ioc32.c
35446@@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
35447 (unsigned long)request);
35448 }
35449
35450-static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35451+static drm_ioctl_compat_t i915_compat_ioctls[] = {
35452 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
35453 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
35454 [DRM_I915_GETPARAM] = compat_i915_getparam,
35455@@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
35456 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35457 {
35458 unsigned int nr = DRM_IOCTL_NR(cmd);
35459- drm_ioctl_compat_t *fn = NULL;
35460 int ret;
35461
35462 if (nr < DRM_COMMAND_BASE)
35463 return drm_compat_ioctl(filp, cmd, arg);
35464
35465- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
35466- fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35467-
35468- if (fn != NULL)
35469+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
35470+ drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
35471 ret = (*fn) (filp, cmd, arg);
35472- else
35473+ } else
35474 ret = drm_ioctl(filp, cmd, arg);
35475
35476 return ret;
35477diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
35478index 3c7bb04..182e049 100644
35479--- a/drivers/gpu/drm/i915/i915_irq.c
35480+++ b/drivers/gpu/drm/i915/i915_irq.c
35481@@ -549,7 +549,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
35482 int pipe;
35483 u32 pipe_stats[I915_MAX_PIPES];
35484
35485- atomic_inc(&dev_priv->irq_received);
35486+ atomic_inc_unchecked(&dev_priv->irq_received);
35487
35488 while (true) {
35489 iir = I915_READ(VLV_IIR);
35490@@ -705,7 +705,7 @@ static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
35491 irqreturn_t ret = IRQ_NONE;
35492 int i;
35493
35494- atomic_inc(&dev_priv->irq_received);
35495+ atomic_inc_unchecked(&dev_priv->irq_received);
35496
35497 /* disable master interrupt before clearing iir */
35498 de_ier = I915_READ(DEIER);
35499@@ -791,7 +791,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
35500 int ret = IRQ_NONE;
35501 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
35502
35503- atomic_inc(&dev_priv->irq_received);
35504+ atomic_inc_unchecked(&dev_priv->irq_received);
35505
35506 /* disable master interrupt before clearing iir */
35507 de_ier = I915_READ(DEIER);
35508@@ -1886,7 +1886,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
35509 {
35510 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35511
35512- atomic_set(&dev_priv->irq_received, 0);
35513+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35514
35515 I915_WRITE(HWSTAM, 0xeffe);
35516
35517@@ -1912,7 +1912,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
35518 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35519 int pipe;
35520
35521- atomic_set(&dev_priv->irq_received, 0);
35522+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35523
35524 /* VLV magic */
35525 I915_WRITE(VLV_IMR, 0);
35526@@ -2208,7 +2208,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
35527 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35528 int pipe;
35529
35530- atomic_set(&dev_priv->irq_received, 0);
35531+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35532
35533 for_each_pipe(pipe)
35534 I915_WRITE(PIPESTAT(pipe), 0);
35535@@ -2259,7 +2259,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
35536 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
35537 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
35538
35539- atomic_inc(&dev_priv->irq_received);
35540+ atomic_inc_unchecked(&dev_priv->irq_received);
35541
35542 iir = I915_READ16(IIR);
35543 if (iir == 0)
35544@@ -2344,7 +2344,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
35545 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35546 int pipe;
35547
35548- atomic_set(&dev_priv->irq_received, 0);
35549+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35550
35551 if (I915_HAS_HOTPLUG(dev)) {
35552 I915_WRITE(PORT_HOTPLUG_EN, 0);
35553@@ -2448,7 +2448,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
35554 };
35555 int pipe, ret = IRQ_NONE;
35556
35557- atomic_inc(&dev_priv->irq_received);
35558+ atomic_inc_unchecked(&dev_priv->irq_received);
35559
35560 iir = I915_READ(IIR);
35561 do {
35562@@ -2574,7 +2574,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
35563 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
35564 int pipe;
35565
35566- atomic_set(&dev_priv->irq_received, 0);
35567+ atomic_set_unchecked(&dev_priv->irq_received, 0);
35568
35569 I915_WRITE(PORT_HOTPLUG_EN, 0);
35570 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
35571@@ -2690,7 +2690,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
35572 int irq_received;
35573 int ret = IRQ_NONE, pipe;
35574
35575- atomic_inc(&dev_priv->irq_received);
35576+ atomic_inc_unchecked(&dev_priv->irq_received);
35577
35578 iir = I915_READ(IIR);
35579
35580diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
35581index 2ab65b4..acbd821 100644
35582--- a/drivers/gpu/drm/i915/intel_display.c
35583+++ b/drivers/gpu/drm/i915/intel_display.c
35584@@ -8742,13 +8742,13 @@ struct intel_quirk {
35585 int subsystem_vendor;
35586 int subsystem_device;
35587 void (*hook)(struct drm_device *dev);
35588-};
35589+} __do_const;
35590
35591 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
35592 struct intel_dmi_quirk {
35593 void (*hook)(struct drm_device *dev);
35594 const struct dmi_system_id (*dmi_id_list)[];
35595-};
35596+} __do_const;
35597
35598 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35599 {
35600@@ -8756,18 +8756,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
35601 return 1;
35602 }
35603
35604-static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35605+static const struct dmi_system_id intel_dmi_quirks_table[] = {
35606 {
35607- .dmi_id_list = &(const struct dmi_system_id[]) {
35608- {
35609- .callback = intel_dmi_reverse_brightness,
35610- .ident = "NCR Corporation",
35611- .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35612- DMI_MATCH(DMI_PRODUCT_NAME, ""),
35613- },
35614- },
35615- { } /* terminating entry */
35616+ .callback = intel_dmi_reverse_brightness,
35617+ .ident = "NCR Corporation",
35618+ .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
35619+ DMI_MATCH(DMI_PRODUCT_NAME, ""),
35620 },
35621+ },
35622+ { } /* terminating entry */
35623+};
35624+
35625+static const struct intel_dmi_quirk intel_dmi_quirks[] = {
35626+ {
35627+ .dmi_id_list = &intel_dmi_quirks_table,
35628 .hook = quirk_invert_brightness,
35629 },
35630 };
35631diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
35632index 54558a0..2d97005 100644
35633--- a/drivers/gpu/drm/mga/mga_drv.h
35634+++ b/drivers/gpu/drm/mga/mga_drv.h
35635@@ -120,9 +120,9 @@ typedef struct drm_mga_private {
35636 u32 clear_cmd;
35637 u32 maccess;
35638
35639- atomic_t vbl_received; /**< Number of vblanks received. */
35640+ atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
35641 wait_queue_head_t fence_queue;
35642- atomic_t last_fence_retired;
35643+ atomic_unchecked_t last_fence_retired;
35644 u32 next_fence_to_post;
35645
35646 unsigned int fb_cpp;
35647diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
35648index 709e90d..89a1c0d 100644
35649--- a/drivers/gpu/drm/mga/mga_ioc32.c
35650+++ b/drivers/gpu/drm/mga/mga_ioc32.c
35651@@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
35652 return 0;
35653 }
35654
35655-drm_ioctl_compat_t *mga_compat_ioctls[] = {
35656+drm_ioctl_compat_t mga_compat_ioctls[] = {
35657 [DRM_MGA_INIT] = compat_mga_init,
35658 [DRM_MGA_GETPARAM] = compat_mga_getparam,
35659 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
35660@@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
35661 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35662 {
35663 unsigned int nr = DRM_IOCTL_NR(cmd);
35664- drm_ioctl_compat_t *fn = NULL;
35665 int ret;
35666
35667 if (nr < DRM_COMMAND_BASE)
35668 return drm_compat_ioctl(filp, cmd, arg);
35669
35670- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
35671- fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35672-
35673- if (fn != NULL)
35674+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
35675+ drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
35676 ret = (*fn) (filp, cmd, arg);
35677- else
35678+ } else
35679 ret = drm_ioctl(filp, cmd, arg);
35680
35681 return ret;
35682diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
35683index 598c281..60d590e 100644
35684--- a/drivers/gpu/drm/mga/mga_irq.c
35685+++ b/drivers/gpu/drm/mga/mga_irq.c
35686@@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
35687 if (crtc != 0)
35688 return 0;
35689
35690- return atomic_read(&dev_priv->vbl_received);
35691+ return atomic_read_unchecked(&dev_priv->vbl_received);
35692 }
35693
35694
35695@@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35696 /* VBLANK interrupt */
35697 if (status & MGA_VLINEPEN) {
35698 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
35699- atomic_inc(&dev_priv->vbl_received);
35700+ atomic_inc_unchecked(&dev_priv->vbl_received);
35701 drm_handle_vblank(dev, 0);
35702 handled = 1;
35703 }
35704@@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
35705 if ((prim_start & ~0x03) != (prim_end & ~0x03))
35706 MGA_WRITE(MGA_PRIMEND, prim_end);
35707
35708- atomic_inc(&dev_priv->last_fence_retired);
35709+ atomic_inc_unchecked(&dev_priv->last_fence_retired);
35710 DRM_WAKEUP(&dev_priv->fence_queue);
35711 handled = 1;
35712 }
35713@@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
35714 * using fences.
35715 */
35716 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
35717- (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
35718+ (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
35719 - *sequence) <= (1 << 23)));
35720
35721 *sequence = cur_fence;
35722diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
35723index 50a6dd0..ea66ed8 100644
35724--- a/drivers/gpu/drm/nouveau/nouveau_bios.c
35725+++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
35726@@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
35727 struct bit_table {
35728 const char id;
35729 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
35730-};
35731+} __no_const;
35732
35733 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
35734
35735diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
35736index 9c39baf..30a22be 100644
35737--- a/drivers/gpu/drm/nouveau/nouveau_drm.h
35738+++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
35739@@ -81,7 +81,7 @@ struct nouveau_drm {
35740 struct drm_global_reference mem_global_ref;
35741 struct ttm_bo_global_ref bo_global_ref;
35742 struct ttm_bo_device bdev;
35743- atomic_t validate_sequence;
35744+ atomic_unchecked_t validate_sequence;
35745 int (*move)(struct nouveau_channel *,
35746 struct ttm_buffer_object *,
35747 struct ttm_mem_reg *, struct ttm_mem_reg *);
35748diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
35749index b4b4d0c..b7edc15 100644
35750--- a/drivers/gpu/drm/nouveau/nouveau_gem.c
35751+++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
35752@@ -322,7 +322,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
35753 int ret, i;
35754 struct nouveau_bo *res_bo = NULL;
35755
35756- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35757+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35758 retry:
35759 if (++trycnt > 100000) {
35760 NV_ERROR(cli, "%s failed and gave up.\n", __func__);
35761@@ -359,7 +359,7 @@ retry:
35762 if (ret) {
35763 validate_fini(op, NULL);
35764 if (unlikely(ret == -EAGAIN)) {
35765- sequence = atomic_add_return(1, &drm->ttm.validate_sequence);
35766+ sequence = atomic_add_return_unchecked(1, &drm->ttm.validate_sequence);
35767 ret = ttm_bo_reserve_slowpath(&nvbo->bo, true,
35768 sequence);
35769 if (!ret)
35770diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35771index 08214bc..9208577 100644
35772--- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35773+++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
35774@@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
35775 unsigned long arg)
35776 {
35777 unsigned int nr = DRM_IOCTL_NR(cmd);
35778- drm_ioctl_compat_t *fn = NULL;
35779+ drm_ioctl_compat_t fn = NULL;
35780 int ret;
35781
35782 if (nr < DRM_COMMAND_BASE)
35783diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
35784index 25d3495..d81aaf6 100644
35785--- a/drivers/gpu/drm/nouveau/nouveau_vga.c
35786+++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
35787@@ -62,7 +62,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
35788 bool can_switch;
35789
35790 spin_lock(&dev->count_lock);
35791- can_switch = (dev->open_count == 0);
35792+ can_switch = (local_read(&dev->open_count) == 0);
35793 spin_unlock(&dev->count_lock);
35794 return can_switch;
35795 }
35796diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
35797index d4660cf..70dbe65 100644
35798--- a/drivers/gpu/drm/r128/r128_cce.c
35799+++ b/drivers/gpu/drm/r128/r128_cce.c
35800@@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
35801
35802 /* GH: Simple idle check.
35803 */
35804- atomic_set(&dev_priv->idle_count, 0);
35805+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35806
35807 /* We don't support anything other than bus-mastering ring mode,
35808 * but the ring can be in either AGP or PCI space for the ring
35809diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
35810index 930c71b..499aded 100644
35811--- a/drivers/gpu/drm/r128/r128_drv.h
35812+++ b/drivers/gpu/drm/r128/r128_drv.h
35813@@ -90,14 +90,14 @@ typedef struct drm_r128_private {
35814 int is_pci;
35815 unsigned long cce_buffers_offset;
35816
35817- atomic_t idle_count;
35818+ atomic_unchecked_t idle_count;
35819
35820 int page_flipping;
35821 int current_page;
35822 u32 crtc_offset;
35823 u32 crtc_offset_cntl;
35824
35825- atomic_t vbl_received;
35826+ atomic_unchecked_t vbl_received;
35827
35828 u32 color_fmt;
35829 unsigned int front_offset;
35830diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
35831index a954c54..9cc595c 100644
35832--- a/drivers/gpu/drm/r128/r128_ioc32.c
35833+++ b/drivers/gpu/drm/r128/r128_ioc32.c
35834@@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
35835 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
35836 }
35837
35838-drm_ioctl_compat_t *r128_compat_ioctls[] = {
35839+drm_ioctl_compat_t r128_compat_ioctls[] = {
35840 [DRM_R128_INIT] = compat_r128_init,
35841 [DRM_R128_DEPTH] = compat_r128_depth,
35842 [DRM_R128_STIPPLE] = compat_r128_stipple,
35843@@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
35844 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35845 {
35846 unsigned int nr = DRM_IOCTL_NR(cmd);
35847- drm_ioctl_compat_t *fn = NULL;
35848 int ret;
35849
35850 if (nr < DRM_COMMAND_BASE)
35851 return drm_compat_ioctl(filp, cmd, arg);
35852
35853- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
35854- fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35855-
35856- if (fn != NULL)
35857+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
35858+ drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
35859 ret = (*fn) (filp, cmd, arg);
35860- else
35861+ } else
35862 ret = drm_ioctl(filp, cmd, arg);
35863
35864 return ret;
35865diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
35866index 2ea4f09..d391371 100644
35867--- a/drivers/gpu/drm/r128/r128_irq.c
35868+++ b/drivers/gpu/drm/r128/r128_irq.c
35869@@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
35870 if (crtc != 0)
35871 return 0;
35872
35873- return atomic_read(&dev_priv->vbl_received);
35874+ return atomic_read_unchecked(&dev_priv->vbl_received);
35875 }
35876
35877 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35878@@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
35879 /* VBLANK interrupt */
35880 if (status & R128_CRTC_VBLANK_INT) {
35881 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
35882- atomic_inc(&dev_priv->vbl_received);
35883+ atomic_inc_unchecked(&dev_priv->vbl_received);
35884 drm_handle_vblank(dev, 0);
35885 return IRQ_HANDLED;
35886 }
35887diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
35888index 19bb7e6..de7e2a2 100644
35889--- a/drivers/gpu/drm/r128/r128_state.c
35890+++ b/drivers/gpu/drm/r128/r128_state.c
35891@@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
35892
35893 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
35894 {
35895- if (atomic_read(&dev_priv->idle_count) == 0)
35896+ if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
35897 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
35898 else
35899- atomic_set(&dev_priv->idle_count, 0);
35900+ atomic_set_unchecked(&dev_priv->idle_count, 0);
35901 }
35902
35903 #endif
35904diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
35905index 5a82b6b..9e69c73 100644
35906--- a/drivers/gpu/drm/radeon/mkregtable.c
35907+++ b/drivers/gpu/drm/radeon/mkregtable.c
35908@@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
35909 regex_t mask_rex;
35910 regmatch_t match[4];
35911 char buf[1024];
35912- size_t end;
35913+ long end;
35914 int len;
35915 int done = 0;
35916 int r;
35917 unsigned o;
35918 struct offset *offset;
35919 char last_reg_s[10];
35920- int last_reg;
35921+ unsigned long last_reg;
35922
35923 if (regcomp
35924 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
35925diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
35926index 5073665..31d15a6 100644
35927--- a/drivers/gpu/drm/radeon/radeon_device.c
35928+++ b/drivers/gpu/drm/radeon/radeon_device.c
35929@@ -976,7 +976,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
35930 bool can_switch;
35931
35932 spin_lock(&dev->count_lock);
35933- can_switch = (dev->open_count == 0);
35934+ can_switch = (local_read(&dev->open_count) == 0);
35935 spin_unlock(&dev->count_lock);
35936 return can_switch;
35937 }
35938diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
35939index b369d42..8dd04eb 100644
35940--- a/drivers/gpu/drm/radeon/radeon_drv.h
35941+++ b/drivers/gpu/drm/radeon/radeon_drv.h
35942@@ -258,7 +258,7 @@ typedef struct drm_radeon_private {
35943
35944 /* SW interrupt */
35945 wait_queue_head_t swi_queue;
35946- atomic_t swi_emitted;
35947+ atomic_unchecked_t swi_emitted;
35948 int vblank_crtc;
35949 uint32_t irq_enable_reg;
35950 uint32_t r500_disp_irq_reg;
35951diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
35952index c180df8..5fd8186 100644
35953--- a/drivers/gpu/drm/radeon/radeon_ioc32.c
35954+++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
35955@@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35956 request = compat_alloc_user_space(sizeof(*request));
35957 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
35958 || __put_user(req32.param, &request->param)
35959- || __put_user((void __user *)(unsigned long)req32.value,
35960+ || __put_user((unsigned long)req32.value,
35961 &request->value))
35962 return -EFAULT;
35963
35964@@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
35965 #define compat_radeon_cp_setparam NULL
35966 #endif /* X86_64 || IA64 */
35967
35968-static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35969+static drm_ioctl_compat_t radeon_compat_ioctls[] = {
35970 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
35971 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
35972 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
35973@@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
35974 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
35975 {
35976 unsigned int nr = DRM_IOCTL_NR(cmd);
35977- drm_ioctl_compat_t *fn = NULL;
35978 int ret;
35979
35980 if (nr < DRM_COMMAND_BASE)
35981 return drm_compat_ioctl(filp, cmd, arg);
35982
35983- if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
35984- fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35985-
35986- if (fn != NULL)
35987+ if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
35988+ drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
35989 ret = (*fn) (filp, cmd, arg);
35990- else
35991+ } else
35992 ret = drm_ioctl(filp, cmd, arg);
35993
35994 return ret;
35995diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
35996index 8d68e97..9dcfed8 100644
35997--- a/drivers/gpu/drm/radeon/radeon_irq.c
35998+++ b/drivers/gpu/drm/radeon/radeon_irq.c
35999@@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
36000 unsigned int ret;
36001 RING_LOCALS;
36002
36003- atomic_inc(&dev_priv->swi_emitted);
36004- ret = atomic_read(&dev_priv->swi_emitted);
36005+ atomic_inc_unchecked(&dev_priv->swi_emitted);
36006+ ret = atomic_read_unchecked(&dev_priv->swi_emitted);
36007
36008 BEGIN_RING(4);
36009 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
36010@@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
36011 drm_radeon_private_t *dev_priv =
36012 (drm_radeon_private_t *) dev->dev_private;
36013
36014- atomic_set(&dev_priv->swi_emitted, 0);
36015+ atomic_set_unchecked(&dev_priv->swi_emitted, 0);
36016 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
36017
36018 dev->max_vblank_count = 0x001fffff;
36019diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
36020index 4d20910..6726b6d 100644
36021--- a/drivers/gpu/drm/radeon/radeon_state.c
36022+++ b/drivers/gpu/drm/radeon/radeon_state.c
36023@@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
36024 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
36025 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
36026
36027- if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36028+ if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
36029 sarea_priv->nbox * sizeof(depth_boxes[0])))
36030 return -EFAULT;
36031
36032@@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
36033 {
36034 drm_radeon_private_t *dev_priv = dev->dev_private;
36035 drm_radeon_getparam_t *param = data;
36036- int value;
36037+ int value = 0;
36038
36039 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
36040
36041diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
36042index 6c0ce89..66f6d65 100644
36043--- a/drivers/gpu/drm/radeon/radeon_ttm.c
36044+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
36045@@ -782,7 +782,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
36046 man->size = size >> PAGE_SHIFT;
36047 }
36048
36049-static struct vm_operations_struct radeon_ttm_vm_ops;
36050+static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
36051 static const struct vm_operations_struct *ttm_vm_ops = NULL;
36052
36053 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
36054@@ -823,8 +823,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
36055 }
36056 if (unlikely(ttm_vm_ops == NULL)) {
36057 ttm_vm_ops = vma->vm_ops;
36058+ pax_open_kernel();
36059 radeon_ttm_vm_ops = *ttm_vm_ops;
36060 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
36061+ pax_close_kernel();
36062 }
36063 vma->vm_ops = &radeon_ttm_vm_ops;
36064 return 0;
36065@@ -862,28 +864,33 @@ static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
36066 sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
36067 else
36068 sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
36069- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36070- radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36071- radeon_mem_types_list[i].driver_features = 0;
36072+ pax_open_kernel();
36073+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36074+ *(void **)&radeon_mem_types_list[i].show = &radeon_mm_dump_table;
36075+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36076 if (i == 0)
36077- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36078+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
36079 else
36080- radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36081-
36082+ *(void **)&radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
36083+ pax_close_kernel();
36084 }
36085 /* Add ttm page pool to debugfs */
36086 sprintf(radeon_mem_types_names[i], "ttm_page_pool");
36087- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36088- radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36089- radeon_mem_types_list[i].driver_features = 0;
36090- radeon_mem_types_list[i++].data = NULL;
36091+ pax_open_kernel();
36092+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36093+ *(void **)&radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
36094+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36095+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36096+ pax_close_kernel();
36097 #ifdef CONFIG_SWIOTLB
36098 if (swiotlb_nr_tbl()) {
36099 sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
36100- radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36101- radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36102- radeon_mem_types_list[i].driver_features = 0;
36103- radeon_mem_types_list[i++].data = NULL;
36104+ pax_open_kernel();
36105+ *(const char **)&radeon_mem_types_list[i].name = radeon_mem_types_names[i];
36106+ *(void **)&radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
36107+ *(u32 *)&radeon_mem_types_list[i].driver_features = 0;
36108+ *(void **)&radeon_mem_types_list[i++].data = NULL;
36109+ pax_close_kernel();
36110 }
36111 #endif
36112 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
36113diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
36114index fad6633..4ff94de 100644
36115--- a/drivers/gpu/drm/radeon/rs690.c
36116+++ b/drivers/gpu/drm/radeon/rs690.c
36117@@ -304,9 +304,11 @@ static void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
36118 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
36119 rdev->pm.sideport_bandwidth.full)
36120 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
36121- read_delay_latency.full = dfixed_const(370 * 800 * 1000);
36122+ read_delay_latency.full = dfixed_const(800 * 1000);
36123 read_delay_latency.full = dfixed_div(read_delay_latency,
36124 rdev->pm.igp_sideport_mclk);
36125+ a.full = dfixed_const(370);
36126+ read_delay_latency.full = dfixed_mul(read_delay_latency, a);
36127 } else {
36128 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
36129 rdev->pm.k8_bandwidth.full)
36130diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
36131index dbc2def..0a9f710 100644
36132--- a/drivers/gpu/drm/ttm/ttm_memory.c
36133+++ b/drivers/gpu/drm/ttm/ttm_memory.c
36134@@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
36135 zone->glob = glob;
36136 glob->zone_kernel = zone;
36137 ret = kobject_init_and_add(
36138- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36139+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36140 if (unlikely(ret != 0)) {
36141 kobject_put(&zone->kobj);
36142 return ret;
36143@@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
36144 zone->glob = glob;
36145 glob->zone_dma32 = zone;
36146 ret = kobject_init_and_add(
36147- &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
36148+ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
36149 if (unlikely(ret != 0)) {
36150 kobject_put(&zone->kobj);
36151 return ret;
36152diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36153index bd2a3b4..122d9ad 100644
36154--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
36155+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
36156@@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
36157 static int ttm_pool_mm_shrink(struct shrinker *shrink,
36158 struct shrink_control *sc)
36159 {
36160- static atomic_t start_pool = ATOMIC_INIT(0);
36161+ static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
36162 unsigned i;
36163- unsigned pool_offset = atomic_add_return(1, &start_pool);
36164+ unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
36165 struct ttm_page_pool *pool;
36166 int shrink_pages = sc->nr_to_scan;
36167
36168diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
36169index 9f4be3d..cbc9fcc 100644
36170--- a/drivers/gpu/drm/udl/udl_fb.c
36171+++ b/drivers/gpu/drm/udl/udl_fb.c
36172@@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
36173 fb_deferred_io_cleanup(info);
36174 kfree(info->fbdefio);
36175 info->fbdefio = NULL;
36176- info->fbops->fb_mmap = udl_fb_mmap;
36177 }
36178
36179 pr_warn("released /dev/fb%d user=%d count=%d\n",
36180diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
36181index 893a650..6190d3b 100644
36182--- a/drivers/gpu/drm/via/via_drv.h
36183+++ b/drivers/gpu/drm/via/via_drv.h
36184@@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
36185 typedef uint32_t maskarray_t[5];
36186
36187 typedef struct drm_via_irq {
36188- atomic_t irq_received;
36189+ atomic_unchecked_t irq_received;
36190 uint32_t pending_mask;
36191 uint32_t enable_mask;
36192 wait_queue_head_t irq_queue;
36193@@ -75,7 +75,7 @@ typedef struct drm_via_private {
36194 struct timeval last_vblank;
36195 int last_vblank_valid;
36196 unsigned usec_per_vblank;
36197- atomic_t vbl_received;
36198+ atomic_unchecked_t vbl_received;
36199 drm_via_state_t hc_state;
36200 char pci_buf[VIA_PCI_BUF_SIZE];
36201 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
36202diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
36203index ac98964..5dbf512 100644
36204--- a/drivers/gpu/drm/via/via_irq.c
36205+++ b/drivers/gpu/drm/via/via_irq.c
36206@@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
36207 if (crtc != 0)
36208 return 0;
36209
36210- return atomic_read(&dev_priv->vbl_received);
36211+ return atomic_read_unchecked(&dev_priv->vbl_received);
36212 }
36213
36214 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36215@@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36216
36217 status = VIA_READ(VIA_REG_INTERRUPT);
36218 if (status & VIA_IRQ_VBLANK_PENDING) {
36219- atomic_inc(&dev_priv->vbl_received);
36220- if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
36221+ atomic_inc_unchecked(&dev_priv->vbl_received);
36222+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
36223 do_gettimeofday(&cur_vblank);
36224 if (dev_priv->last_vblank_valid) {
36225 dev_priv->usec_per_vblank =
36226@@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36227 dev_priv->last_vblank = cur_vblank;
36228 dev_priv->last_vblank_valid = 1;
36229 }
36230- if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
36231+ if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
36232 DRM_DEBUG("US per vblank is: %u\n",
36233 dev_priv->usec_per_vblank);
36234 }
36235@@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
36236
36237 for (i = 0; i < dev_priv->num_irqs; ++i) {
36238 if (status & cur_irq->pending_mask) {
36239- atomic_inc(&cur_irq->irq_received);
36240+ atomic_inc_unchecked(&cur_irq->irq_received);
36241 DRM_WAKEUP(&cur_irq->irq_queue);
36242 handled = 1;
36243 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
36244@@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
36245 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36246 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
36247 masks[irq][4]));
36248- cur_irq_sequence = atomic_read(&cur_irq->irq_received);
36249+ cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
36250 } else {
36251 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
36252 (((cur_irq_sequence =
36253- atomic_read(&cur_irq->irq_received)) -
36254+ atomic_read_unchecked(&cur_irq->irq_received)) -
36255 *sequence) <= (1 << 23)));
36256 }
36257 *sequence = cur_irq_sequence;
36258@@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
36259 }
36260
36261 for (i = 0; i < dev_priv->num_irqs; ++i) {
36262- atomic_set(&cur_irq->irq_received, 0);
36263+ atomic_set_unchecked(&cur_irq->irq_received, 0);
36264 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
36265 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
36266 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
36267@@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
36268 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
36269 case VIA_IRQ_RELATIVE:
36270 irqwait->request.sequence +=
36271- atomic_read(&cur_irq->irq_received);
36272+ atomic_read_unchecked(&cur_irq->irq_received);
36273 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
36274 case VIA_IRQ_ABSOLUTE:
36275 break;
36276diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36277index 13aeda7..4a952d1 100644
36278--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36279+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
36280@@ -290,7 +290,7 @@ struct vmw_private {
36281 * Fencing and IRQs.
36282 */
36283
36284- atomic_t marker_seq;
36285+ atomic_unchecked_t marker_seq;
36286 wait_queue_head_t fence_queue;
36287 wait_queue_head_t fifo_queue;
36288 int fence_queue_waiters; /* Protected by hw_mutex */
36289diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36290index 3eb1486..0a47ee9 100644
36291--- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36292+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
36293@@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
36294 (unsigned int) min,
36295 (unsigned int) fifo->capabilities);
36296
36297- atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36298+ atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
36299 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
36300 vmw_marker_queue_init(&fifo->marker_queue);
36301 return vmw_fifo_send_fence(dev_priv, &dummy);
36302@@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
36303 if (reserveable)
36304 iowrite32(bytes, fifo_mem +
36305 SVGA_FIFO_RESERVED);
36306- return fifo_mem + (next_cmd >> 2);
36307+ return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
36308 } else {
36309 need_bounce = true;
36310 }
36311@@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36312
36313 fm = vmw_fifo_reserve(dev_priv, bytes);
36314 if (unlikely(fm == NULL)) {
36315- *seqno = atomic_read(&dev_priv->marker_seq);
36316+ *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36317 ret = -ENOMEM;
36318 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
36319 false, 3*HZ);
36320@@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
36321 }
36322
36323 do {
36324- *seqno = atomic_add_return(1, &dev_priv->marker_seq);
36325+ *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
36326 } while (*seqno == 0);
36327
36328 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
36329diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36330index c509d40..3b640c3 100644
36331--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36332+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
36333@@ -138,7 +138,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
36334 int ret;
36335
36336 num_clips = arg->num_clips;
36337- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36338+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36339
36340 if (unlikely(num_clips == 0))
36341 return 0;
36342@@ -222,7 +222,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
36343 int ret;
36344
36345 num_clips = arg->num_clips;
36346- clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
36347+ clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
36348
36349 if (unlikely(num_clips == 0))
36350 return 0;
36351diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36352index 4640adb..e1384ed 100644
36353--- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36354+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
36355@@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
36356 * emitted. Then the fence is stale and signaled.
36357 */
36358
36359- ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
36360+ ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
36361 > VMW_FENCE_WRAP);
36362
36363 return ret;
36364@@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
36365
36366 if (fifo_idle)
36367 down_read(&fifo_state->rwsem);
36368- signal_seq = atomic_read(&dev_priv->marker_seq);
36369+ signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
36370 ret = 0;
36371
36372 for (;;) {
36373diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36374index 8a8725c2..afed796 100644
36375--- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36376+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
36377@@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
36378 while (!vmw_lag_lt(queue, us)) {
36379 spin_lock(&queue->lock);
36380 if (list_empty(&queue->head))
36381- seqno = atomic_read(&dev_priv->marker_seq);
36382+ seqno = atomic_read_unchecked(&dev_priv->marker_seq);
36383 else {
36384 marker = list_first_entry(&queue->head,
36385 struct vmw_marker, head);
36386diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
36387index e6dbf09..3dd2540 100644
36388--- a/drivers/hid/hid-core.c
36389+++ b/drivers/hid/hid-core.c
36390@@ -2268,7 +2268,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
36391
36392 int hid_add_device(struct hid_device *hdev)
36393 {
36394- static atomic_t id = ATOMIC_INIT(0);
36395+ static atomic_unchecked_t id = ATOMIC_INIT(0);
36396 int ret;
36397
36398 if (WARN_ON(hdev->status & HID_STAT_ADDED))
36399@@ -2302,7 +2302,7 @@ int hid_add_device(struct hid_device *hdev)
36400 /* XXX hack, any other cleaner solution after the driver core
36401 * is converted to allow more than 20 bytes as the device name? */
36402 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
36403- hdev->vendor, hdev->product, atomic_inc_return(&id));
36404+ hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
36405
36406 hid_debug_register(hdev, dev_name(&hdev->dev));
36407 ret = device_add(&hdev->dev);
36408diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
36409index 90124ff..3761764 100644
36410--- a/drivers/hid/hid-wiimote-debug.c
36411+++ b/drivers/hid/hid-wiimote-debug.c
36412@@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
36413 else if (size == 0)
36414 return -EIO;
36415
36416- if (copy_to_user(u, buf, size))
36417+ if (size > sizeof(buf) || copy_to_user(u, buf, size))
36418 return -EFAULT;
36419
36420 *off += size;
36421diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
36422index 0b122f8..b1d8160 100644
36423--- a/drivers/hv/channel.c
36424+++ b/drivers/hv/channel.c
36425@@ -394,8 +394,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
36426 int ret = 0;
36427 int t;
36428
36429- next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
36430- atomic_inc(&vmbus_connection.next_gpadl_handle);
36431+ next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
36432+ atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
36433
36434 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
36435 if (ret)
36436diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
36437index 7311589..861e9ef 100644
36438--- a/drivers/hv/hv.c
36439+++ b/drivers/hv/hv.c
36440@@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
36441 u64 output_address = (output) ? virt_to_phys(output) : 0;
36442 u32 output_address_hi = output_address >> 32;
36443 u32 output_address_lo = output_address & 0xFFFFFFFF;
36444- void *hypercall_page = hv_context.hypercall_page;
36445+ void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
36446
36447 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
36448 "=a"(hv_status_lo) : "d" (control_hi),
36449diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
36450index 12f2f9e..679603c 100644
36451--- a/drivers/hv/hyperv_vmbus.h
36452+++ b/drivers/hv/hyperv_vmbus.h
36453@@ -591,7 +591,7 @@ enum vmbus_connect_state {
36454 struct vmbus_connection {
36455 enum vmbus_connect_state conn_state;
36456
36457- atomic_t next_gpadl_handle;
36458+ atomic_unchecked_t next_gpadl_handle;
36459
36460 /*
36461 * Represents channel interrupts. Each bit position represents a
36462diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
36463index bf421e0..ce2c897 100644
36464--- a/drivers/hv/vmbus_drv.c
36465+++ b/drivers/hv/vmbus_drv.c
36466@@ -668,10 +668,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
36467 {
36468 int ret = 0;
36469
36470- static atomic_t device_num = ATOMIC_INIT(0);
36471+ static atomic_unchecked_t device_num = ATOMIC_INIT(0);
36472
36473 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
36474- atomic_inc_return(&device_num));
36475+ atomic_inc_return_unchecked(&device_num));
36476
36477 child_device_obj->device.bus = &hv_bus;
36478 child_device_obj->device.parent = &hv_acpi_dev->dev;
36479diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
36480index 6351aba..dc4aaf4 100644
36481--- a/drivers/hwmon/acpi_power_meter.c
36482+++ b/drivers/hwmon/acpi_power_meter.c
36483@@ -117,7 +117,7 @@ struct sensor_template {
36484 struct device_attribute *devattr,
36485 const char *buf, size_t count);
36486 int index;
36487-};
36488+} __do_const;
36489
36490 /* Averaging interval */
36491 static int update_avg_interval(struct acpi_power_meter_resource *resource)
36492@@ -629,7 +629,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
36493 struct sensor_template *attrs)
36494 {
36495 struct device *dev = &resource->acpi_dev->dev;
36496- struct sensor_device_attribute *sensors =
36497+ sensor_device_attribute_no_const *sensors =
36498 &resource->sensors[resource->num_sensors];
36499 int res = 0;
36500
36501diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
36502index b41baff..4953e4d 100644
36503--- a/drivers/hwmon/applesmc.c
36504+++ b/drivers/hwmon/applesmc.c
36505@@ -1084,7 +1084,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
36506 {
36507 struct applesmc_node_group *grp;
36508 struct applesmc_dev_attr *node;
36509- struct attribute *attr;
36510+ attribute_no_const *attr;
36511 int ret, i;
36512
36513 for (grp = groups; grp->format; grp++) {
36514diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
36515index b25c643..a13460d 100644
36516--- a/drivers/hwmon/asus_atk0110.c
36517+++ b/drivers/hwmon/asus_atk0110.c
36518@@ -152,10 +152,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
36519 struct atk_sensor_data {
36520 struct list_head list;
36521 struct atk_data *data;
36522- struct device_attribute label_attr;
36523- struct device_attribute input_attr;
36524- struct device_attribute limit1_attr;
36525- struct device_attribute limit2_attr;
36526+ device_attribute_no_const label_attr;
36527+ device_attribute_no_const input_attr;
36528+ device_attribute_no_const limit1_attr;
36529+ device_attribute_no_const limit2_attr;
36530 char label_attr_name[ATTR_NAME_SIZE];
36531 char input_attr_name[ATTR_NAME_SIZE];
36532 char limit1_attr_name[ATTR_NAME_SIZE];
36533@@ -275,7 +275,7 @@ static ssize_t atk_name_show(struct device *dev,
36534 static struct device_attribute atk_name_attr =
36535 __ATTR(name, 0444, atk_name_show, NULL);
36536
36537-static void atk_init_attribute(struct device_attribute *attr, char *name,
36538+static void atk_init_attribute(device_attribute_no_const *attr, char *name,
36539 sysfs_show_func show)
36540 {
36541 sysfs_attr_init(&attr->attr);
36542diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
36543index 3f1e297..a6cafb5 100644
36544--- a/drivers/hwmon/coretemp.c
36545+++ b/drivers/hwmon/coretemp.c
36546@@ -791,7 +791,7 @@ static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb,
36547 return NOTIFY_OK;
36548 }
36549
36550-static struct notifier_block coretemp_cpu_notifier __refdata = {
36551+static struct notifier_block coretemp_cpu_notifier = {
36552 .notifier_call = coretemp_cpu_callback,
36553 };
36554
36555diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
36556index a14f634..2916ee2 100644
36557--- a/drivers/hwmon/ibmaem.c
36558+++ b/drivers/hwmon/ibmaem.c
36559@@ -925,7 +925,7 @@ static int aem_register_sensors(struct aem_data *data,
36560 struct aem_rw_sensor_template *rw)
36561 {
36562 struct device *dev = &data->pdev->dev;
36563- struct sensor_device_attribute *sensors = data->sensors;
36564+ sensor_device_attribute_no_const *sensors = data->sensors;
36565 int err;
36566
36567 /* Set up read-only sensors */
36568diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
36569index 9add6092..ee7ba3f 100644
36570--- a/drivers/hwmon/pmbus/pmbus_core.c
36571+++ b/drivers/hwmon/pmbus/pmbus_core.c
36572@@ -781,7 +781,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
36573 return 0;
36574 }
36575
36576-static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36577+static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
36578 const char *name,
36579 umode_t mode,
36580 ssize_t (*show)(struct device *dev,
36581@@ -798,7 +798,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
36582 dev_attr->store = store;
36583 }
36584
36585-static void pmbus_attr_init(struct sensor_device_attribute *a,
36586+static void pmbus_attr_init(sensor_device_attribute_no_const *a,
36587 const char *name,
36588 umode_t mode,
36589 ssize_t (*show)(struct device *dev,
36590@@ -820,7 +820,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
36591 u16 reg, u8 mask)
36592 {
36593 struct pmbus_boolean *boolean;
36594- struct sensor_device_attribute *a;
36595+ sensor_device_attribute_no_const *a;
36596
36597 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
36598 if (!boolean)
36599@@ -845,7 +845,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
36600 bool update, bool readonly)
36601 {
36602 struct pmbus_sensor *sensor;
36603- struct device_attribute *a;
36604+ device_attribute_no_const *a;
36605
36606 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
36607 if (!sensor)
36608@@ -876,7 +876,7 @@ static int pmbus_add_label(struct pmbus_data *data,
36609 const char *lstring, int index)
36610 {
36611 struct pmbus_label *label;
36612- struct device_attribute *a;
36613+ device_attribute_no_const *a;
36614
36615 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
36616 if (!label)
36617diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
36618index 2507f90..1645765 100644
36619--- a/drivers/hwmon/sht15.c
36620+++ b/drivers/hwmon/sht15.c
36621@@ -169,7 +169,7 @@ struct sht15_data {
36622 int supply_uv;
36623 bool supply_uv_valid;
36624 struct work_struct update_supply_work;
36625- atomic_t interrupt_handled;
36626+ atomic_unchecked_t interrupt_handled;
36627 };
36628
36629 /**
36630@@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
36631 ret = gpio_direction_input(data->pdata->gpio_data);
36632 if (ret)
36633 return ret;
36634- atomic_set(&data->interrupt_handled, 0);
36635+ atomic_set_unchecked(&data->interrupt_handled, 0);
36636
36637 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36638 if (gpio_get_value(data->pdata->gpio_data) == 0) {
36639 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
36640 /* Only relevant if the interrupt hasn't occurred. */
36641- if (!atomic_read(&data->interrupt_handled))
36642+ if (!atomic_read_unchecked(&data->interrupt_handled))
36643 schedule_work(&data->read_work);
36644 }
36645 ret = wait_event_timeout(data->wait_queue,
36646@@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
36647
36648 /* First disable the interrupt */
36649 disable_irq_nosync(irq);
36650- atomic_inc(&data->interrupt_handled);
36651+ atomic_inc_unchecked(&data->interrupt_handled);
36652 /* Then schedule a reading work struct */
36653 if (data->state != SHT15_READING_NOTHING)
36654 schedule_work(&data->read_work);
36655@@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
36656 * If not, then start the interrupt again - care here as could
36657 * have gone low in meantime so verify it hasn't!
36658 */
36659- atomic_set(&data->interrupt_handled, 0);
36660+ atomic_set_unchecked(&data->interrupt_handled, 0);
36661 enable_irq(gpio_to_irq(data->pdata->gpio_data));
36662 /* If still not occurred or another handler was scheduled */
36663 if (gpio_get_value(data->pdata->gpio_data)
36664- || atomic_read(&data->interrupt_handled))
36665+ || atomic_read_unchecked(&data->interrupt_handled))
36666 return;
36667 }
36668
36669diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
36670index 76f157b..9c0db1b 100644
36671--- a/drivers/hwmon/via-cputemp.c
36672+++ b/drivers/hwmon/via-cputemp.c
36673@@ -296,7 +296,7 @@ static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb,
36674 return NOTIFY_OK;
36675 }
36676
36677-static struct notifier_block via_cputemp_cpu_notifier __refdata = {
36678+static struct notifier_block via_cputemp_cpu_notifier = {
36679 .notifier_call = via_cputemp_cpu_callback,
36680 };
36681
36682diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
36683index 378fcb5..5e91fa8 100644
36684--- a/drivers/i2c/busses/i2c-amd756-s4882.c
36685+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
36686@@ -43,7 +43,7 @@
36687 extern struct i2c_adapter amd756_smbus;
36688
36689 static struct i2c_adapter *s4882_adapter;
36690-static struct i2c_algorithm *s4882_algo;
36691+static i2c_algorithm_no_const *s4882_algo;
36692
36693 /* Wrapper access functions for multiplexed SMBus */
36694 static DEFINE_MUTEX(amd756_lock);
36695diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
36696index 29015eb..af2d8e9 100644
36697--- a/drivers/i2c/busses/i2c-nforce2-s4985.c
36698+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
36699@@ -41,7 +41,7 @@
36700 extern struct i2c_adapter *nforce2_smbus;
36701
36702 static struct i2c_adapter *s4985_adapter;
36703-static struct i2c_algorithm *s4985_algo;
36704+static i2c_algorithm_no_const *s4985_algo;
36705
36706 /* Wrapper access functions for multiplexed SMBus */
36707 static DEFINE_MUTEX(nforce2_lock);
36708diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
36709index c3ccdea..5b3dc1a 100644
36710--- a/drivers/i2c/i2c-dev.c
36711+++ b/drivers/i2c/i2c-dev.c
36712@@ -271,7 +271,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
36713 break;
36714 }
36715
36716- data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
36717+ data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
36718 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
36719 if (IS_ERR(rdwr_pa[i].buf)) {
36720 res = PTR_ERR(rdwr_pa[i].buf);
36721diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
36722index 8126824..55a2798 100644
36723--- a/drivers/ide/ide-cd.c
36724+++ b/drivers/ide/ide-cd.c
36725@@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
36726 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
36727 if ((unsigned long)buf & alignment
36728 || blk_rq_bytes(rq) & q->dma_pad_mask
36729- || object_is_on_stack(buf))
36730+ || object_starts_on_stack(buf))
36731 drive->dma = 0;
36732 }
36733 }
36734diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
36735index 8848f16..f8e6dd8 100644
36736--- a/drivers/iio/industrialio-core.c
36737+++ b/drivers/iio/industrialio-core.c
36738@@ -506,7 +506,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
36739 }
36740
36741 static
36742-int __iio_device_attr_init(struct device_attribute *dev_attr,
36743+int __iio_device_attr_init(device_attribute_no_const *dev_attr,
36744 const char *postfix,
36745 struct iio_chan_spec const *chan,
36746 ssize_t (*readfunc)(struct device *dev,
36747diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
36748index 784b97c..c9ceadf 100644
36749--- a/drivers/infiniband/core/cm.c
36750+++ b/drivers/infiniband/core/cm.c
36751@@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
36752
36753 struct cm_counter_group {
36754 struct kobject obj;
36755- atomic_long_t counter[CM_ATTR_COUNT];
36756+ atomic_long_unchecked_t counter[CM_ATTR_COUNT];
36757 };
36758
36759 struct cm_counter_attribute {
36760@@ -1395,7 +1395,7 @@ static void cm_dup_req_handler(struct cm_work *work,
36761 struct ib_mad_send_buf *msg = NULL;
36762 int ret;
36763
36764- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36765+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36766 counter[CM_REQ_COUNTER]);
36767
36768 /* Quick state check to discard duplicate REQs. */
36769@@ -1779,7 +1779,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
36770 if (!cm_id_priv)
36771 return;
36772
36773- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36774+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36775 counter[CM_REP_COUNTER]);
36776 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
36777 if (ret)
36778@@ -1946,7 +1946,7 @@ static int cm_rtu_handler(struct cm_work *work)
36779 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
36780 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
36781 spin_unlock_irq(&cm_id_priv->lock);
36782- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36783+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36784 counter[CM_RTU_COUNTER]);
36785 goto out;
36786 }
36787@@ -2129,7 +2129,7 @@ static int cm_dreq_handler(struct cm_work *work)
36788 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
36789 dreq_msg->local_comm_id);
36790 if (!cm_id_priv) {
36791- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36792+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36793 counter[CM_DREQ_COUNTER]);
36794 cm_issue_drep(work->port, work->mad_recv_wc);
36795 return -EINVAL;
36796@@ -2154,7 +2154,7 @@ static int cm_dreq_handler(struct cm_work *work)
36797 case IB_CM_MRA_REP_RCVD:
36798 break;
36799 case IB_CM_TIMEWAIT:
36800- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36801+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36802 counter[CM_DREQ_COUNTER]);
36803 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36804 goto unlock;
36805@@ -2168,7 +2168,7 @@ static int cm_dreq_handler(struct cm_work *work)
36806 cm_free_msg(msg);
36807 goto deref;
36808 case IB_CM_DREQ_RCVD:
36809- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36810+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36811 counter[CM_DREQ_COUNTER]);
36812 goto unlock;
36813 default:
36814@@ -2535,7 +2535,7 @@ static int cm_mra_handler(struct cm_work *work)
36815 ib_modify_mad(cm_id_priv->av.port->mad_agent,
36816 cm_id_priv->msg, timeout)) {
36817 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
36818- atomic_long_inc(&work->port->
36819+ atomic_long_inc_unchecked(&work->port->
36820 counter_group[CM_RECV_DUPLICATES].
36821 counter[CM_MRA_COUNTER]);
36822 goto out;
36823@@ -2544,7 +2544,7 @@ static int cm_mra_handler(struct cm_work *work)
36824 break;
36825 case IB_CM_MRA_REQ_RCVD:
36826 case IB_CM_MRA_REP_RCVD:
36827- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36828+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36829 counter[CM_MRA_COUNTER]);
36830 /* fall through */
36831 default:
36832@@ -2706,7 +2706,7 @@ static int cm_lap_handler(struct cm_work *work)
36833 case IB_CM_LAP_IDLE:
36834 break;
36835 case IB_CM_MRA_LAP_SENT:
36836- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36837+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36838 counter[CM_LAP_COUNTER]);
36839 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
36840 goto unlock;
36841@@ -2722,7 +2722,7 @@ static int cm_lap_handler(struct cm_work *work)
36842 cm_free_msg(msg);
36843 goto deref;
36844 case IB_CM_LAP_RCVD:
36845- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36846+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36847 counter[CM_LAP_COUNTER]);
36848 goto unlock;
36849 default:
36850@@ -3006,7 +3006,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
36851 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
36852 if (cur_cm_id_priv) {
36853 spin_unlock_irq(&cm.lock);
36854- atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
36855+ atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
36856 counter[CM_SIDR_REQ_COUNTER]);
36857 goto out; /* Duplicate message. */
36858 }
36859@@ -3218,10 +3218,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
36860 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
36861 msg->retries = 1;
36862
36863- atomic_long_add(1 + msg->retries,
36864+ atomic_long_add_unchecked(1 + msg->retries,
36865 &port->counter_group[CM_XMIT].counter[attr_index]);
36866 if (msg->retries)
36867- atomic_long_add(msg->retries,
36868+ atomic_long_add_unchecked(msg->retries,
36869 &port->counter_group[CM_XMIT_RETRIES].
36870 counter[attr_index]);
36871
36872@@ -3431,7 +3431,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
36873 }
36874
36875 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
36876- atomic_long_inc(&port->counter_group[CM_RECV].
36877+ atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
36878 counter[attr_id - CM_ATTR_ID_OFFSET]);
36879
36880 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
36881@@ -3636,7 +3636,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
36882 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
36883
36884 return sprintf(buf, "%ld\n",
36885- atomic_long_read(&group->counter[cm_attr->index]));
36886+ atomic_long_read_unchecked(&group->counter[cm_attr->index]));
36887 }
36888
36889 static const struct sysfs_ops cm_counter_ops = {
36890diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
36891index 9f5ad7c..588cd84 100644
36892--- a/drivers/infiniband/core/fmr_pool.c
36893+++ b/drivers/infiniband/core/fmr_pool.c
36894@@ -98,8 +98,8 @@ struct ib_fmr_pool {
36895
36896 struct task_struct *thread;
36897
36898- atomic_t req_ser;
36899- atomic_t flush_ser;
36900+ atomic_unchecked_t req_ser;
36901+ atomic_unchecked_t flush_ser;
36902
36903 wait_queue_head_t force_wait;
36904 };
36905@@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36906 struct ib_fmr_pool *pool = pool_ptr;
36907
36908 do {
36909- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
36910+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
36911 ib_fmr_batch_release(pool);
36912
36913- atomic_inc(&pool->flush_ser);
36914+ atomic_inc_unchecked(&pool->flush_ser);
36915 wake_up_interruptible(&pool->force_wait);
36916
36917 if (pool->flush_function)
36918@@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
36919 }
36920
36921 set_current_state(TASK_INTERRUPTIBLE);
36922- if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
36923+ if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
36924 !kthread_should_stop())
36925 schedule();
36926 __set_current_state(TASK_RUNNING);
36927@@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
36928 pool->dirty_watermark = params->dirty_watermark;
36929 pool->dirty_len = 0;
36930 spin_lock_init(&pool->pool_lock);
36931- atomic_set(&pool->req_ser, 0);
36932- atomic_set(&pool->flush_ser, 0);
36933+ atomic_set_unchecked(&pool->req_ser, 0);
36934+ atomic_set_unchecked(&pool->flush_ser, 0);
36935 init_waitqueue_head(&pool->force_wait);
36936
36937 pool->thread = kthread_run(ib_fmr_cleanup_thread,
36938@@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
36939 }
36940 spin_unlock_irq(&pool->pool_lock);
36941
36942- serial = atomic_inc_return(&pool->req_ser);
36943+ serial = atomic_inc_return_unchecked(&pool->req_ser);
36944 wake_up_process(pool->thread);
36945
36946 if (wait_event_interruptible(pool->force_wait,
36947- atomic_read(&pool->flush_ser) - serial >= 0))
36948+ atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
36949 return -EINTR;
36950
36951 return 0;
36952@@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
36953 } else {
36954 list_add_tail(&fmr->list, &pool->dirty_list);
36955 if (++pool->dirty_len >= pool->dirty_watermark) {
36956- atomic_inc(&pool->req_ser);
36957+ atomic_inc_unchecked(&pool->req_ser);
36958 wake_up_process(pool->thread);
36959 }
36960 }
36961diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
36962index 903a92d..9262548 100644
36963--- a/drivers/infiniband/hw/cxgb4/mem.c
36964+++ b/drivers/infiniband/hw/cxgb4/mem.c
36965@@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36966 int err;
36967 struct fw_ri_tpte tpt;
36968 u32 stag_idx;
36969- static atomic_t key;
36970+ static atomic_unchecked_t key;
36971
36972 if (c4iw_fatal_error(rdev))
36973 return -EIO;
36974@@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
36975 if (rdev->stats.stag.cur > rdev->stats.stag.max)
36976 rdev->stats.stag.max = rdev->stats.stag.cur;
36977 mutex_unlock(&rdev->stats.lock);
36978- *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
36979+ *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
36980 }
36981 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
36982 __func__, stag_state, type, pdid, stag_idx);
36983diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
36984index 79b3dbc..96e5fcc 100644
36985--- a/drivers/infiniband/hw/ipath/ipath_rc.c
36986+++ b/drivers/infiniband/hw/ipath/ipath_rc.c
36987@@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36988 struct ib_atomic_eth *ateth;
36989 struct ipath_ack_entry *e;
36990 u64 vaddr;
36991- atomic64_t *maddr;
36992+ atomic64_unchecked_t *maddr;
36993 u64 sdata;
36994 u32 rkey;
36995 u8 next;
36996@@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
36997 IB_ACCESS_REMOTE_ATOMIC)))
36998 goto nack_acc_unlck;
36999 /* Perform atomic OP and save result. */
37000- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37001+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37002 sdata = be64_to_cpu(ateth->swap_data);
37003 e = &qp->s_ack_queue[qp->r_head_ack_queue];
37004 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
37005- (u64) atomic64_add_return(sdata, maddr) - sdata :
37006+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37007 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37008 be64_to_cpu(ateth->compare_data),
37009 sdata);
37010diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
37011index 1f95bba..9530f87 100644
37012--- a/drivers/infiniband/hw/ipath/ipath_ruc.c
37013+++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
37014@@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
37015 unsigned long flags;
37016 struct ib_wc wc;
37017 u64 sdata;
37018- atomic64_t *maddr;
37019+ atomic64_unchecked_t *maddr;
37020 enum ib_wc_status send_status;
37021
37022 /*
37023@@ -382,11 +382,11 @@ again:
37024 IB_ACCESS_REMOTE_ATOMIC)))
37025 goto acc_err;
37026 /* Perform atomic OP and save result. */
37027- maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
37028+ maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
37029 sdata = wqe->wr.wr.atomic.compare_add;
37030 *(u64 *) sqp->s_sge.sge.vaddr =
37031 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
37032- (u64) atomic64_add_return(sdata, maddr) - sdata :
37033+ (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
37034 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
37035 sdata, wqe->wr.wr.atomic.swap);
37036 goto send_comp;
37037diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
37038index 9d3e5c1..d9afe4a 100644
37039--- a/drivers/infiniband/hw/mthca/mthca_cmd.c
37040+++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
37041@@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
37042 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
37043 }
37044
37045-int mthca_QUERY_FW(struct mthca_dev *dev)
37046+int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
37047 {
37048 struct mthca_mailbox *mailbox;
37049 u32 *outbox;
37050diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
37051index ed9a989..e0c5871 100644
37052--- a/drivers/infiniband/hw/mthca/mthca_mr.c
37053+++ b/drivers/infiniband/hw/mthca/mthca_mr.c
37054@@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
37055 return key;
37056 }
37057
37058-int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37059+int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
37060 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
37061 {
37062 struct mthca_mailbox *mailbox;
37063diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
37064index 4291410..d2ab1fb 100644
37065--- a/drivers/infiniband/hw/nes/nes.c
37066+++ b/drivers/infiniband/hw/nes/nes.c
37067@@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
37068 LIST_HEAD(nes_adapter_list);
37069 static LIST_HEAD(nes_dev_list);
37070
37071-atomic_t qps_destroyed;
37072+atomic_unchecked_t qps_destroyed;
37073
37074 static unsigned int ee_flsh_adapter;
37075 static unsigned int sysfs_nonidx_addr;
37076@@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
37077 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
37078 struct nes_adapter *nesadapter = nesdev->nesadapter;
37079
37080- atomic_inc(&qps_destroyed);
37081+ atomic_inc_unchecked(&qps_destroyed);
37082
37083 /* Free the control structures */
37084
37085diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
37086index 33cc589..3bd6538 100644
37087--- a/drivers/infiniband/hw/nes/nes.h
37088+++ b/drivers/infiniband/hw/nes/nes.h
37089@@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
37090 extern unsigned int wqm_quanta;
37091 extern struct list_head nes_adapter_list;
37092
37093-extern atomic_t cm_connects;
37094-extern atomic_t cm_accepts;
37095-extern atomic_t cm_disconnects;
37096-extern atomic_t cm_closes;
37097-extern atomic_t cm_connecteds;
37098-extern atomic_t cm_connect_reqs;
37099-extern atomic_t cm_rejects;
37100-extern atomic_t mod_qp_timouts;
37101-extern atomic_t qps_created;
37102-extern atomic_t qps_destroyed;
37103-extern atomic_t sw_qps_destroyed;
37104+extern atomic_unchecked_t cm_connects;
37105+extern atomic_unchecked_t cm_accepts;
37106+extern atomic_unchecked_t cm_disconnects;
37107+extern atomic_unchecked_t cm_closes;
37108+extern atomic_unchecked_t cm_connecteds;
37109+extern atomic_unchecked_t cm_connect_reqs;
37110+extern atomic_unchecked_t cm_rejects;
37111+extern atomic_unchecked_t mod_qp_timouts;
37112+extern atomic_unchecked_t qps_created;
37113+extern atomic_unchecked_t qps_destroyed;
37114+extern atomic_unchecked_t sw_qps_destroyed;
37115 extern u32 mh_detected;
37116 extern u32 mh_pauses_sent;
37117 extern u32 cm_packets_sent;
37118@@ -196,16 +196,16 @@ extern u32 cm_packets_created;
37119 extern u32 cm_packets_received;
37120 extern u32 cm_packets_dropped;
37121 extern u32 cm_packets_retrans;
37122-extern atomic_t cm_listens_created;
37123-extern atomic_t cm_listens_destroyed;
37124+extern atomic_unchecked_t cm_listens_created;
37125+extern atomic_unchecked_t cm_listens_destroyed;
37126 extern u32 cm_backlog_drops;
37127-extern atomic_t cm_loopbacks;
37128-extern atomic_t cm_nodes_created;
37129-extern atomic_t cm_nodes_destroyed;
37130-extern atomic_t cm_accel_dropped_pkts;
37131-extern atomic_t cm_resets_recvd;
37132-extern atomic_t pau_qps_created;
37133-extern atomic_t pau_qps_destroyed;
37134+extern atomic_unchecked_t cm_loopbacks;
37135+extern atomic_unchecked_t cm_nodes_created;
37136+extern atomic_unchecked_t cm_nodes_destroyed;
37137+extern atomic_unchecked_t cm_accel_dropped_pkts;
37138+extern atomic_unchecked_t cm_resets_recvd;
37139+extern atomic_unchecked_t pau_qps_created;
37140+extern atomic_unchecked_t pau_qps_destroyed;
37141
37142 extern u32 int_mod_timer_init;
37143 extern u32 int_mod_cq_depth_256;
37144diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
37145index 24b9f1a..00fd004 100644
37146--- a/drivers/infiniband/hw/nes/nes_cm.c
37147+++ b/drivers/infiniband/hw/nes/nes_cm.c
37148@@ -68,14 +68,14 @@ u32 cm_packets_dropped;
37149 u32 cm_packets_retrans;
37150 u32 cm_packets_created;
37151 u32 cm_packets_received;
37152-atomic_t cm_listens_created;
37153-atomic_t cm_listens_destroyed;
37154+atomic_unchecked_t cm_listens_created;
37155+atomic_unchecked_t cm_listens_destroyed;
37156 u32 cm_backlog_drops;
37157-atomic_t cm_loopbacks;
37158-atomic_t cm_nodes_created;
37159-atomic_t cm_nodes_destroyed;
37160-atomic_t cm_accel_dropped_pkts;
37161-atomic_t cm_resets_recvd;
37162+atomic_unchecked_t cm_loopbacks;
37163+atomic_unchecked_t cm_nodes_created;
37164+atomic_unchecked_t cm_nodes_destroyed;
37165+atomic_unchecked_t cm_accel_dropped_pkts;
37166+atomic_unchecked_t cm_resets_recvd;
37167
37168 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
37169 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
37170@@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
37171
37172 static struct nes_cm_core *g_cm_core;
37173
37174-atomic_t cm_connects;
37175-atomic_t cm_accepts;
37176-atomic_t cm_disconnects;
37177-atomic_t cm_closes;
37178-atomic_t cm_connecteds;
37179-atomic_t cm_connect_reqs;
37180-atomic_t cm_rejects;
37181+atomic_unchecked_t cm_connects;
37182+atomic_unchecked_t cm_accepts;
37183+atomic_unchecked_t cm_disconnects;
37184+atomic_unchecked_t cm_closes;
37185+atomic_unchecked_t cm_connecteds;
37186+atomic_unchecked_t cm_connect_reqs;
37187+atomic_unchecked_t cm_rejects;
37188
37189 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
37190 {
37191@@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
37192 kfree(listener);
37193 listener = NULL;
37194 ret = 0;
37195- atomic_inc(&cm_listens_destroyed);
37196+ atomic_inc_unchecked(&cm_listens_destroyed);
37197 } else {
37198 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
37199 }
37200@@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
37201 cm_node->rem_mac);
37202
37203 add_hte_node(cm_core, cm_node);
37204- atomic_inc(&cm_nodes_created);
37205+ atomic_inc_unchecked(&cm_nodes_created);
37206
37207 return cm_node;
37208 }
37209@@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
37210 }
37211
37212 atomic_dec(&cm_core->node_cnt);
37213- atomic_inc(&cm_nodes_destroyed);
37214+ atomic_inc_unchecked(&cm_nodes_destroyed);
37215 nesqp = cm_node->nesqp;
37216 if (nesqp) {
37217 nesqp->cm_node = NULL;
37218@@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
37219
37220 static void drop_packet(struct sk_buff *skb)
37221 {
37222- atomic_inc(&cm_accel_dropped_pkts);
37223+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37224 dev_kfree_skb_any(skb);
37225 }
37226
37227@@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
37228 {
37229
37230 int reset = 0; /* whether to send reset in case of err.. */
37231- atomic_inc(&cm_resets_recvd);
37232+ atomic_inc_unchecked(&cm_resets_recvd);
37233 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
37234 " refcnt=%d\n", cm_node, cm_node->state,
37235 atomic_read(&cm_node->ref_count));
37236@@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
37237 rem_ref_cm_node(cm_node->cm_core, cm_node);
37238 return NULL;
37239 }
37240- atomic_inc(&cm_loopbacks);
37241+ atomic_inc_unchecked(&cm_loopbacks);
37242 loopbackremotenode->loopbackpartner = cm_node;
37243 loopbackremotenode->tcp_cntxt.rcv_wscale =
37244 NES_CM_DEFAULT_RCV_WND_SCALE;
37245@@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
37246 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
37247 else {
37248 rem_ref_cm_node(cm_core, cm_node);
37249- atomic_inc(&cm_accel_dropped_pkts);
37250+ atomic_inc_unchecked(&cm_accel_dropped_pkts);
37251 dev_kfree_skb_any(skb);
37252 }
37253 break;
37254@@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37255
37256 if ((cm_id) && (cm_id->event_handler)) {
37257 if (issue_disconn) {
37258- atomic_inc(&cm_disconnects);
37259+ atomic_inc_unchecked(&cm_disconnects);
37260 cm_event.event = IW_CM_EVENT_DISCONNECT;
37261 cm_event.status = disconn_status;
37262 cm_event.local_addr = cm_id->local_addr;
37263@@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
37264 }
37265
37266 if (issue_close) {
37267- atomic_inc(&cm_closes);
37268+ atomic_inc_unchecked(&cm_closes);
37269 nes_disconnect(nesqp, 1);
37270
37271 cm_id->provider_data = nesqp;
37272@@ -3033,7 +3033,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37273
37274 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
37275 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
37276- atomic_inc(&cm_accepts);
37277+ atomic_inc_unchecked(&cm_accepts);
37278
37279 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
37280 netdev_refcnt_read(nesvnic->netdev));
37281@@ -3228,7 +3228,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
37282 struct nes_cm_core *cm_core;
37283 u8 *start_buff;
37284
37285- atomic_inc(&cm_rejects);
37286+ atomic_inc_unchecked(&cm_rejects);
37287 cm_node = (struct nes_cm_node *)cm_id->provider_data;
37288 loopback = cm_node->loopbackpartner;
37289 cm_core = cm_node->cm_core;
37290@@ -3288,7 +3288,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
37291 ntohl(cm_id->local_addr.sin_addr.s_addr),
37292 ntohs(cm_id->local_addr.sin_port));
37293
37294- atomic_inc(&cm_connects);
37295+ atomic_inc_unchecked(&cm_connects);
37296 nesqp->active_conn = 1;
37297
37298 /* cache the cm_id in the qp */
37299@@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
37300 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
37301 return err;
37302 }
37303- atomic_inc(&cm_listens_created);
37304+ atomic_inc_unchecked(&cm_listens_created);
37305 }
37306
37307 cm_id->add_ref(cm_id);
37308@@ -3499,7 +3499,7 @@ static void cm_event_connected(struct nes_cm_event *event)
37309
37310 if (nesqp->destroyed)
37311 return;
37312- atomic_inc(&cm_connecteds);
37313+ atomic_inc_unchecked(&cm_connecteds);
37314 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
37315 " local port 0x%04X. jiffies = %lu.\n",
37316 nesqp->hwqp.qp_id,
37317@@ -3679,7 +3679,7 @@ static void cm_event_reset(struct nes_cm_event *event)
37318
37319 cm_id->add_ref(cm_id);
37320 ret = cm_id->event_handler(cm_id, &cm_event);
37321- atomic_inc(&cm_closes);
37322+ atomic_inc_unchecked(&cm_closes);
37323 cm_event.event = IW_CM_EVENT_CLOSE;
37324 cm_event.status = 0;
37325 cm_event.provider_data = cm_id->provider_data;
37326@@ -3715,7 +3715,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
37327 return;
37328 cm_id = cm_node->cm_id;
37329
37330- atomic_inc(&cm_connect_reqs);
37331+ atomic_inc_unchecked(&cm_connect_reqs);
37332 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37333 cm_node, cm_id, jiffies);
37334
37335@@ -3755,7 +3755,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
37336 return;
37337 cm_id = cm_node->cm_id;
37338
37339- atomic_inc(&cm_connect_reqs);
37340+ atomic_inc_unchecked(&cm_connect_reqs);
37341 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
37342 cm_node, cm_id, jiffies);
37343
37344diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
37345index 4166452..fc952c3 100644
37346--- a/drivers/infiniband/hw/nes/nes_mgt.c
37347+++ b/drivers/infiniband/hw/nes/nes_mgt.c
37348@@ -40,8 +40,8 @@
37349 #include "nes.h"
37350 #include "nes_mgt.h"
37351
37352-atomic_t pau_qps_created;
37353-atomic_t pau_qps_destroyed;
37354+atomic_unchecked_t pau_qps_created;
37355+atomic_unchecked_t pau_qps_destroyed;
37356
37357 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
37358 {
37359@@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
37360 {
37361 struct sk_buff *skb;
37362 unsigned long flags;
37363- atomic_inc(&pau_qps_destroyed);
37364+ atomic_inc_unchecked(&pau_qps_destroyed);
37365
37366 /* Free packets that have not yet been forwarded */
37367 /* Lock is acquired by skb_dequeue when removing the skb */
37368@@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
37369 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
37370 skb_queue_head_init(&nesqp->pau_list);
37371 spin_lock_init(&nesqp->pau_lock);
37372- atomic_inc(&pau_qps_created);
37373+ atomic_inc_unchecked(&pau_qps_created);
37374 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
37375 }
37376
37377diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
37378index 85cf4d1..05d8e71 100644
37379--- a/drivers/infiniband/hw/nes/nes_nic.c
37380+++ b/drivers/infiniband/hw/nes/nes_nic.c
37381@@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
37382 target_stat_values[++index] = mh_detected;
37383 target_stat_values[++index] = mh_pauses_sent;
37384 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
37385- target_stat_values[++index] = atomic_read(&cm_connects);
37386- target_stat_values[++index] = atomic_read(&cm_accepts);
37387- target_stat_values[++index] = atomic_read(&cm_disconnects);
37388- target_stat_values[++index] = atomic_read(&cm_connecteds);
37389- target_stat_values[++index] = atomic_read(&cm_connect_reqs);
37390- target_stat_values[++index] = atomic_read(&cm_rejects);
37391- target_stat_values[++index] = atomic_read(&mod_qp_timouts);
37392- target_stat_values[++index] = atomic_read(&qps_created);
37393- target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
37394- target_stat_values[++index] = atomic_read(&qps_destroyed);
37395- target_stat_values[++index] = atomic_read(&cm_closes);
37396+ target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
37397+ target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
37398+ target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
37399+ target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
37400+ target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
37401+ target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
37402+ target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
37403+ target_stat_values[++index] = atomic_read_unchecked(&qps_created);
37404+ target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
37405+ target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
37406+ target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
37407 target_stat_values[++index] = cm_packets_sent;
37408 target_stat_values[++index] = cm_packets_bounced;
37409 target_stat_values[++index] = cm_packets_created;
37410 target_stat_values[++index] = cm_packets_received;
37411 target_stat_values[++index] = cm_packets_dropped;
37412 target_stat_values[++index] = cm_packets_retrans;
37413- target_stat_values[++index] = atomic_read(&cm_listens_created);
37414- target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
37415+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
37416+ target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
37417 target_stat_values[++index] = cm_backlog_drops;
37418- target_stat_values[++index] = atomic_read(&cm_loopbacks);
37419- target_stat_values[++index] = atomic_read(&cm_nodes_created);
37420- target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
37421- target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
37422- target_stat_values[++index] = atomic_read(&cm_resets_recvd);
37423+ target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
37424+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
37425+ target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
37426+ target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
37427+ target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
37428 target_stat_values[++index] = nesadapter->free_4kpbl;
37429 target_stat_values[++index] = nesadapter->free_256pbl;
37430 target_stat_values[++index] = int_mod_timer_init;
37431 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
37432 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
37433 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
37434- target_stat_values[++index] = atomic_read(&pau_qps_created);
37435- target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
37436+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
37437+ target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
37438 }
37439
37440 /**
37441diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
37442index 8f67fe2..8960859 100644
37443--- a/drivers/infiniband/hw/nes/nes_verbs.c
37444+++ b/drivers/infiniband/hw/nes/nes_verbs.c
37445@@ -46,9 +46,9 @@
37446
37447 #include <rdma/ib_umem.h>
37448
37449-atomic_t mod_qp_timouts;
37450-atomic_t qps_created;
37451-atomic_t sw_qps_destroyed;
37452+atomic_unchecked_t mod_qp_timouts;
37453+atomic_unchecked_t qps_created;
37454+atomic_unchecked_t sw_qps_destroyed;
37455
37456 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
37457
37458@@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
37459 if (init_attr->create_flags)
37460 return ERR_PTR(-EINVAL);
37461
37462- atomic_inc(&qps_created);
37463+ atomic_inc_unchecked(&qps_created);
37464 switch (init_attr->qp_type) {
37465 case IB_QPT_RC:
37466 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
37467@@ -1465,7 +1465,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
37468 struct iw_cm_event cm_event;
37469 int ret = 0;
37470
37471- atomic_inc(&sw_qps_destroyed);
37472+ atomic_inc_unchecked(&sw_qps_destroyed);
37473 nesqp->destroyed = 1;
37474
37475 /* Blow away the connection if it exists. */
37476diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
37477index 4d11575..3e890e5 100644
37478--- a/drivers/infiniband/hw/qib/qib.h
37479+++ b/drivers/infiniband/hw/qib/qib.h
37480@@ -51,6 +51,7 @@
37481 #include <linux/completion.h>
37482 #include <linux/kref.h>
37483 #include <linux/sched.h>
37484+#include <linux/slab.h>
37485
37486 #include "qib_common.h"
37487 #include "qib_verbs.h"
37488diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
37489index da739d9..da1c7f4 100644
37490--- a/drivers/input/gameport/gameport.c
37491+++ b/drivers/input/gameport/gameport.c
37492@@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
37493 */
37494 static void gameport_init_port(struct gameport *gameport)
37495 {
37496- static atomic_t gameport_no = ATOMIC_INIT(0);
37497+ static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
37498
37499 __module_get(THIS_MODULE);
37500
37501 mutex_init(&gameport->drv_mutex);
37502 device_initialize(&gameport->dev);
37503 dev_set_name(&gameport->dev, "gameport%lu",
37504- (unsigned long)atomic_inc_return(&gameport_no) - 1);
37505+ (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
37506 gameport->dev.bus = &gameport_bus;
37507 gameport->dev.release = gameport_release_port;
37508 if (gameport->parent)
37509diff --git a/drivers/input/input.c b/drivers/input/input.c
37510index c044699..174d71a 100644
37511--- a/drivers/input/input.c
37512+++ b/drivers/input/input.c
37513@@ -2019,7 +2019,7 @@ static void devm_input_device_unregister(struct device *dev, void *res)
37514 */
37515 int input_register_device(struct input_dev *dev)
37516 {
37517- static atomic_t input_no = ATOMIC_INIT(0);
37518+ static atomic_unchecked_t input_no = ATOMIC_INIT(0);
37519 struct input_devres *devres = NULL;
37520 struct input_handler *handler;
37521 unsigned int packet_size;
37522@@ -2074,7 +2074,7 @@ int input_register_device(struct input_dev *dev)
37523 dev->setkeycode = input_default_setkeycode;
37524
37525 dev_set_name(&dev->dev, "input%ld",
37526- (unsigned long) atomic_inc_return(&input_no) - 1);
37527+ (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
37528
37529 error = device_add(&dev->dev);
37530 if (error)
37531diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
37532index 04c69af..5f92d00 100644
37533--- a/drivers/input/joystick/sidewinder.c
37534+++ b/drivers/input/joystick/sidewinder.c
37535@@ -30,6 +30,7 @@
37536 #include <linux/kernel.h>
37537 #include <linux/module.h>
37538 #include <linux/slab.h>
37539+#include <linux/sched.h>
37540 #include <linux/init.h>
37541 #include <linux/input.h>
37542 #include <linux/gameport.h>
37543diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
37544index fa061d4..4a6957c 100644
37545--- a/drivers/input/joystick/xpad.c
37546+++ b/drivers/input/joystick/xpad.c
37547@@ -735,7 +735,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
37548
37549 static int xpad_led_probe(struct usb_xpad *xpad)
37550 {
37551- static atomic_t led_seq = ATOMIC_INIT(0);
37552+ static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
37553 long led_no;
37554 struct xpad_led *led;
37555 struct led_classdev *led_cdev;
37556@@ -748,7 +748,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
37557 if (!led)
37558 return -ENOMEM;
37559
37560- led_no = (long)atomic_inc_return(&led_seq) - 1;
37561+ led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
37562
37563 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
37564 led->xpad = xpad;
37565diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
37566index 2f0b39d..7370f13 100644
37567--- a/drivers/input/mouse/psmouse.h
37568+++ b/drivers/input/mouse/psmouse.h
37569@@ -116,7 +116,7 @@ struct psmouse_attribute {
37570 ssize_t (*set)(struct psmouse *psmouse, void *data,
37571 const char *buf, size_t count);
37572 bool protect;
37573-};
37574+} __do_const;
37575 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
37576
37577 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
37578diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
37579index 4c842c3..590b0bf 100644
37580--- a/drivers/input/mousedev.c
37581+++ b/drivers/input/mousedev.c
37582@@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
37583
37584 spin_unlock_irq(&client->packet_lock);
37585
37586- if (copy_to_user(buffer, data, count))
37587+ if (count > sizeof(data) || copy_to_user(buffer, data, count))
37588 return -EFAULT;
37589
37590 return count;
37591diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
37592index 25fc597..558bf3b3 100644
37593--- a/drivers/input/serio/serio.c
37594+++ b/drivers/input/serio/serio.c
37595@@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
37596 */
37597 static void serio_init_port(struct serio *serio)
37598 {
37599- static atomic_t serio_no = ATOMIC_INIT(0);
37600+ static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
37601
37602 __module_get(THIS_MODULE);
37603
37604@@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
37605 mutex_init(&serio->drv_mutex);
37606 device_initialize(&serio->dev);
37607 dev_set_name(&serio->dev, "serio%ld",
37608- (long)atomic_inc_return(&serio_no) - 1);
37609+ (long)atomic_inc_return_unchecked(&serio_no) - 1);
37610 serio->dev.bus = &serio_bus;
37611 serio->dev.release = serio_release_port;
37612 serio->dev.groups = serio_device_attr_groups;
37613diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
37614index b972d43..8943713 100644
37615--- a/drivers/iommu/iommu.c
37616+++ b/drivers/iommu/iommu.c
37617@@ -554,7 +554,7 @@ static struct notifier_block iommu_bus_nb = {
37618 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
37619 {
37620 bus_register_notifier(bus, &iommu_bus_nb);
37621- bus_for_each_dev(bus, NULL, ops, add_iommu_group);
37622+ bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
37623 }
37624
37625 /**
37626diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
37627index 7c11ff3..a2a0457 100644
37628--- a/drivers/iommu/irq_remapping.c
37629+++ b/drivers/iommu/irq_remapping.c
37630@@ -348,7 +348,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
37631 void panic_if_irq_remap(const char *msg)
37632 {
37633 if (irq_remapping_enabled)
37634- panic(msg);
37635+ panic("%s", msg);
37636 }
37637
37638 static void ir_ack_apic_edge(struct irq_data *data)
37639@@ -369,10 +369,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
37640
37641 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
37642 {
37643- chip->irq_print_chip = ir_print_prefix;
37644- chip->irq_ack = ir_ack_apic_edge;
37645- chip->irq_eoi = ir_ack_apic_level;
37646- chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37647+ pax_open_kernel();
37648+ *(void **)&chip->irq_print_chip = ir_print_prefix;
37649+ *(void **)&chip->irq_ack = ir_ack_apic_edge;
37650+ *(void **)&chip->irq_eoi = ir_ack_apic_level;
37651+ *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
37652+ pax_close_kernel();
37653 }
37654
37655 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
37656diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
37657index fc6aebf..762c5f5 100644
37658--- a/drivers/irqchip/irq-gic.c
37659+++ b/drivers/irqchip/irq-gic.c
37660@@ -83,7 +83,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
37661 * Supported arch specific GIC irq extension.
37662 * Default make them NULL.
37663 */
37664-struct irq_chip gic_arch_extn = {
37665+irq_chip_no_const gic_arch_extn = {
37666 .irq_eoi = NULL,
37667 .irq_mask = NULL,
37668 .irq_unmask = NULL,
37669@@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
37670 chained_irq_exit(chip, desc);
37671 }
37672
37673-static struct irq_chip gic_chip = {
37674+static irq_chip_no_const gic_chip __read_only = {
37675 .name = "GIC",
37676 .irq_mask = gic_mask_irq,
37677 .irq_unmask = gic_unmask_irq,
37678diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
37679index 89562a8..218999b 100644
37680--- a/drivers/isdn/capi/capi.c
37681+++ b/drivers/isdn/capi/capi.c
37682@@ -81,8 +81,8 @@ struct capiminor {
37683
37684 struct capi20_appl *ap;
37685 u32 ncci;
37686- atomic_t datahandle;
37687- atomic_t msgid;
37688+ atomic_unchecked_t datahandle;
37689+ atomic_unchecked_t msgid;
37690
37691 struct tty_port port;
37692 int ttyinstop;
37693@@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
37694 capimsg_setu16(s, 2, mp->ap->applid);
37695 capimsg_setu8 (s, 4, CAPI_DATA_B3);
37696 capimsg_setu8 (s, 5, CAPI_RESP);
37697- capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
37698+ capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
37699 capimsg_setu32(s, 8, mp->ncci);
37700 capimsg_setu16(s, 12, datahandle);
37701 }
37702@@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
37703 mp->outbytes -= len;
37704 spin_unlock_bh(&mp->outlock);
37705
37706- datahandle = atomic_inc_return(&mp->datahandle);
37707+ datahandle = atomic_inc_return_unchecked(&mp->datahandle);
37708 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
37709 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37710 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
37711 capimsg_setu16(skb->data, 2, mp->ap->applid);
37712 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
37713 capimsg_setu8 (skb->data, 5, CAPI_REQ);
37714- capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
37715+ capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
37716 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
37717 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
37718 capimsg_setu16(skb->data, 16, len); /* Data length */
37719diff --git a/drivers/isdn/capi/kcapi.c b/drivers/isdn/capi/kcapi.c
37720index 9b1b274..c123709 100644
37721--- a/drivers/isdn/capi/kcapi.c
37722+++ b/drivers/isdn/capi/kcapi.c
37723@@ -93,7 +93,7 @@ capi_ctr_put(struct capi_ctr *ctr)
37724
37725 static inline struct capi_ctr *get_capi_ctr_by_nr(u16 contr)
37726 {
37727- if (contr - 1 >= CAPI_MAXCONTR)
37728+ if (contr < 1 || contr - 1 >= CAPI_MAXCONTR)
37729 return NULL;
37730
37731 return capi_controller[contr - 1];
37732@@ -103,7 +103,7 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
37733 {
37734 lockdep_assert_held(&capi_controller_lock);
37735
37736- if (applid - 1 >= CAPI_MAXAPPL)
37737+ if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
37738 return NULL;
37739
37740 return capi_applications[applid - 1];
37741@@ -111,7 +111,7 @@ static inline struct capi20_appl *__get_capi_appl_by_nr(u16 applid)
37742
37743 static inline struct capi20_appl *get_capi_appl_by_nr(u16 applid)
37744 {
37745- if (applid - 1 >= CAPI_MAXAPPL)
37746+ if (applid < 1 || applid - 1 >= CAPI_MAXAPPL)
37747 return NULL;
37748
37749 return rcu_dereference(capi_applications[applid - 1]);
37750diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
37751index e2b5396..c5486dc 100644
37752--- a/drivers/isdn/gigaset/interface.c
37753+++ b/drivers/isdn/gigaset/interface.c
37754@@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
37755 }
37756 tty->driver_data = cs;
37757
37758- ++cs->port.count;
37759+ atomic_inc(&cs->port.count);
37760
37761- if (cs->port.count == 1) {
37762+ if (atomic_read(&cs->port.count) == 1) {
37763 tty_port_tty_set(&cs->port, tty);
37764 cs->port.low_latency = 1;
37765 }
37766@@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
37767
37768 if (!cs->connected)
37769 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
37770- else if (!cs->port.count)
37771+ else if (!atomic_read(&cs->port.count))
37772 dev_warn(cs->dev, "%s: device not opened\n", __func__);
37773- else if (!--cs->port.count)
37774+ else if (!atomic_dec_return(&cs->port.count))
37775 tty_port_tty_set(&cs->port, NULL);
37776
37777 mutex_unlock(&cs->mutex);
37778diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
37779index 821f7ac..28d4030 100644
37780--- a/drivers/isdn/hardware/avm/b1.c
37781+++ b/drivers/isdn/hardware/avm/b1.c
37782@@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
37783 }
37784 if (left) {
37785 if (t4file->user) {
37786- if (copy_from_user(buf, dp, left))
37787+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37788 return -EFAULT;
37789 } else {
37790 memcpy(buf, dp, left);
37791@@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
37792 }
37793 if (left) {
37794 if (config->user) {
37795- if (copy_from_user(buf, dp, left))
37796+ if (left > sizeof buf || copy_from_user(buf, dp, left))
37797 return -EFAULT;
37798 } else {
37799 memcpy(buf, dp, left);
37800diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
37801index ebaebdf..acd4405 100644
37802--- a/drivers/isdn/i4l/isdn_tty.c
37803+++ b/drivers/isdn/i4l/isdn_tty.c
37804@@ -1511,9 +1511,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
37805
37806 #ifdef ISDN_DEBUG_MODEM_OPEN
37807 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
37808- port->count);
37809+ atomic_read(&port->count));
37810 #endif
37811- port->count++;
37812+ atomic_inc(&port->count);
37813 port->tty = tty;
37814 /*
37815 * Start up serial port
37816@@ -1557,7 +1557,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37817 #endif
37818 return;
37819 }
37820- if ((tty->count == 1) && (port->count != 1)) {
37821+ if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
37822 /*
37823 * Uh, oh. tty->count is 1, which means that the tty
37824 * structure will be freed. Info->count should always
37825@@ -1566,15 +1566,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
37826 * serial port won't be shutdown.
37827 */
37828 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
37829- "info->count is %d\n", port->count);
37830- port->count = 1;
37831+ "info->count is %d\n", atomic_read(&port->count));
37832+ atomic_set(&port->count, 1);
37833 }
37834- if (--port->count < 0) {
37835+ if (atomic_dec_return(&port->count) < 0) {
37836 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
37837- info->line, port->count);
37838- port->count = 0;
37839+ info->line, atomic_read(&port->count));
37840+ atomic_set(&port->count, 0);
37841 }
37842- if (port->count) {
37843+ if (atomic_read(&port->count)) {
37844 #ifdef ISDN_DEBUG_MODEM_OPEN
37845 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
37846 #endif
37847@@ -1628,7 +1628,7 @@ isdn_tty_hangup(struct tty_struct *tty)
37848 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
37849 return;
37850 isdn_tty_shutdown(info);
37851- port->count = 0;
37852+ atomic_set(&port->count, 0);
37853 port->flags &= ~ASYNC_NORMAL_ACTIVE;
37854 port->tty = NULL;
37855 wake_up_interruptible(&port->open_wait);
37856@@ -1973,7 +1973,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
37857 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
37858 modem_info *info = &dev->mdm.info[i];
37859
37860- if (info->port.count == 0)
37861+ if (atomic_read(&info->port.count) == 0)
37862 continue;
37863 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
37864 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
37865diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
37866index e74df7c..03a03ba 100644
37867--- a/drivers/isdn/icn/icn.c
37868+++ b/drivers/isdn/icn/icn.c
37869@@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
37870 if (count > len)
37871 count = len;
37872 if (user) {
37873- if (copy_from_user(msg, buf, count))
37874+ if (count > sizeof msg || copy_from_user(msg, buf, count))
37875 return -EFAULT;
37876 } else
37877 memcpy(msg, buf, count);
37878diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
37879index 6a8405d..0bd1c7e 100644
37880--- a/drivers/leds/leds-clevo-mail.c
37881+++ b/drivers/leds/leds-clevo-mail.c
37882@@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
37883 * detected as working, but in reality it is not) as low as
37884 * possible.
37885 */
37886-static struct dmi_system_id __initdata clevo_mail_led_dmi_table[] = {
37887+static const struct dmi_system_id __initconst clevo_mail_led_dmi_table[] = {
37888 {
37889 .callback = clevo_mail_led_dmi_callback,
37890 .ident = "Clevo D410J",
37891diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
37892index 64e204e..c6bf189 100644
37893--- a/drivers/leds/leds-ss4200.c
37894+++ b/drivers/leds/leds-ss4200.c
37895@@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
37896 * detected as working, but in reality it is not) as low as
37897 * possible.
37898 */
37899-static struct dmi_system_id __initdata nas_led_whitelist[] = {
37900+static const struct dmi_system_id __initconst nas_led_whitelist[] = {
37901 {
37902 .callback = ss4200_led_dmi_callback,
37903 .ident = "Intel SS4200-E",
37904diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
37905index a5ebc00..3de3364 100644
37906--- a/drivers/lguest/core.c
37907+++ b/drivers/lguest/core.c
37908@@ -92,9 +92,17 @@ static __init int map_switcher(void)
37909 * it's worked so far. The end address needs +1 because __get_vm_area
37910 * allocates an extra guard page, so we need space for that.
37911 */
37912+
37913+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
37914+ switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37915+ VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
37916+ + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37917+#else
37918 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
37919 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
37920 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
37921+#endif
37922+
37923 if (!switcher_vma) {
37924 err = -ENOMEM;
37925 printk("lguest: could not map switcher pages high\n");
37926@@ -119,7 +127,7 @@ static __init int map_switcher(void)
37927 * Now the Switcher is mapped at the right address, we can't fail!
37928 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
37929 */
37930- memcpy(switcher_vma->addr, start_switcher_text,
37931+ memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
37932 end_switcher_text - start_switcher_text);
37933
37934 printk(KERN_INFO "lguest: mapped switcher at %p\n",
37935diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
37936index 3b62be16..e33134a 100644
37937--- a/drivers/lguest/page_tables.c
37938+++ b/drivers/lguest/page_tables.c
37939@@ -532,7 +532,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
37940 /*:*/
37941
37942 #ifdef CONFIG_X86_PAE
37943-static void release_pmd(pmd_t *spmd)
37944+static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
37945 {
37946 /* If the entry's not present, there's nothing to release. */
37947 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
37948diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
37949index 4af12e1..0e89afe 100644
37950--- a/drivers/lguest/x86/core.c
37951+++ b/drivers/lguest/x86/core.c
37952@@ -59,7 +59,7 @@ static struct {
37953 /* Offset from where switcher.S was compiled to where we've copied it */
37954 static unsigned long switcher_offset(void)
37955 {
37956- return SWITCHER_ADDR - (unsigned long)start_switcher_text;
37957+ return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
37958 }
37959
37960 /* This cpu's struct lguest_pages. */
37961@@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
37962 * These copies are pretty cheap, so we do them unconditionally: */
37963 /* Save the current Host top-level page directory.
37964 */
37965+
37966+#ifdef CONFIG_PAX_PER_CPU_PGD
37967+ pages->state.host_cr3 = read_cr3();
37968+#else
37969 pages->state.host_cr3 = __pa(current->mm->pgd);
37970+#endif
37971+
37972 /*
37973 * Set up the Guest's page tables to see this CPU's pages (and no
37974 * other CPU's pages).
37975@@ -476,7 +482,7 @@ void __init lguest_arch_host_init(void)
37976 * compiled-in switcher code and the high-mapped copy we just made.
37977 */
37978 for (i = 0; i < IDT_ENTRIES; i++)
37979- default_idt_entries[i] += switcher_offset();
37980+ default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
37981
37982 /*
37983 * Set up the Switcher's per-cpu areas.
37984@@ -559,7 +565,7 @@ void __init lguest_arch_host_init(void)
37985 * it will be undisturbed when we switch. To change %cs and jump we
37986 * need this structure to feed to Intel's "lcall" instruction.
37987 */
37988- lguest_entry.offset = (long)switch_to_guest + switcher_offset();
37989+ lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
37990 lguest_entry.segment = LGUEST_CS;
37991
37992 /*
37993diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
37994index 40634b0..4f5855e 100644
37995--- a/drivers/lguest/x86/switcher_32.S
37996+++ b/drivers/lguest/x86/switcher_32.S
37997@@ -87,6 +87,7 @@
37998 #include <asm/page.h>
37999 #include <asm/segment.h>
38000 #include <asm/lguest.h>
38001+#include <asm/processor-flags.h>
38002
38003 // We mark the start of the code to copy
38004 // It's placed in .text tho it's never run here
38005@@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
38006 // Changes type when we load it: damn Intel!
38007 // For after we switch over our page tables
38008 // That entry will be read-only: we'd crash.
38009+
38010+#ifdef CONFIG_PAX_KERNEXEC
38011+ mov %cr0, %edx
38012+ xor $X86_CR0_WP, %edx
38013+ mov %edx, %cr0
38014+#endif
38015+
38016 movl $(GDT_ENTRY_TSS*8), %edx
38017 ltr %dx
38018
38019@@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
38020 // Let's clear it again for our return.
38021 // The GDT descriptor of the Host
38022 // Points to the table after two "size" bytes
38023- movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
38024+ movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
38025 // Clear "used" from type field (byte 5, bit 2)
38026- andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
38027+ andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
38028+
38029+#ifdef CONFIG_PAX_KERNEXEC
38030+ mov %cr0, %eax
38031+ xor $X86_CR0_WP, %eax
38032+ mov %eax, %cr0
38033+#endif
38034
38035 // Once our page table's switched, the Guest is live!
38036 // The Host fades as we run this final step.
38037@@ -295,13 +309,12 @@ deliver_to_host:
38038 // I consulted gcc, and it gave
38039 // These instructions, which I gladly credit:
38040 leal (%edx,%ebx,8), %eax
38041- movzwl (%eax),%edx
38042- movl 4(%eax), %eax
38043- xorw %ax, %ax
38044- orl %eax, %edx
38045+ movl 4(%eax), %edx
38046+ movw (%eax), %dx
38047 // Now the address of the handler's in %edx
38048 // We call it now: its "iret" drops us home.
38049- jmp *%edx
38050+ ljmp $__KERNEL_CS, $1f
38051+1: jmp *%edx
38052
38053 // Every interrupt can come to us here
38054 // But we must truly tell each apart.
38055diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
38056index 4fd9d6a..834fa03 100644
38057--- a/drivers/md/bitmap.c
38058+++ b/drivers/md/bitmap.c
38059@@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
38060 chunk_kb ? "KB" : "B");
38061 if (bitmap->storage.file) {
38062 seq_printf(seq, ", file: ");
38063- seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
38064+ seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
38065 }
38066
38067 seq_printf(seq, "\n");
38068diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
38069index aa04f02..2a1309e 100644
38070--- a/drivers/md/dm-ioctl.c
38071+++ b/drivers/md/dm-ioctl.c
38072@@ -1694,7 +1694,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
38073 cmd == DM_LIST_VERSIONS_CMD)
38074 return 0;
38075
38076- if ((cmd == DM_DEV_CREATE_CMD)) {
38077+ if (cmd == DM_DEV_CREATE_CMD) {
38078 if (!*param->name) {
38079 DMWARN("name not supplied when creating device");
38080 return -EINVAL;
38081diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
38082index d053098..05cc375 100644
38083--- a/drivers/md/dm-raid1.c
38084+++ b/drivers/md/dm-raid1.c
38085@@ -40,7 +40,7 @@ enum dm_raid1_error {
38086
38087 struct mirror {
38088 struct mirror_set *ms;
38089- atomic_t error_count;
38090+ atomic_unchecked_t error_count;
38091 unsigned long error_type;
38092 struct dm_dev *dev;
38093 sector_t offset;
38094@@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
38095 struct mirror *m;
38096
38097 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
38098- if (!atomic_read(&m->error_count))
38099+ if (!atomic_read_unchecked(&m->error_count))
38100 return m;
38101
38102 return NULL;
38103@@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
38104 * simple way to tell if a device has encountered
38105 * errors.
38106 */
38107- atomic_inc(&m->error_count);
38108+ atomic_inc_unchecked(&m->error_count);
38109
38110 if (test_and_set_bit(error_type, &m->error_type))
38111 return;
38112@@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
38113 struct mirror *m = get_default_mirror(ms);
38114
38115 do {
38116- if (likely(!atomic_read(&m->error_count)))
38117+ if (likely(!atomic_read_unchecked(&m->error_count)))
38118 return m;
38119
38120 if (m-- == ms->mirror)
38121@@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
38122 {
38123 struct mirror *default_mirror = get_default_mirror(m->ms);
38124
38125- return !atomic_read(&default_mirror->error_count);
38126+ return !atomic_read_unchecked(&default_mirror->error_count);
38127 }
38128
38129 static int mirror_available(struct mirror_set *ms, struct bio *bio)
38130@@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
38131 */
38132 if (likely(region_in_sync(ms, region, 1)))
38133 m = choose_mirror(ms, bio->bi_sector);
38134- else if (m && atomic_read(&m->error_count))
38135+ else if (m && atomic_read_unchecked(&m->error_count))
38136 m = NULL;
38137
38138 if (likely(m))
38139@@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
38140 }
38141
38142 ms->mirror[mirror].ms = ms;
38143- atomic_set(&(ms->mirror[mirror].error_count), 0);
38144+ atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
38145 ms->mirror[mirror].error_type = 0;
38146 ms->mirror[mirror].offset = offset;
38147
38148@@ -1340,7 +1340,7 @@ static void mirror_resume(struct dm_target *ti)
38149 */
38150 static char device_status_char(struct mirror *m)
38151 {
38152- if (!atomic_read(&(m->error_count)))
38153+ if (!atomic_read_unchecked(&(m->error_count)))
38154 return 'A';
38155
38156 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
38157diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
38158index 7b8b2b9..9c7d145 100644
38159--- a/drivers/md/dm-stripe.c
38160+++ b/drivers/md/dm-stripe.c
38161@@ -20,7 +20,7 @@ struct stripe {
38162 struct dm_dev *dev;
38163 sector_t physical_start;
38164
38165- atomic_t error_count;
38166+ atomic_unchecked_t error_count;
38167 };
38168
38169 struct stripe_c {
38170@@ -185,7 +185,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
38171 kfree(sc);
38172 return r;
38173 }
38174- atomic_set(&(sc->stripe[i].error_count), 0);
38175+ atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
38176 }
38177
38178 ti->private = sc;
38179@@ -326,7 +326,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
38180 DMEMIT("%d ", sc->stripes);
38181 for (i = 0; i < sc->stripes; i++) {
38182 DMEMIT("%s ", sc->stripe[i].dev->name);
38183- buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
38184+ buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
38185 'D' : 'A';
38186 }
38187 buffer[i] = '\0';
38188@@ -371,8 +371,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
38189 */
38190 for (i = 0; i < sc->stripes; i++)
38191 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
38192- atomic_inc(&(sc->stripe[i].error_count));
38193- if (atomic_read(&(sc->stripe[i].error_count)) <
38194+ atomic_inc_unchecked(&(sc->stripe[i].error_count));
38195+ if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
38196 DM_IO_ERROR_THRESHOLD)
38197 schedule_work(&sc->trigger_event);
38198 }
38199diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
38200index 1ff252a..ee384c1 100644
38201--- a/drivers/md/dm-table.c
38202+++ b/drivers/md/dm-table.c
38203@@ -389,7 +389,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
38204 if (!dev_size)
38205 return 0;
38206
38207- if ((start >= dev_size) || (start + len > dev_size)) {
38208+ if ((start >= dev_size) || (len > dev_size - start)) {
38209 DMWARN("%s: %s too small for target: "
38210 "start=%llu, len=%llu, dev_size=%llu",
38211 dm_device_name(ti->table->md), bdevname(bdev, b),
38212diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
38213index 00cee02..b89a29d 100644
38214--- a/drivers/md/dm-thin-metadata.c
38215+++ b/drivers/md/dm-thin-metadata.c
38216@@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38217 {
38218 pmd->info.tm = pmd->tm;
38219 pmd->info.levels = 2;
38220- pmd->info.value_type.context = pmd->data_sm;
38221+ pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38222 pmd->info.value_type.size = sizeof(__le64);
38223 pmd->info.value_type.inc = data_block_inc;
38224 pmd->info.value_type.dec = data_block_dec;
38225@@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
38226
38227 pmd->bl_info.tm = pmd->tm;
38228 pmd->bl_info.levels = 1;
38229- pmd->bl_info.value_type.context = pmd->data_sm;
38230+ pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
38231 pmd->bl_info.value_type.size = sizeof(__le64);
38232 pmd->bl_info.value_type.inc = data_block_inc;
38233 pmd->bl_info.value_type.dec = data_block_dec;
38234diff --git a/drivers/md/dm.c b/drivers/md/dm.c
38235index 9a0bdad..4df9543 100644
38236--- a/drivers/md/dm.c
38237+++ b/drivers/md/dm.c
38238@@ -169,9 +169,9 @@ struct mapped_device {
38239 /*
38240 * Event handling.
38241 */
38242- atomic_t event_nr;
38243+ atomic_unchecked_t event_nr;
38244 wait_queue_head_t eventq;
38245- atomic_t uevent_seq;
38246+ atomic_unchecked_t uevent_seq;
38247 struct list_head uevent_list;
38248 spinlock_t uevent_lock; /* Protect access to uevent_list */
38249
38250@@ -1879,8 +1879,8 @@ static struct mapped_device *alloc_dev(int minor)
38251 rwlock_init(&md->map_lock);
38252 atomic_set(&md->holders, 1);
38253 atomic_set(&md->open_count, 0);
38254- atomic_set(&md->event_nr, 0);
38255- atomic_set(&md->uevent_seq, 0);
38256+ atomic_set_unchecked(&md->event_nr, 0);
38257+ atomic_set_unchecked(&md->uevent_seq, 0);
38258 INIT_LIST_HEAD(&md->uevent_list);
38259 spin_lock_init(&md->uevent_lock);
38260
38261@@ -2028,7 +2028,7 @@ static void event_callback(void *context)
38262
38263 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
38264
38265- atomic_inc(&md->event_nr);
38266+ atomic_inc_unchecked(&md->event_nr);
38267 wake_up(&md->eventq);
38268 }
38269
38270@@ -2685,18 +2685,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
38271
38272 uint32_t dm_next_uevent_seq(struct mapped_device *md)
38273 {
38274- return atomic_add_return(1, &md->uevent_seq);
38275+ return atomic_add_return_unchecked(1, &md->uevent_seq);
38276 }
38277
38278 uint32_t dm_get_event_nr(struct mapped_device *md)
38279 {
38280- return atomic_read(&md->event_nr);
38281+ return atomic_read_unchecked(&md->event_nr);
38282 }
38283
38284 int dm_wait_event(struct mapped_device *md, int event_nr)
38285 {
38286 return wait_event_interruptible(md->eventq,
38287- (event_nr != atomic_read(&md->event_nr)));
38288+ (event_nr != atomic_read_unchecked(&md->event_nr)));
38289 }
38290
38291 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
38292diff --git a/drivers/md/md.c b/drivers/md/md.c
38293index a4a93b9..4747b63 100644
38294--- a/drivers/md/md.c
38295+++ b/drivers/md/md.c
38296@@ -240,10 +240,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
38297 * start build, activate spare
38298 */
38299 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
38300-static atomic_t md_event_count;
38301+static atomic_unchecked_t md_event_count;
38302 void md_new_event(struct mddev *mddev)
38303 {
38304- atomic_inc(&md_event_count);
38305+ atomic_inc_unchecked(&md_event_count);
38306 wake_up(&md_event_waiters);
38307 }
38308 EXPORT_SYMBOL_GPL(md_new_event);
38309@@ -253,7 +253,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
38310 */
38311 static void md_new_event_inintr(struct mddev *mddev)
38312 {
38313- atomic_inc(&md_event_count);
38314+ atomic_inc_unchecked(&md_event_count);
38315 wake_up(&md_event_waiters);
38316 }
38317
38318@@ -1507,7 +1507,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
38319 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
38320 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
38321 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
38322- atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38323+ atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
38324
38325 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
38326 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
38327@@ -1751,7 +1751,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
38328 else
38329 sb->resync_offset = cpu_to_le64(0);
38330
38331- sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
38332+ sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
38333
38334 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
38335 sb->size = cpu_to_le64(mddev->dev_sectors);
38336@@ -2751,7 +2751,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
38337 static ssize_t
38338 errors_show(struct md_rdev *rdev, char *page)
38339 {
38340- return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
38341+ return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
38342 }
38343
38344 static ssize_t
38345@@ -2760,7 +2760,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
38346 char *e;
38347 unsigned long n = simple_strtoul(buf, &e, 10);
38348 if (*buf && (*e == 0 || *e == '\n')) {
38349- atomic_set(&rdev->corrected_errors, n);
38350+ atomic_set_unchecked(&rdev->corrected_errors, n);
38351 return len;
38352 }
38353 return -EINVAL;
38354@@ -3210,8 +3210,8 @@ int md_rdev_init(struct md_rdev *rdev)
38355 rdev->sb_loaded = 0;
38356 rdev->bb_page = NULL;
38357 atomic_set(&rdev->nr_pending, 0);
38358- atomic_set(&rdev->read_errors, 0);
38359- atomic_set(&rdev->corrected_errors, 0);
38360+ atomic_set_unchecked(&rdev->read_errors, 0);
38361+ atomic_set_unchecked(&rdev->corrected_errors, 0);
38362
38363 INIT_LIST_HEAD(&rdev->same_set);
38364 init_waitqueue_head(&rdev->blocked_wait);
38365@@ -6994,7 +6994,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
38366
38367 spin_unlock(&pers_lock);
38368 seq_printf(seq, "\n");
38369- seq->poll_event = atomic_read(&md_event_count);
38370+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38371 return 0;
38372 }
38373 if (v == (void*)2) {
38374@@ -7097,7 +7097,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
38375 return error;
38376
38377 seq = file->private_data;
38378- seq->poll_event = atomic_read(&md_event_count);
38379+ seq->poll_event = atomic_read_unchecked(&md_event_count);
38380 return error;
38381 }
38382
38383@@ -7111,7 +7111,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
38384 /* always allow read */
38385 mask = POLLIN | POLLRDNORM;
38386
38387- if (seq->poll_event != atomic_read(&md_event_count))
38388+ if (seq->poll_event != atomic_read_unchecked(&md_event_count))
38389 mask |= POLLERR | POLLPRI;
38390 return mask;
38391 }
38392@@ -7155,7 +7155,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
38393 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
38394 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
38395 (int)part_stat_read(&disk->part0, sectors[1]) -
38396- atomic_read(&disk->sync_io);
38397+ atomic_read_unchecked(&disk->sync_io);
38398 /* sync IO will cause sync_io to increase before the disk_stats
38399 * as sync_io is counted when a request starts, and
38400 * disk_stats is counted when it completes.
38401diff --git a/drivers/md/md.h b/drivers/md/md.h
38402index d90fb1a..4174a2b 100644
38403--- a/drivers/md/md.h
38404+++ b/drivers/md/md.h
38405@@ -94,13 +94,13 @@ struct md_rdev {
38406 * only maintained for arrays that
38407 * support hot removal
38408 */
38409- atomic_t read_errors; /* number of consecutive read errors that
38410+ atomic_unchecked_t read_errors; /* number of consecutive read errors that
38411 * we have tried to ignore.
38412 */
38413 struct timespec last_read_error; /* monotonic time since our
38414 * last read error
38415 */
38416- atomic_t corrected_errors; /* number of corrected read errors,
38417+ atomic_unchecked_t corrected_errors; /* number of corrected read errors,
38418 * for reporting to userspace and storing
38419 * in superblock.
38420 */
38421@@ -434,7 +434,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
38422
38423 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
38424 {
38425- atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38426+ atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
38427 }
38428
38429 struct md_personality
38430diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
38431index 1cbfc6b..56e1dbb 100644
38432--- a/drivers/md/persistent-data/dm-space-map.h
38433+++ b/drivers/md/persistent-data/dm-space-map.h
38434@@ -60,6 +60,7 @@ struct dm_space_map {
38435 int (*root_size)(struct dm_space_map *sm, size_t *result);
38436 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
38437 };
38438+typedef struct dm_space_map __no_const dm_space_map_no_const;
38439
38440 /*----------------------------------------------------------------*/
38441
38442diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
38443index 7116798..c81390c 100644
38444--- a/drivers/md/raid1.c
38445+++ b/drivers/md/raid1.c
38446@@ -1836,7 +1836,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
38447 if (r1_sync_page_io(rdev, sect, s,
38448 bio->bi_io_vec[idx].bv_page,
38449 READ) != 0)
38450- atomic_add(s, &rdev->corrected_errors);
38451+ atomic_add_unchecked(s, &rdev->corrected_errors);
38452 }
38453 sectors -= s;
38454 sect += s;
38455@@ -2058,7 +2058,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
38456 test_bit(In_sync, &rdev->flags)) {
38457 if (r1_sync_page_io(rdev, sect, s,
38458 conf->tmppage, READ)) {
38459- atomic_add(s, &rdev->corrected_errors);
38460+ atomic_add_unchecked(s, &rdev->corrected_errors);
38461 printk(KERN_INFO
38462 "md/raid1:%s: read error corrected "
38463 "(%d sectors at %llu on %s)\n",
38464diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
38465index e4ea992..d234520 100644
38466--- a/drivers/md/raid10.c
38467+++ b/drivers/md/raid10.c
38468@@ -1942,7 +1942,7 @@ static void end_sync_read(struct bio *bio, int error)
38469 /* The write handler will notice the lack of
38470 * R10BIO_Uptodate and record any errors etc
38471 */
38472- atomic_add(r10_bio->sectors,
38473+ atomic_add_unchecked(r10_bio->sectors,
38474 &conf->mirrors[d].rdev->corrected_errors);
38475
38476 /* for reconstruct, we always reschedule after a read.
38477@@ -2291,7 +2291,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38478 {
38479 struct timespec cur_time_mon;
38480 unsigned long hours_since_last;
38481- unsigned int read_errors = atomic_read(&rdev->read_errors);
38482+ unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
38483
38484 ktime_get_ts(&cur_time_mon);
38485
38486@@ -2313,9 +2313,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
38487 * overflowing the shift of read_errors by hours_since_last.
38488 */
38489 if (hours_since_last >= 8 * sizeof(read_errors))
38490- atomic_set(&rdev->read_errors, 0);
38491+ atomic_set_unchecked(&rdev->read_errors, 0);
38492 else
38493- atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
38494+ atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
38495 }
38496
38497 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
38498@@ -2369,8 +2369,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38499 return;
38500
38501 check_decay_read_errors(mddev, rdev);
38502- atomic_inc(&rdev->read_errors);
38503- if (atomic_read(&rdev->read_errors) > max_read_errors) {
38504+ atomic_inc_unchecked(&rdev->read_errors);
38505+ if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
38506 char b[BDEVNAME_SIZE];
38507 bdevname(rdev->bdev, b);
38508
38509@@ -2378,7 +2378,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38510 "md/raid10:%s: %s: Raid device exceeded "
38511 "read_error threshold [cur %d:max %d]\n",
38512 mdname(mddev), b,
38513- atomic_read(&rdev->read_errors), max_read_errors);
38514+ atomic_read_unchecked(&rdev->read_errors), max_read_errors);
38515 printk(KERN_NOTICE
38516 "md/raid10:%s: %s: Failing raid device\n",
38517 mdname(mddev), b);
38518@@ -2533,7 +2533,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
38519 sect +
38520 choose_data_offset(r10_bio, rdev)),
38521 bdevname(rdev->bdev, b));
38522- atomic_add(s, &rdev->corrected_errors);
38523+ atomic_add_unchecked(s, &rdev->corrected_errors);
38524 }
38525
38526 rdev_dec_pending(rdev, mddev);
38527diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
38528index 251ab64..ed23a18 100644
38529--- a/drivers/md/raid5.c
38530+++ b/drivers/md/raid5.c
38531@@ -1763,21 +1763,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
38532 mdname(conf->mddev), STRIPE_SECTORS,
38533 (unsigned long long)s,
38534 bdevname(rdev->bdev, b));
38535- atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
38536+ atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
38537 clear_bit(R5_ReadError, &sh->dev[i].flags);
38538 clear_bit(R5_ReWrite, &sh->dev[i].flags);
38539 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
38540 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
38541
38542- if (atomic_read(&rdev->read_errors))
38543- atomic_set(&rdev->read_errors, 0);
38544+ if (atomic_read_unchecked(&rdev->read_errors))
38545+ atomic_set_unchecked(&rdev->read_errors, 0);
38546 } else {
38547 const char *bdn = bdevname(rdev->bdev, b);
38548 int retry = 0;
38549 int set_bad = 0;
38550
38551 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
38552- atomic_inc(&rdev->read_errors);
38553+ atomic_inc_unchecked(&rdev->read_errors);
38554 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
38555 printk_ratelimited(
38556 KERN_WARNING
38557@@ -1805,7 +1805,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
38558 mdname(conf->mddev),
38559 (unsigned long long)s,
38560 bdn);
38561- } else if (atomic_read(&rdev->read_errors)
38562+ } else if (atomic_read_unchecked(&rdev->read_errors)
38563 > conf->max_nr_stripes)
38564 printk(KERN_WARNING
38565 "md/raid:%s: Too many read errors, failing device %s.\n",
38566diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
38567index 401ef64..836e563 100644
38568--- a/drivers/media/dvb-core/dvbdev.c
38569+++ b/drivers/media/dvb-core/dvbdev.c
38570@@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
38571 const struct dvb_device *template, void *priv, int type)
38572 {
38573 struct dvb_device *dvbdev;
38574- struct file_operations *dvbdevfops;
38575+ file_operations_no_const *dvbdevfops;
38576 struct device *clsdev;
38577 int minor;
38578 int id;
38579diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
38580index 9b6c3bb..baeb5c7 100644
38581--- a/drivers/media/dvb-frontends/dib3000.h
38582+++ b/drivers/media/dvb-frontends/dib3000.h
38583@@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
38584 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
38585 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
38586 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
38587-};
38588+} __no_const;
38589
38590 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
38591 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
38592diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
38593index bc78354..42c9459 100644
38594--- a/drivers/media/pci/cx88/cx88-video.c
38595+++ b/drivers/media/pci/cx88/cx88-video.c
38596@@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
38597
38598 /* ------------------------------------------------------------------ */
38599
38600-static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38601-static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38602-static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38603+static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38604+static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38605+static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
38606
38607 module_param_array(video_nr, int, NULL, 0444);
38608 module_param_array(vbi_nr, int, NULL, 0444);
38609diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
38610index 96c4a17..1305a79 100644
38611--- a/drivers/media/platform/omap/omap_vout.c
38612+++ b/drivers/media/platform/omap/omap_vout.c
38613@@ -63,7 +63,6 @@ enum omap_vout_channels {
38614 OMAP_VIDEO2,
38615 };
38616
38617-static struct videobuf_queue_ops video_vbq_ops;
38618 /* Variables configurable through module params*/
38619 static u32 video1_numbuffers = 3;
38620 static u32 video2_numbuffers = 3;
38621@@ -1012,6 +1011,12 @@ static int omap_vout_open(struct file *file)
38622 {
38623 struct videobuf_queue *q;
38624 struct omap_vout_device *vout = NULL;
38625+ static struct videobuf_queue_ops video_vbq_ops = {
38626+ .buf_setup = omap_vout_buffer_setup,
38627+ .buf_prepare = omap_vout_buffer_prepare,
38628+ .buf_release = omap_vout_buffer_release,
38629+ .buf_queue = omap_vout_buffer_queue,
38630+ };
38631
38632 vout = video_drvdata(file);
38633 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
38634@@ -1029,10 +1034,6 @@ static int omap_vout_open(struct file *file)
38635 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
38636
38637 q = &vout->vbq;
38638- video_vbq_ops.buf_setup = omap_vout_buffer_setup;
38639- video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
38640- video_vbq_ops.buf_release = omap_vout_buffer_release;
38641- video_vbq_ops.buf_queue = omap_vout_buffer_queue;
38642 spin_lock_init(&vout->vbq_lock);
38643
38644 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
38645diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
38646index 04e6490..2df65bf 100644
38647--- a/drivers/media/platform/s5p-tv/mixer.h
38648+++ b/drivers/media/platform/s5p-tv/mixer.h
38649@@ -156,7 +156,7 @@ struct mxr_layer {
38650 /** layer index (unique identifier) */
38651 int idx;
38652 /** callbacks for layer methods */
38653- struct mxr_layer_ops ops;
38654+ struct mxr_layer_ops *ops;
38655 /** format array */
38656 const struct mxr_format **fmt_array;
38657 /** size of format array */
38658diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38659index b93a21f..2535195 100644
38660--- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38661+++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
38662@@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
38663 {
38664 struct mxr_layer *layer;
38665 int ret;
38666- struct mxr_layer_ops ops = {
38667+ static struct mxr_layer_ops ops = {
38668 .release = mxr_graph_layer_release,
38669 .buffer_set = mxr_graph_buffer_set,
38670 .stream_set = mxr_graph_stream_set,
38671diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
38672index b713403..53cb5ad 100644
38673--- a/drivers/media/platform/s5p-tv/mixer_reg.c
38674+++ b/drivers/media/platform/s5p-tv/mixer_reg.c
38675@@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
38676 layer->update_buf = next;
38677 }
38678
38679- layer->ops.buffer_set(layer, layer->update_buf);
38680+ layer->ops->buffer_set(layer, layer->update_buf);
38681
38682 if (done && done != layer->shadow_buf)
38683 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
38684diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
38685index 82142a2..6de47e8 100644
38686--- a/drivers/media/platform/s5p-tv/mixer_video.c
38687+++ b/drivers/media/platform/s5p-tv/mixer_video.c
38688@@ -209,7 +209,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
38689 layer->geo.src.height = layer->geo.src.full_height;
38690
38691 mxr_geometry_dump(mdev, &layer->geo);
38692- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38693+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38694 mxr_geometry_dump(mdev, &layer->geo);
38695 }
38696
38697@@ -227,7 +227,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
38698 layer->geo.dst.full_width = mbus_fmt.width;
38699 layer->geo.dst.full_height = mbus_fmt.height;
38700 layer->geo.dst.field = mbus_fmt.field;
38701- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38702+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
38703
38704 mxr_geometry_dump(mdev, &layer->geo);
38705 }
38706@@ -333,7 +333,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
38707 /* set source size to highest accepted value */
38708 geo->src.full_width = max(geo->dst.full_width, pix->width);
38709 geo->src.full_height = max(geo->dst.full_height, pix->height);
38710- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38711+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38712 mxr_geometry_dump(mdev, &layer->geo);
38713 /* set cropping to total visible screen */
38714 geo->src.width = pix->width;
38715@@ -341,12 +341,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
38716 geo->src.x_offset = 0;
38717 geo->src.y_offset = 0;
38718 /* assure consistency of geometry */
38719- layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38720+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
38721 mxr_geometry_dump(mdev, &layer->geo);
38722 /* set full size to lowest possible value */
38723 geo->src.full_width = 0;
38724 geo->src.full_height = 0;
38725- layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38726+ layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
38727 mxr_geometry_dump(mdev, &layer->geo);
38728
38729 /* returning results */
38730@@ -473,7 +473,7 @@ static int mxr_s_selection(struct file *file, void *fh,
38731 target->width = s->r.width;
38732 target->height = s->r.height;
38733
38734- layer->ops.fix_geometry(layer, stage, s->flags);
38735+ layer->ops->fix_geometry(layer, stage, s->flags);
38736
38737 /* retrieve update selection rectangle */
38738 res.left = target->x_offset;
38739@@ -938,13 +938,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
38740 mxr_output_get(mdev);
38741
38742 mxr_layer_update_output(layer);
38743- layer->ops.format_set(layer);
38744+ layer->ops->format_set(layer);
38745 /* enabling layer in hardware */
38746 spin_lock_irqsave(&layer->enq_slock, flags);
38747 layer->state = MXR_LAYER_STREAMING;
38748 spin_unlock_irqrestore(&layer->enq_slock, flags);
38749
38750- layer->ops.stream_set(layer, MXR_ENABLE);
38751+ layer->ops->stream_set(layer, MXR_ENABLE);
38752 mxr_streamer_get(mdev);
38753
38754 return 0;
38755@@ -1014,7 +1014,7 @@ static int stop_streaming(struct vb2_queue *vq)
38756 spin_unlock_irqrestore(&layer->enq_slock, flags);
38757
38758 /* disabling layer in hardware */
38759- layer->ops.stream_set(layer, MXR_DISABLE);
38760+ layer->ops->stream_set(layer, MXR_DISABLE);
38761 /* remove one streamer */
38762 mxr_streamer_put(mdev);
38763 /* allow changes in output configuration */
38764@@ -1053,8 +1053,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
38765
38766 void mxr_layer_release(struct mxr_layer *layer)
38767 {
38768- if (layer->ops.release)
38769- layer->ops.release(layer);
38770+ if (layer->ops->release)
38771+ layer->ops->release(layer);
38772 }
38773
38774 void mxr_base_layer_release(struct mxr_layer *layer)
38775@@ -1080,7 +1080,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
38776
38777 layer->mdev = mdev;
38778 layer->idx = idx;
38779- layer->ops = *ops;
38780+ layer->ops = ops;
38781
38782 spin_lock_init(&layer->enq_slock);
38783 INIT_LIST_HEAD(&layer->enq_list);
38784diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38785index 3d13a63..da31bf1 100644
38786--- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38787+++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
38788@@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
38789 {
38790 struct mxr_layer *layer;
38791 int ret;
38792- struct mxr_layer_ops ops = {
38793+ static struct mxr_layer_ops ops = {
38794 .release = mxr_vp_layer_release,
38795 .buffer_set = mxr_vp_buffer_set,
38796 .stream_set = mxr_vp_stream_set,
38797diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
38798index 643d80a..56bb96b 100644
38799--- a/drivers/media/radio/radio-cadet.c
38800+++ b/drivers/media/radio/radio-cadet.c
38801@@ -302,6 +302,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38802 unsigned char readbuf[RDS_BUFFER];
38803 int i = 0;
38804
38805+ if (count > RDS_BUFFER)
38806+ return -EFAULT;
38807 mutex_lock(&dev->lock);
38808 if (dev->rdsstat == 0)
38809 cadet_start_rds(dev);
38810@@ -317,7 +319,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
38811 while (i < count && dev->rdsin != dev->rdsout)
38812 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
38813
38814- if (i && copy_to_user(data, readbuf, i))
38815+ if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
38816 i = -EFAULT;
38817 unlock:
38818 mutex_unlock(&dev->lock);
38819diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
38820index 3940bb0..fb3952a 100644
38821--- a/drivers/media/usb/dvb-usb/cxusb.c
38822+++ b/drivers/media/usb/dvb-usb/cxusb.c
38823@@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
38824
38825 struct dib0700_adapter_state {
38826 int (*set_param_save) (struct dvb_frontend *);
38827-};
38828+} __no_const;
38829
38830 static int dib7070_set_param_override(struct dvb_frontend *fe)
38831 {
38832diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
38833index 9578a67..31aa652 100644
38834--- a/drivers/media/usb/dvb-usb/dw2102.c
38835+++ b/drivers/media/usb/dvb-usb/dw2102.c
38836@@ -115,7 +115,7 @@ struct su3000_state {
38837
38838 struct s6x0_state {
38839 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
38840-};
38841+} __no_const;
38842
38843 /* debug */
38844 static int dvb_usb_dw2102_debug;
38845diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38846index 7157af3..139e91a 100644
38847--- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38848+++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
38849@@ -326,7 +326,7 @@ struct v4l2_buffer32 {
38850 __u32 reserved;
38851 };
38852
38853-static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38854+static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
38855 enum v4l2_memory memory)
38856 {
38857 void __user *up_pln;
38858@@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38859 return 0;
38860 }
38861
38862-static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
38863+static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
38864 enum v4l2_memory memory)
38865 {
38866 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
38867@@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
38868 put_user(kp->start_block, &up->start_block) ||
38869 put_user(kp->blocks, &up->blocks) ||
38870 put_user(tmp, &up->edid) ||
38871- copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
38872+ copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
38873 return -EFAULT;
38874 return 0;
38875 }
38876diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
38877index aa6e7c7..cb5de87 100644
38878--- a/drivers/media/v4l2-core/v4l2-ioctl.c
38879+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
38880@@ -236,7 +236,7 @@ static void v4l_print_format(const void *arg, bool write_only)
38881 const struct v4l2_vbi_format *vbi;
38882 const struct v4l2_sliced_vbi_format *sliced;
38883 const struct v4l2_window *win;
38884- const struct v4l2_clip *clip;
38885+ const struct v4l2_clip __user *pclip;
38886 unsigned i;
38887
38888 pr_cont("type=%s", prt_names(p->type, v4l2_type_names));
38889@@ -284,12 +284,16 @@ static void v4l_print_format(const void *arg, bool write_only)
38890 win->w.left, win->w.top,
38891 prt_names(win->field, v4l2_field_names),
38892 win->chromakey, win->bitmap, win->global_alpha);
38893- clip = win->clips;
38894+ pclip = win->clips;
38895 for (i = 0; i < win->clipcount; i++) {
38896+ struct v4l2_clip clip;
38897+
38898+ if (copy_from_user(&clip, pclip, sizeof clip))
38899+ break;
38900 printk(KERN_DEBUG "clip %u: wxh=%dx%d, x,y=%d,%d\n",
38901- i, clip->c.width, clip->c.height,
38902- clip->c.left, clip->c.top);
38903- clip = clip->next;
38904+ i, clip.c.width, clip.c.height,
38905+ clip.c.left, clip.c.top);
38906+ pclip = clip.next;
38907 }
38908 break;
38909 case V4L2_BUF_TYPE_VBI_CAPTURE:
38910@@ -1923,7 +1927,8 @@ struct v4l2_ioctl_info {
38911 struct file *file, void *fh, void *p);
38912 } u;
38913 void (*debug)(const void *arg, bool write_only);
38914-};
38915+} __do_const;
38916+typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
38917
38918 /* This control needs a priority check */
38919 #define INFO_FL_PRIO (1 << 0)
38920@@ -2108,7 +2113,7 @@ static long __video_do_ioctl(struct file *file,
38921 struct video_device *vfd = video_devdata(file);
38922 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
38923 bool write_only = false;
38924- struct v4l2_ioctl_info default_info;
38925+ v4l2_ioctl_info_no_const default_info;
38926 const struct v4l2_ioctl_info *info;
38927 void *fh = file->private_data;
38928 struct v4l2_fh *vfh = NULL;
38929@@ -2193,7 +2198,7 @@ done:
38930 }
38931
38932 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
38933- void * __user *user_ptr, void ***kernel_ptr)
38934+ void __user **user_ptr, void ***kernel_ptr)
38935 {
38936 int ret = 0;
38937
38938@@ -2209,7 +2214,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
38939 ret = -EINVAL;
38940 break;
38941 }
38942- *user_ptr = (void __user *)buf->m.planes;
38943+ *user_ptr = (void __force_user *)buf->m.planes;
38944 *kernel_ptr = (void *)&buf->m.planes;
38945 *array_size = sizeof(struct v4l2_plane) * buf->length;
38946 ret = 1;
38947@@ -2244,7 +2249,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
38948 ret = -EINVAL;
38949 break;
38950 }
38951- *user_ptr = (void __user *)ctrls->controls;
38952+ *user_ptr = (void __force_user *)ctrls->controls;
38953 *kernel_ptr = (void *)&ctrls->controls;
38954 *array_size = sizeof(struct v4l2_ext_control)
38955 * ctrls->count;
38956diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
38957index fb69baa..3aeea2e 100644
38958--- a/drivers/message/fusion/mptbase.c
38959+++ b/drivers/message/fusion/mptbase.c
38960@@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38961 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
38962 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
38963
38964+#ifdef CONFIG_GRKERNSEC_HIDESYM
38965+ seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
38966+#else
38967 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
38968 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
38969+#endif
38970+
38971 /*
38972 * Rounding UP to nearest 4-kB boundary here...
38973 */
38974@@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
38975 ioc->facts.GlobalCredits);
38976
38977 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
38978+#ifdef CONFIG_GRKERNSEC_HIDESYM
38979+ NULL, NULL);
38980+#else
38981 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
38982+#endif
38983 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
38984 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
38985 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
38986diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
38987index fa43c39..daeb158 100644
38988--- a/drivers/message/fusion/mptsas.c
38989+++ b/drivers/message/fusion/mptsas.c
38990@@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
38991 return 0;
38992 }
38993
38994+static inline void
38995+mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
38996+{
38997+ if (phy_info->port_details) {
38998+ phy_info->port_details->rphy = rphy;
38999+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39000+ ioc->name, rphy));
39001+ }
39002+
39003+ if (rphy) {
39004+ dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39005+ &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39006+ dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39007+ ioc->name, rphy, rphy->dev.release));
39008+ }
39009+}
39010+
39011 /* no mutex */
39012 static void
39013 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
39014@@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
39015 return NULL;
39016 }
39017
39018-static inline void
39019-mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
39020-{
39021- if (phy_info->port_details) {
39022- phy_info->port_details->rphy = rphy;
39023- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
39024- ioc->name, rphy));
39025- }
39026-
39027- if (rphy) {
39028- dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
39029- &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
39030- dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
39031- ioc->name, rphy, rphy->dev.release));
39032- }
39033-}
39034-
39035 static inline struct sas_port *
39036 mptsas_get_port(struct mptsas_phyinfo *phy_info)
39037 {
39038diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
39039index 164afa7..b6b2e74 100644
39040--- a/drivers/message/fusion/mptscsih.c
39041+++ b/drivers/message/fusion/mptscsih.c
39042@@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
39043
39044 h = shost_priv(SChost);
39045
39046- if (h) {
39047- if (h->info_kbuf == NULL)
39048- if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39049- return h->info_kbuf;
39050- h->info_kbuf[0] = '\0';
39051+ if (!h)
39052+ return NULL;
39053
39054- mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39055- h->info_kbuf[size-1] = '\0';
39056- }
39057+ if (h->info_kbuf == NULL)
39058+ if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
39059+ return h->info_kbuf;
39060+ h->info_kbuf[0] = '\0';
39061+
39062+ mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
39063+ h->info_kbuf[size-1] = '\0';
39064
39065 return h->info_kbuf;
39066 }
39067diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
39068index 8001aa6..b137580 100644
39069--- a/drivers/message/i2o/i2o_proc.c
39070+++ b/drivers/message/i2o/i2o_proc.c
39071@@ -255,12 +255,6 @@ static char *scsi_devices[] = {
39072 "Array Controller Device"
39073 };
39074
39075-static char *chtostr(char *tmp, u8 *chars, int n)
39076-{
39077- tmp[0] = 0;
39078- return strncat(tmp, (char *)chars, n);
39079-}
39080-
39081 static int i2o_report_query_status(struct seq_file *seq, int block_status,
39082 char *group)
39083 {
39084@@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39085 } *result;
39086
39087 i2o_exec_execute_ddm_table ddm_table;
39088- char tmp[28 + 1];
39089
39090 result = kmalloc(sizeof(*result), GFP_KERNEL);
39091 if (!result)
39092@@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
39093
39094 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
39095 seq_printf(seq, "%-#8x", ddm_table.module_id);
39096- seq_printf(seq, "%-29s",
39097- chtostr(tmp, ddm_table.module_name_version, 28));
39098+ seq_printf(seq, "%-.28s", ddm_table.module_name_version);
39099 seq_printf(seq, "%9d ", ddm_table.data_size);
39100 seq_printf(seq, "%8d", ddm_table.code_size);
39101
39102@@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39103
39104 i2o_driver_result_table *result;
39105 i2o_driver_store_table *dst;
39106- char tmp[28 + 1];
39107
39108 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
39109 if (result == NULL)
39110@@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
39111
39112 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
39113 seq_printf(seq, "%-#8x", dst->module_id);
39114- seq_printf(seq, "%-29s",
39115- chtostr(tmp, dst->module_name_version, 28));
39116- seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
39117+ seq_printf(seq, "%-.28s", dst->module_name_version);
39118+ seq_printf(seq, "%-.8s", dst->date);
39119 seq_printf(seq, "%8d ", dst->module_size);
39120 seq_printf(seq, "%8d ", dst->mpb_size);
39121 seq_printf(seq, "0x%04x", dst->module_flags);
39122@@ -1250,7 +1240,6 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39123 // == (allow) 512d bytes (max)
39124 static u16 *work16 = (u16 *) work32;
39125 int token;
39126- char tmp[16 + 1];
39127
39128 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
39129
39130@@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
39131 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
39132 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
39133 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
39134- seq_printf(seq, "Vendor info : %s\n",
39135- chtostr(tmp, (u8 *) (work32 + 2), 16));
39136- seq_printf(seq, "Product info : %s\n",
39137- chtostr(tmp, (u8 *) (work32 + 6), 16));
39138- seq_printf(seq, "Description : %s\n",
39139- chtostr(tmp, (u8 *) (work32 + 10), 16));
39140- seq_printf(seq, "Product rev. : %s\n",
39141- chtostr(tmp, (u8 *) (work32 + 14), 8));
39142+ seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
39143+ seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
39144+ seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
39145+ seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
39146
39147 seq_printf(seq, "Serial number : ");
39148 print_serial_number(seq, (u8 *) (work32 + 16),
39149@@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39150 u8 pad[256]; // allow up to 256 byte (max) serial number
39151 } result;
39152
39153- char tmp[24 + 1];
39154-
39155 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
39156
39157 if (token < 0) {
39158@@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
39159 }
39160
39161 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
39162- seq_printf(seq, "Module name : %s\n",
39163- chtostr(tmp, result.module_name, 24));
39164- seq_printf(seq, "Module revision : %s\n",
39165- chtostr(tmp, result.module_rev, 8));
39166+ seq_printf(seq, "Module name : %.24s\n", result.module_name);
39167+ seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
39168
39169 seq_printf(seq, "Serial number : ");
39170 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
39171@@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39172 u8 instance_number[4];
39173 } result;
39174
39175- char tmp[64 + 1];
39176-
39177 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
39178
39179 if (token < 0) {
39180@@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
39181 return 0;
39182 }
39183
39184- seq_printf(seq, "Device name : %s\n",
39185- chtostr(tmp, result.device_name, 64));
39186- seq_printf(seq, "Service name : %s\n",
39187- chtostr(tmp, result.service_name, 64));
39188- seq_printf(seq, "Physical name : %s\n",
39189- chtostr(tmp, result.physical_location, 64));
39190- seq_printf(seq, "Instance number : %s\n",
39191- chtostr(tmp, result.instance_number, 4));
39192+ seq_printf(seq, "Device name : %.64s\n", result.device_name);
39193+ seq_printf(seq, "Service name : %.64s\n", result.service_name);
39194+ seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
39195+ seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
39196
39197 return 0;
39198 }
39199diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
39200index a8c08f3..155fe3d 100644
39201--- a/drivers/message/i2o/iop.c
39202+++ b/drivers/message/i2o/iop.c
39203@@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
39204
39205 spin_lock_irqsave(&c->context_list_lock, flags);
39206
39207- if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
39208- atomic_inc(&c->context_list_counter);
39209+ if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
39210+ atomic_inc_unchecked(&c->context_list_counter);
39211
39212- entry->context = atomic_read(&c->context_list_counter);
39213+ entry->context = atomic_read_unchecked(&c->context_list_counter);
39214
39215 list_add(&entry->list, &c->context_list);
39216
39217@@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
39218
39219 #if BITS_PER_LONG == 64
39220 spin_lock_init(&c->context_list_lock);
39221- atomic_set(&c->context_list_counter, 0);
39222+ atomic_set_unchecked(&c->context_list_counter, 0);
39223 INIT_LIST_HEAD(&c->context_list);
39224 #endif
39225
39226diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
39227index 45ece11..8efa218 100644
39228--- a/drivers/mfd/janz-cmodio.c
39229+++ b/drivers/mfd/janz-cmodio.c
39230@@ -13,6 +13,7 @@
39231
39232 #include <linux/kernel.h>
39233 #include <linux/module.h>
39234+#include <linux/slab.h>
39235 #include <linux/init.h>
39236 #include <linux/pci.h>
39237 #include <linux/interrupt.h>
39238diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
39239index a5f9888..1c0ed56 100644
39240--- a/drivers/mfd/twl4030-irq.c
39241+++ b/drivers/mfd/twl4030-irq.c
39242@@ -35,6 +35,7 @@
39243 #include <linux/of.h>
39244 #include <linux/irqdomain.h>
39245 #include <linux/i2c/twl.h>
39246+#include <asm/pgtable.h>
39247
39248 #include "twl-core.h"
39249
39250@@ -728,10 +729,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
39251 * Install an irq handler for each of the SIH modules;
39252 * clone dummy irq_chip since PIH can't *do* anything
39253 */
39254- twl4030_irq_chip = dummy_irq_chip;
39255- twl4030_irq_chip.name = "twl4030";
39256+ pax_open_kernel();
39257+ memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
39258+ *(const char **)&twl4030_irq_chip.name = "twl4030";
39259
39260- twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39261+ *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
39262+ pax_close_kernel();
39263
39264 for (i = irq_base; i < irq_end; i++) {
39265 irq_set_chip_and_handler(i, &twl4030_irq_chip,
39266diff --git a/drivers/mfd/twl6030-irq.c b/drivers/mfd/twl6030-irq.c
39267index 277a8db..0e0b754 100644
39268--- a/drivers/mfd/twl6030-irq.c
39269+++ b/drivers/mfd/twl6030-irq.c
39270@@ -387,10 +387,12 @@ int twl6030_init_irq(struct device *dev, int irq_num)
39271 * install an irq handler for each of the modules;
39272 * clone dummy irq_chip since PIH can't *do* anything
39273 */
39274- twl6030_irq_chip = dummy_irq_chip;
39275- twl6030_irq_chip.name = "twl6030";
39276- twl6030_irq_chip.irq_set_type = NULL;
39277- twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39278+ pax_open_kernel();
39279+ memcpy((void *)&twl6030_irq_chip, &dummy_irq_chip, sizeof twl6030_irq_chip);
39280+ *(const char **)&twl6030_irq_chip.name = "twl6030";
39281+ *(void **)&twl6030_irq_chip.irq_set_type = NULL;
39282+ *(void **)&twl6030_irq_chip.irq_set_wake = twl6030_irq_set_wake;
39283+ pax_close_kernel();
39284
39285 for (i = irq_base; i < irq_end; i++) {
39286 irq_set_chip_and_handler(i, &twl6030_irq_chip,
39287diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
39288index f32550a..e3e52a2 100644
39289--- a/drivers/misc/c2port/core.c
39290+++ b/drivers/misc/c2port/core.c
39291@@ -920,7 +920,9 @@ struct c2port_device *c2port_device_register(char *name,
39292 mutex_init(&c2dev->mutex);
39293
39294 /* Create binary file */
39295- c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39296+ pax_open_kernel();
39297+ *(size_t *)&c2port_bin_attrs.size = ops->blocks_num * ops->block_size;
39298+ pax_close_kernel();
39299 ret = device_create_bin_file(c2dev->dev, &c2port_bin_attrs);
39300 if (unlikely(ret))
39301 goto error_device_create_bin_file;
39302diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
39303index 36f5d52..32311c3 100644
39304--- a/drivers/misc/kgdbts.c
39305+++ b/drivers/misc/kgdbts.c
39306@@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
39307 char before[BREAK_INSTR_SIZE];
39308 char after[BREAK_INSTR_SIZE];
39309
39310- probe_kernel_read(before, (char *)kgdbts_break_test,
39311+ probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
39312 BREAK_INSTR_SIZE);
39313 init_simple_test();
39314 ts.tst = plant_and_detach_test;
39315@@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
39316 /* Activate test with initial breakpoint */
39317 if (!is_early)
39318 kgdb_breakpoint();
39319- probe_kernel_read(after, (char *)kgdbts_break_test,
39320+ probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
39321 BREAK_INSTR_SIZE);
39322 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
39323 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
39324diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
39325index 4a87e5c..76bdf5c 100644
39326--- a/drivers/misc/lis3lv02d/lis3lv02d.c
39327+++ b/drivers/misc/lis3lv02d/lis3lv02d.c
39328@@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
39329 * the lid is closed. This leads to interrupts as soon as a little move
39330 * is done.
39331 */
39332- atomic_inc(&lis3->count);
39333+ atomic_inc_unchecked(&lis3->count);
39334
39335 wake_up_interruptible(&lis3->misc_wait);
39336 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
39337@@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
39338 if (lis3->pm_dev)
39339 pm_runtime_get_sync(lis3->pm_dev);
39340
39341- atomic_set(&lis3->count, 0);
39342+ atomic_set_unchecked(&lis3->count, 0);
39343 return 0;
39344 }
39345
39346@@ -617,7 +617,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
39347 add_wait_queue(&lis3->misc_wait, &wait);
39348 while (true) {
39349 set_current_state(TASK_INTERRUPTIBLE);
39350- data = atomic_xchg(&lis3->count, 0);
39351+ data = atomic_xchg_unchecked(&lis3->count, 0);
39352 if (data)
39353 break;
39354
39355@@ -658,7 +658,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
39356 struct lis3lv02d, miscdev);
39357
39358 poll_wait(file, &lis3->misc_wait, wait);
39359- if (atomic_read(&lis3->count))
39360+ if (atomic_read_unchecked(&lis3->count))
39361 return POLLIN | POLLRDNORM;
39362 return 0;
39363 }
39364diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
39365index c439c82..1f20f57 100644
39366--- a/drivers/misc/lis3lv02d/lis3lv02d.h
39367+++ b/drivers/misc/lis3lv02d/lis3lv02d.h
39368@@ -297,7 +297,7 @@ struct lis3lv02d {
39369 struct input_polled_dev *idev; /* input device */
39370 struct platform_device *pdev; /* platform device */
39371 struct regulator_bulk_data regulators[2];
39372- atomic_t count; /* interrupt count after last read */
39373+ atomic_unchecked_t count; /* interrupt count after last read */
39374 union axis_conversion ac; /* hw -> logical axis */
39375 int mapped_btns[3];
39376
39377diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
39378index 2f30bad..c4c13d0 100644
39379--- a/drivers/misc/sgi-gru/gruhandles.c
39380+++ b/drivers/misc/sgi-gru/gruhandles.c
39381@@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
39382 unsigned long nsec;
39383
39384 nsec = CLKS2NSEC(clks);
39385- atomic_long_inc(&mcs_op_statistics[op].count);
39386- atomic_long_add(nsec, &mcs_op_statistics[op].total);
39387+ atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
39388+ atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
39389 if (mcs_op_statistics[op].max < nsec)
39390 mcs_op_statistics[op].max = nsec;
39391 }
39392diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
39393index 950dbe9..eeef0f8 100644
39394--- a/drivers/misc/sgi-gru/gruprocfs.c
39395+++ b/drivers/misc/sgi-gru/gruprocfs.c
39396@@ -32,9 +32,9 @@
39397
39398 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
39399
39400-static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
39401+static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
39402 {
39403- unsigned long val = atomic_long_read(v);
39404+ unsigned long val = atomic_long_read_unchecked(v);
39405
39406 seq_printf(s, "%16lu %s\n", val, id);
39407 }
39408@@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
39409
39410 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
39411 for (op = 0; op < mcsop_last; op++) {
39412- count = atomic_long_read(&mcs_op_statistics[op].count);
39413- total = atomic_long_read(&mcs_op_statistics[op].total);
39414+ count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
39415+ total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
39416 max = mcs_op_statistics[op].max;
39417 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
39418 count ? total / count : 0, max);
39419diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
39420index 5c3ce24..4915ccb 100644
39421--- a/drivers/misc/sgi-gru/grutables.h
39422+++ b/drivers/misc/sgi-gru/grutables.h
39423@@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
39424 * GRU statistics.
39425 */
39426 struct gru_stats_s {
39427- atomic_long_t vdata_alloc;
39428- atomic_long_t vdata_free;
39429- atomic_long_t gts_alloc;
39430- atomic_long_t gts_free;
39431- atomic_long_t gms_alloc;
39432- atomic_long_t gms_free;
39433- atomic_long_t gts_double_allocate;
39434- atomic_long_t assign_context;
39435- atomic_long_t assign_context_failed;
39436- atomic_long_t free_context;
39437- atomic_long_t load_user_context;
39438- atomic_long_t load_kernel_context;
39439- atomic_long_t lock_kernel_context;
39440- atomic_long_t unlock_kernel_context;
39441- atomic_long_t steal_user_context;
39442- atomic_long_t steal_kernel_context;
39443- atomic_long_t steal_context_failed;
39444- atomic_long_t nopfn;
39445- atomic_long_t asid_new;
39446- atomic_long_t asid_next;
39447- atomic_long_t asid_wrap;
39448- atomic_long_t asid_reuse;
39449- atomic_long_t intr;
39450- atomic_long_t intr_cbr;
39451- atomic_long_t intr_tfh;
39452- atomic_long_t intr_spurious;
39453- atomic_long_t intr_mm_lock_failed;
39454- atomic_long_t call_os;
39455- atomic_long_t call_os_wait_queue;
39456- atomic_long_t user_flush_tlb;
39457- atomic_long_t user_unload_context;
39458- atomic_long_t user_exception;
39459- atomic_long_t set_context_option;
39460- atomic_long_t check_context_retarget_intr;
39461- atomic_long_t check_context_unload;
39462- atomic_long_t tlb_dropin;
39463- atomic_long_t tlb_preload_page;
39464- atomic_long_t tlb_dropin_fail_no_asid;
39465- atomic_long_t tlb_dropin_fail_upm;
39466- atomic_long_t tlb_dropin_fail_invalid;
39467- atomic_long_t tlb_dropin_fail_range_active;
39468- atomic_long_t tlb_dropin_fail_idle;
39469- atomic_long_t tlb_dropin_fail_fmm;
39470- atomic_long_t tlb_dropin_fail_no_exception;
39471- atomic_long_t tfh_stale_on_fault;
39472- atomic_long_t mmu_invalidate_range;
39473- atomic_long_t mmu_invalidate_page;
39474- atomic_long_t flush_tlb;
39475- atomic_long_t flush_tlb_gru;
39476- atomic_long_t flush_tlb_gru_tgh;
39477- atomic_long_t flush_tlb_gru_zero_asid;
39478+ atomic_long_unchecked_t vdata_alloc;
39479+ atomic_long_unchecked_t vdata_free;
39480+ atomic_long_unchecked_t gts_alloc;
39481+ atomic_long_unchecked_t gts_free;
39482+ atomic_long_unchecked_t gms_alloc;
39483+ atomic_long_unchecked_t gms_free;
39484+ atomic_long_unchecked_t gts_double_allocate;
39485+ atomic_long_unchecked_t assign_context;
39486+ atomic_long_unchecked_t assign_context_failed;
39487+ atomic_long_unchecked_t free_context;
39488+ atomic_long_unchecked_t load_user_context;
39489+ atomic_long_unchecked_t load_kernel_context;
39490+ atomic_long_unchecked_t lock_kernel_context;
39491+ atomic_long_unchecked_t unlock_kernel_context;
39492+ atomic_long_unchecked_t steal_user_context;
39493+ atomic_long_unchecked_t steal_kernel_context;
39494+ atomic_long_unchecked_t steal_context_failed;
39495+ atomic_long_unchecked_t nopfn;
39496+ atomic_long_unchecked_t asid_new;
39497+ atomic_long_unchecked_t asid_next;
39498+ atomic_long_unchecked_t asid_wrap;
39499+ atomic_long_unchecked_t asid_reuse;
39500+ atomic_long_unchecked_t intr;
39501+ atomic_long_unchecked_t intr_cbr;
39502+ atomic_long_unchecked_t intr_tfh;
39503+ atomic_long_unchecked_t intr_spurious;
39504+ atomic_long_unchecked_t intr_mm_lock_failed;
39505+ atomic_long_unchecked_t call_os;
39506+ atomic_long_unchecked_t call_os_wait_queue;
39507+ atomic_long_unchecked_t user_flush_tlb;
39508+ atomic_long_unchecked_t user_unload_context;
39509+ atomic_long_unchecked_t user_exception;
39510+ atomic_long_unchecked_t set_context_option;
39511+ atomic_long_unchecked_t check_context_retarget_intr;
39512+ atomic_long_unchecked_t check_context_unload;
39513+ atomic_long_unchecked_t tlb_dropin;
39514+ atomic_long_unchecked_t tlb_preload_page;
39515+ atomic_long_unchecked_t tlb_dropin_fail_no_asid;
39516+ atomic_long_unchecked_t tlb_dropin_fail_upm;
39517+ atomic_long_unchecked_t tlb_dropin_fail_invalid;
39518+ atomic_long_unchecked_t tlb_dropin_fail_range_active;
39519+ atomic_long_unchecked_t tlb_dropin_fail_idle;
39520+ atomic_long_unchecked_t tlb_dropin_fail_fmm;
39521+ atomic_long_unchecked_t tlb_dropin_fail_no_exception;
39522+ atomic_long_unchecked_t tfh_stale_on_fault;
39523+ atomic_long_unchecked_t mmu_invalidate_range;
39524+ atomic_long_unchecked_t mmu_invalidate_page;
39525+ atomic_long_unchecked_t flush_tlb;
39526+ atomic_long_unchecked_t flush_tlb_gru;
39527+ atomic_long_unchecked_t flush_tlb_gru_tgh;
39528+ atomic_long_unchecked_t flush_tlb_gru_zero_asid;
39529
39530- atomic_long_t copy_gpa;
39531- atomic_long_t read_gpa;
39532+ atomic_long_unchecked_t copy_gpa;
39533+ atomic_long_unchecked_t read_gpa;
39534
39535- atomic_long_t mesq_receive;
39536- atomic_long_t mesq_receive_none;
39537- atomic_long_t mesq_send;
39538- atomic_long_t mesq_send_failed;
39539- atomic_long_t mesq_noop;
39540- atomic_long_t mesq_send_unexpected_error;
39541- atomic_long_t mesq_send_lb_overflow;
39542- atomic_long_t mesq_send_qlimit_reached;
39543- atomic_long_t mesq_send_amo_nacked;
39544- atomic_long_t mesq_send_put_nacked;
39545- atomic_long_t mesq_page_overflow;
39546- atomic_long_t mesq_qf_locked;
39547- atomic_long_t mesq_qf_noop_not_full;
39548- atomic_long_t mesq_qf_switch_head_failed;
39549- atomic_long_t mesq_qf_unexpected_error;
39550- atomic_long_t mesq_noop_unexpected_error;
39551- atomic_long_t mesq_noop_lb_overflow;
39552- atomic_long_t mesq_noop_qlimit_reached;
39553- atomic_long_t mesq_noop_amo_nacked;
39554- atomic_long_t mesq_noop_put_nacked;
39555- atomic_long_t mesq_noop_page_overflow;
39556+ atomic_long_unchecked_t mesq_receive;
39557+ atomic_long_unchecked_t mesq_receive_none;
39558+ atomic_long_unchecked_t mesq_send;
39559+ atomic_long_unchecked_t mesq_send_failed;
39560+ atomic_long_unchecked_t mesq_noop;
39561+ atomic_long_unchecked_t mesq_send_unexpected_error;
39562+ atomic_long_unchecked_t mesq_send_lb_overflow;
39563+ atomic_long_unchecked_t mesq_send_qlimit_reached;
39564+ atomic_long_unchecked_t mesq_send_amo_nacked;
39565+ atomic_long_unchecked_t mesq_send_put_nacked;
39566+ atomic_long_unchecked_t mesq_page_overflow;
39567+ atomic_long_unchecked_t mesq_qf_locked;
39568+ atomic_long_unchecked_t mesq_qf_noop_not_full;
39569+ atomic_long_unchecked_t mesq_qf_switch_head_failed;
39570+ atomic_long_unchecked_t mesq_qf_unexpected_error;
39571+ atomic_long_unchecked_t mesq_noop_unexpected_error;
39572+ atomic_long_unchecked_t mesq_noop_lb_overflow;
39573+ atomic_long_unchecked_t mesq_noop_qlimit_reached;
39574+ atomic_long_unchecked_t mesq_noop_amo_nacked;
39575+ atomic_long_unchecked_t mesq_noop_put_nacked;
39576+ atomic_long_unchecked_t mesq_noop_page_overflow;
39577
39578 };
39579
39580@@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
39581 tghop_invalidate, mcsop_last};
39582
39583 struct mcs_op_statistic {
39584- atomic_long_t count;
39585- atomic_long_t total;
39586+ atomic_long_unchecked_t count;
39587+ atomic_long_unchecked_t total;
39588 unsigned long max;
39589 };
39590
39591@@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
39592
39593 #define STAT(id) do { \
39594 if (gru_options & OPT_STATS) \
39595- atomic_long_inc(&gru_stats.id); \
39596+ atomic_long_inc_unchecked(&gru_stats.id); \
39597 } while (0)
39598
39599 #ifdef CONFIG_SGI_GRU_DEBUG
39600diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
39601index c862cd4..0d176fe 100644
39602--- a/drivers/misc/sgi-xp/xp.h
39603+++ b/drivers/misc/sgi-xp/xp.h
39604@@ -288,7 +288,7 @@ struct xpc_interface {
39605 xpc_notify_func, void *);
39606 void (*received) (short, int, void *);
39607 enum xp_retval (*partid_to_nasids) (short, void *);
39608-};
39609+} __no_const;
39610
39611 extern struct xpc_interface xpc_interface;
39612
39613diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
39614index b94d5f7..7f494c5 100644
39615--- a/drivers/misc/sgi-xp/xpc.h
39616+++ b/drivers/misc/sgi-xp/xpc.h
39617@@ -835,6 +835,7 @@ struct xpc_arch_operations {
39618 void (*received_payload) (struct xpc_channel *, void *);
39619 void (*notify_senders_of_disconnect) (struct xpc_channel *);
39620 };
39621+typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
39622
39623 /* struct xpc_partition act_state values (for XPC HB) */
39624
39625@@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
39626 /* found in xpc_main.c */
39627 extern struct device *xpc_part;
39628 extern struct device *xpc_chan;
39629-extern struct xpc_arch_operations xpc_arch_ops;
39630+extern xpc_arch_operations_no_const xpc_arch_ops;
39631 extern int xpc_disengage_timelimit;
39632 extern int xpc_disengage_timedout;
39633 extern int xpc_activate_IRQ_rcvd;
39634diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
39635index d971817..33bdca5 100644
39636--- a/drivers/misc/sgi-xp/xpc_main.c
39637+++ b/drivers/misc/sgi-xp/xpc_main.c
39638@@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
39639 .notifier_call = xpc_system_die,
39640 };
39641
39642-struct xpc_arch_operations xpc_arch_ops;
39643+xpc_arch_operations_no_const xpc_arch_ops;
39644
39645 /*
39646 * Timer function to enforce the timelimit on the partition disengage.
39647@@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
39648
39649 if (((die_args->trapnr == X86_TRAP_MF) ||
39650 (die_args->trapnr == X86_TRAP_XF)) &&
39651- !user_mode_vm(die_args->regs))
39652+ !user_mode(die_args->regs))
39653 xpc_die_deactivate();
39654
39655 break;
39656diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
39657index 49f04bc..65660c2 100644
39658--- a/drivers/mmc/core/mmc_ops.c
39659+++ b/drivers/mmc/core/mmc_ops.c
39660@@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
39661 void *data_buf;
39662 int is_on_stack;
39663
39664- is_on_stack = object_is_on_stack(buf);
39665+ is_on_stack = object_starts_on_stack(buf);
39666 if (is_on_stack) {
39667 /*
39668 * dma onto stack is unsafe/nonportable, but callers to this
39669diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
39670index 53b8fd9..615b462 100644
39671--- a/drivers/mmc/host/dw_mmc.h
39672+++ b/drivers/mmc/host/dw_mmc.h
39673@@ -205,5 +205,5 @@ struct dw_mci_drv_data {
39674 int (*parse_dt)(struct dw_mci *host);
39675 int (*setup_bus)(struct dw_mci *host,
39676 struct device_node *slot_np, u8 bus_width);
39677-};
39678+} __do_const;
39679 #endif /* _DW_MMC_H_ */
39680diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
39681index 7363efe..681558e 100644
39682--- a/drivers/mmc/host/sdhci-s3c.c
39683+++ b/drivers/mmc/host/sdhci-s3c.c
39684@@ -720,9 +720,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
39685 * we can use overriding functions instead of default.
39686 */
39687 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
39688- sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39689- sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39690- sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39691+ pax_open_kernel();
39692+ *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
39693+ *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
39694+ *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
39695+ pax_close_kernel();
39696 }
39697
39698 /* It supports additional host capabilities if needed */
39699diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
39700index a4eb8b5..8c0628f 100644
39701--- a/drivers/mtd/devices/doc2000.c
39702+++ b/drivers/mtd/devices/doc2000.c
39703@@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
39704
39705 /* The ECC will not be calculated correctly if less than 512 is written */
39706 /* DBB-
39707- if (len != 0x200 && eccbuf)
39708+ if (len != 0x200)
39709 printk(KERN_WARNING
39710 "ECC needs a full sector write (adr: %lx size %lx)\n",
39711 (long) to, (long) len);
39712diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
39713index 0c8bb6b..6f35deb 100644
39714--- a/drivers/mtd/nand/denali.c
39715+++ b/drivers/mtd/nand/denali.c
39716@@ -24,6 +24,7 @@
39717 #include <linux/slab.h>
39718 #include <linux/mtd/mtd.h>
39719 #include <linux/module.h>
39720+#include <linux/slab.h>
39721
39722 #include "denali.h"
39723
39724diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
39725index 51b9d6a..52af9a7 100644
39726--- a/drivers/mtd/nftlmount.c
39727+++ b/drivers/mtd/nftlmount.c
39728@@ -24,6 +24,7 @@
39729 #include <asm/errno.h>
39730 #include <linux/delay.h>
39731 #include <linux/slab.h>
39732+#include <linux/sched.h>
39733 #include <linux/mtd/mtd.h>
39734 #include <linux/mtd/nand.h>
39735 #include <linux/mtd/nftl.h>
39736diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
39737index 8dd6ba5..419cc1d 100644
39738--- a/drivers/mtd/sm_ftl.c
39739+++ b/drivers/mtd/sm_ftl.c
39740@@ -56,7 +56,7 @@ ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
39741 #define SM_CIS_VENDOR_OFFSET 0x59
39742 struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
39743 {
39744- struct attribute_group *attr_group;
39745+ attribute_group_no_const *attr_group;
39746 struct attribute **attributes;
39747 struct sm_sysfs_attribute *vendor_attribute;
39748
39749diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
39750index dbbea0e..3f4a0b1 100644
39751--- a/drivers/net/bonding/bond_main.c
39752+++ b/drivers/net/bonding/bond_main.c
39753@@ -4822,7 +4822,7 @@ static unsigned int bond_get_num_tx_queues(void)
39754 return tx_queues;
39755 }
39756
39757-static struct rtnl_link_ops bond_link_ops __read_mostly = {
39758+static struct rtnl_link_ops bond_link_ops = {
39759 .kind = "bond",
39760 .priv_size = sizeof(struct bonding),
39761 .setup = bond_setup,
39762@@ -4947,8 +4947,8 @@ static void __exit bonding_exit(void)
39763
39764 bond_destroy_debugfs();
39765
39766- rtnl_link_unregister(&bond_link_ops);
39767 unregister_pernet_subsys(&bond_net_ops);
39768+ rtnl_link_unregister(&bond_link_ops);
39769
39770 #ifdef CONFIG_NET_POLL_CONTROLLER
39771 /*
39772diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
39773index e1d2643..7f4133b 100644
39774--- a/drivers/net/ethernet/8390/ax88796.c
39775+++ b/drivers/net/ethernet/8390/ax88796.c
39776@@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
39777 if (ax->plat->reg_offsets)
39778 ei_local->reg_offset = ax->plat->reg_offsets;
39779 else {
39780+ resource_size_t _mem_size = mem_size;
39781+ do_div(_mem_size, 0x18);
39782 ei_local->reg_offset = ax->reg_offsets;
39783 for (ret = 0; ret < 0x18; ret++)
39784- ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
39785+ ax->reg_offsets[ret] = _mem_size * ret;
39786 }
39787
39788 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
39789diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39790index aee7671..3ca2651 100644
39791--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39792+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
39793@@ -1093,7 +1093,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
39794 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
39795 {
39796 /* RX_MODE controlling object */
39797- bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
39798+ bnx2x_init_rx_mode_obj(bp);
39799
39800 /* multicast configuration controlling object */
39801 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
39802diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39803index 7306416..5fb7fb5 100644
39804--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39805+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
39806@@ -2381,15 +2381,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
39807 return rc;
39808 }
39809
39810-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39811- struct bnx2x_rx_mode_obj *o)
39812+void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
39813 {
39814 if (CHIP_IS_E1x(bp)) {
39815- o->wait_comp = bnx2x_empty_rx_mode_wait;
39816- o->config_rx_mode = bnx2x_set_rx_mode_e1x;
39817+ bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
39818+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
39819 } else {
39820- o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
39821- o->config_rx_mode = bnx2x_set_rx_mode_e2;
39822+ bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
39823+ bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
39824 }
39825 }
39826
39827diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39828index ff90760..08d8aed 100644
39829--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39830+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
39831@@ -1306,8 +1306,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
39832
39833 /********************* RX MODE ****************/
39834
39835-void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
39836- struct bnx2x_rx_mode_obj *o);
39837+void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
39838
39839 /**
39840 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
39841diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
39842index 25309bf..fcfd54c 100644
39843--- a/drivers/net/ethernet/broadcom/tg3.h
39844+++ b/drivers/net/ethernet/broadcom/tg3.h
39845@@ -147,6 +147,7 @@
39846 #define CHIPREV_ID_5750_A0 0x4000
39847 #define CHIPREV_ID_5750_A1 0x4001
39848 #define CHIPREV_ID_5750_A3 0x4003
39849+#define CHIPREV_ID_5750_C1 0x4201
39850 #define CHIPREV_ID_5750_C2 0x4202
39851 #define CHIPREV_ID_5752_A0_HW 0x5000
39852 #define CHIPREV_ID_5752_A0 0x6000
39853diff --git a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39854index 6e8bc9d..94d957d 100644
39855--- a/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39856+++ b/drivers/net/ethernet/brocade/bna/bnad_debugfs.c
39857@@ -244,7 +244,7 @@ bnad_debugfs_lseek(struct file *file, loff_t offset, int orig)
39858 file->f_pos += offset;
39859 break;
39860 case 2:
39861- file->f_pos = debug->buffer_len - offset;
39862+ file->f_pos = debug->buffer_len + offset;
39863 break;
39864 default:
39865 return -EINVAL;
39866diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39867index 8cffcdf..aadf043 100644
39868--- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39869+++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
39870@@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
39871 */
39872 struct l2t_skb_cb {
39873 arp_failure_handler_func arp_failure_handler;
39874-};
39875+} __no_const;
39876
39877 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
39878
39879diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
39880index 4c83003..2a2a5b9 100644
39881--- a/drivers/net/ethernet/dec/tulip/de4x5.c
39882+++ b/drivers/net/ethernet/dec/tulip/de4x5.c
39883@@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39884 for (i=0; i<ETH_ALEN; i++) {
39885 tmp.addr[i] = dev->dev_addr[i];
39886 }
39887- if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39888+ if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
39889 break;
39890
39891 case DE4X5_SET_HWADDR: /* Set the hardware address */
39892@@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
39893 spin_lock_irqsave(&lp->lock, flags);
39894 memcpy(&statbuf, &lp->pktStats, ioc->len);
39895 spin_unlock_irqrestore(&lp->lock, flags);
39896- if (copy_to_user(ioc->data, &statbuf, ioc->len))
39897+ if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
39898 return -EFAULT;
39899 break;
39900 }
39901diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
39902index 2886c9b..db71673 100644
39903--- a/drivers/net/ethernet/emulex/benet/be_main.c
39904+++ b/drivers/net/ethernet/emulex/benet/be_main.c
39905@@ -455,7 +455,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
39906
39907 if (wrapped)
39908 newacc += 65536;
39909- ACCESS_ONCE(*acc) = newacc;
39910+ ACCESS_ONCE_RW(*acc) = newacc;
39911 }
39912
39913 void be_parse_stats(struct be_adapter *adapter)
39914diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
39915index 7c361d1..57e3ff1 100644
39916--- a/drivers/net/ethernet/faraday/ftgmac100.c
39917+++ b/drivers/net/ethernet/faraday/ftgmac100.c
39918@@ -31,6 +31,8 @@
39919 #include <linux/netdevice.h>
39920 #include <linux/phy.h>
39921 #include <linux/platform_device.h>
39922+#include <linux/interrupt.h>
39923+#include <linux/irqreturn.h>
39924 #include <net/ip.h>
39925
39926 #include "ftgmac100.h"
39927diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
39928index b5ea8fb..bd25e9a 100644
39929--- a/drivers/net/ethernet/faraday/ftmac100.c
39930+++ b/drivers/net/ethernet/faraday/ftmac100.c
39931@@ -31,6 +31,8 @@
39932 #include <linux/module.h>
39933 #include <linux/netdevice.h>
39934 #include <linux/platform_device.h>
39935+#include <linux/interrupt.h>
39936+#include <linux/irqreturn.h>
39937
39938 #include "ftmac100.h"
39939
39940diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39941index 331987d..3be1135 100644
39942--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39943+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
39944@@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
39945 }
39946
39947 /* update the base incval used to calculate frequency adjustment */
39948- ACCESS_ONCE(adapter->base_incval) = incval;
39949+ ACCESS_ONCE_RW(adapter->base_incval) = incval;
39950 smp_mb();
39951
39952 /* need lock to prevent incorrect read while modifying cyclecounter */
39953diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39954index fbe5363..266b4e3 100644
39955--- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
39956+++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
39957@@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39958 struct __vxge_hw_fifo *fifo;
39959 struct vxge_hw_fifo_config *config;
39960 u32 txdl_size, txdl_per_memblock;
39961- struct vxge_hw_mempool_cbs fifo_mp_callback;
39962+ static struct vxge_hw_mempool_cbs fifo_mp_callback = {
39963+ .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
39964+ };
39965+
39966 struct __vxge_hw_virtualpath *vpath;
39967
39968 if ((vp == NULL) || (attr == NULL)) {
39969@@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
39970 goto exit;
39971 }
39972
39973- fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
39974-
39975 fifo->mempool =
39976 __vxge_hw_mempool_create(vpath->hldev,
39977 fifo->config->memblock_size,
39978diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39979index 5c033f2..7bbb0d8 100644
39980--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39981+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
39982@@ -1894,7 +1894,9 @@ int qlcnic_83xx_config_default_opmode(struct qlcnic_adapter *adapter)
39983 op_mode = QLCRDX(ahw, QLC_83XX_DRV_OP_MODE);
39984
39985 if (op_mode == QLC_83XX_DEFAULT_OPMODE) {
39986- adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
39987+ pax_open_kernel();
39988+ *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
39989+ pax_close_kernel();
39990 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
39991 } else {
39992 return -EIO;
39993diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39994index b0c3de9..fc5857e 100644
39995--- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39996+++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
39997@@ -200,15 +200,21 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
39998 if (priv_level == QLCNIC_NON_PRIV_FUNC) {
39999 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
40000 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40001- nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40002+ pax_open_kernel();
40003+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
40004+ pax_close_kernel();
40005 } else if (priv_level == QLCNIC_PRIV_FUNC) {
40006 ahw->op_mode = QLCNIC_PRIV_FUNC;
40007 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
40008- nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40009+ pax_open_kernel();
40010+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
40011+ pax_close_kernel();
40012 } else if (priv_level == QLCNIC_MGMT_FUNC) {
40013 ahw->op_mode = QLCNIC_MGMT_FUNC;
40014 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
40015- nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40016+ pax_open_kernel();
40017+ *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
40018+ pax_close_kernel();
40019 } else {
40020 return -EIO;
40021 }
40022diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
40023index 54fd2ef..33c8a4f 100644
40024--- a/drivers/net/ethernet/realtek/r8169.c
40025+++ b/drivers/net/ethernet/realtek/r8169.c
40026@@ -740,22 +740,22 @@ struct rtl8169_private {
40027 struct mdio_ops {
40028 void (*write)(struct rtl8169_private *, int, int);
40029 int (*read)(struct rtl8169_private *, int);
40030- } mdio_ops;
40031+ } __no_const mdio_ops;
40032
40033 struct pll_power_ops {
40034 void (*down)(struct rtl8169_private *);
40035 void (*up)(struct rtl8169_private *);
40036- } pll_power_ops;
40037+ } __no_const pll_power_ops;
40038
40039 struct jumbo_ops {
40040 void (*enable)(struct rtl8169_private *);
40041 void (*disable)(struct rtl8169_private *);
40042- } jumbo_ops;
40043+ } __no_const jumbo_ops;
40044
40045 struct csi_ops {
40046 void (*write)(struct rtl8169_private *, int, int);
40047 u32 (*read)(struct rtl8169_private *, int);
40048- } csi_ops;
40049+ } __no_const csi_ops;
40050
40051 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
40052 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
40053diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
40054index 3f93624..cf01144 100644
40055--- a/drivers/net/ethernet/sfc/ptp.c
40056+++ b/drivers/net/ethernet/sfc/ptp.c
40057@@ -553,7 +553,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
40058 (u32)((u64)ptp->start.dma_addr >> 32));
40059
40060 /* Clear flag that signals MC ready */
40061- ACCESS_ONCE(*start) = 0;
40062+ ACCESS_ONCE_RW(*start) = 0;
40063 efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
40064 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
40065
40066diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40067index 50617c5..b13724c 100644
40068--- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40069+++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
40070@@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
40071
40072 writel(value, ioaddr + MMC_CNTRL);
40073
40074- pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40075- MMC_CNTRL, value);
40076+// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
40077+// MMC_CNTRL, value);
40078 }
40079
40080 /* To mask all all interrupts.*/
40081diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
40082index e6fe0d8..2b7d752 100644
40083--- a/drivers/net/hyperv/hyperv_net.h
40084+++ b/drivers/net/hyperv/hyperv_net.h
40085@@ -101,7 +101,7 @@ struct rndis_device {
40086
40087 enum rndis_device_state state;
40088 bool link_state;
40089- atomic_t new_req_id;
40090+ atomic_unchecked_t new_req_id;
40091
40092 spinlock_t request_lock;
40093 struct list_head req_list;
40094diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
40095index 0775f0a..d4fb316 100644
40096--- a/drivers/net/hyperv/rndis_filter.c
40097+++ b/drivers/net/hyperv/rndis_filter.c
40098@@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
40099 * template
40100 */
40101 set = &rndis_msg->msg.set_req;
40102- set->req_id = atomic_inc_return(&dev->new_req_id);
40103+ set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40104
40105 /* Add to the request list */
40106 spin_lock_irqsave(&dev->request_lock, flags);
40107@@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
40108
40109 /* Setup the rndis set */
40110 halt = &request->request_msg.msg.halt_req;
40111- halt->req_id = atomic_inc_return(&dev->new_req_id);
40112+ halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
40113
40114 /* Ignore return since this msg is optional. */
40115 rndis_filter_send_request(dev, request);
40116diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
40117index 8f1c256..a2991d1 100644
40118--- a/drivers/net/ieee802154/fakehard.c
40119+++ b/drivers/net/ieee802154/fakehard.c
40120@@ -385,7 +385,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
40121 phy->transmit_power = 0xbf;
40122
40123 dev->netdev_ops = &fake_ops;
40124- dev->ml_priv = &fake_mlme;
40125+ dev->ml_priv = (void *)&fake_mlme;
40126
40127 priv = netdev_priv(dev);
40128 priv->phy = phy;
40129diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
40130index 011062e..ada88e9 100644
40131--- a/drivers/net/macvlan.c
40132+++ b/drivers/net/macvlan.c
40133@@ -892,13 +892,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
40134 int macvlan_link_register(struct rtnl_link_ops *ops)
40135 {
40136 /* common fields */
40137- ops->priv_size = sizeof(struct macvlan_dev);
40138- ops->validate = macvlan_validate;
40139- ops->maxtype = IFLA_MACVLAN_MAX;
40140- ops->policy = macvlan_policy;
40141- ops->changelink = macvlan_changelink;
40142- ops->get_size = macvlan_get_size;
40143- ops->fill_info = macvlan_fill_info;
40144+ pax_open_kernel();
40145+ *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
40146+ *(void **)&ops->validate = macvlan_validate;
40147+ *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
40148+ *(const void **)&ops->policy = macvlan_policy;
40149+ *(void **)&ops->changelink = macvlan_changelink;
40150+ *(void **)&ops->get_size = macvlan_get_size;
40151+ *(void **)&ops->fill_info = macvlan_fill_info;
40152+ pax_close_kernel();
40153
40154 return rtnl_link_register(ops);
40155 };
40156@@ -954,7 +956,7 @@ static int macvlan_device_event(struct notifier_block *unused,
40157 return NOTIFY_DONE;
40158 }
40159
40160-static struct notifier_block macvlan_notifier_block __read_mostly = {
40161+static struct notifier_block macvlan_notifier_block = {
40162 .notifier_call = macvlan_device_event,
40163 };
40164
40165diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
40166index acf6450..8f771b7 100644
40167--- a/drivers/net/macvtap.c
40168+++ b/drivers/net/macvtap.c
40169@@ -525,8 +525,10 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
40170 return -EMSGSIZE;
40171 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
40172 if (num_pages != size) {
40173- for (i = 0; i < num_pages; i++)
40174- put_page(page[i]);
40175+ int j;
40176+
40177+ for (j = 0; j < num_pages; j++)
40178+ put_page(page[i + j]);
40179 return -EFAULT;
40180 }
40181 truesize = size * PAGE_SIZE;
40182@@ -1099,7 +1101,7 @@ static int macvtap_device_event(struct notifier_block *unused,
40183 return NOTIFY_DONE;
40184 }
40185
40186-static struct notifier_block macvtap_notifier_block __read_mostly = {
40187+static struct notifier_block macvtap_notifier_block = {
40188 .notifier_call = macvtap_device_event,
40189 };
40190
40191diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
40192index daec9b0..6428fcb 100644
40193--- a/drivers/net/phy/mdio-bitbang.c
40194+++ b/drivers/net/phy/mdio-bitbang.c
40195@@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
40196 struct mdiobb_ctrl *ctrl = bus->priv;
40197
40198 module_put(ctrl->ops->owner);
40199+ mdiobus_unregister(bus);
40200 mdiobus_free(bus);
40201 }
40202 EXPORT_SYMBOL(free_mdio_bitbang);
40203diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
40204index 72ff14b..11d442d 100644
40205--- a/drivers/net/ppp/ppp_generic.c
40206+++ b/drivers/net/ppp/ppp_generic.c
40207@@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40208 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
40209 struct ppp_stats stats;
40210 struct ppp_comp_stats cstats;
40211- char *vers;
40212
40213 switch (cmd) {
40214 case SIOCGPPPSTATS:
40215@@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
40216 break;
40217
40218 case SIOCGPPPVER:
40219- vers = PPP_VERSION;
40220- if (copy_to_user(addr, vers, strlen(vers) + 1))
40221+ if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
40222 break;
40223 err = 0;
40224 break;
40225diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
40226index 1252d9c..80e660b 100644
40227--- a/drivers/net/slip/slhc.c
40228+++ b/drivers/net/slip/slhc.c
40229@@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
40230 register struct tcphdr *thp;
40231 register struct iphdr *ip;
40232 register struct cstate *cs;
40233- int len, hdrlen;
40234+ long len, hdrlen;
40235 unsigned char *cp = icp;
40236
40237 /* We've got a compressed packet; read the change byte */
40238diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
40239index 0017b67..ab8f595 100644
40240--- a/drivers/net/team/team.c
40241+++ b/drivers/net/team/team.c
40242@@ -2668,7 +2668,7 @@ static int team_device_event(struct notifier_block *unused,
40243 return NOTIFY_DONE;
40244 }
40245
40246-static struct notifier_block team_notifier_block __read_mostly = {
40247+static struct notifier_block team_notifier_block = {
40248 .notifier_call = team_device_event,
40249 };
40250
40251diff --git a/drivers/net/tun.c b/drivers/net/tun.c
40252index 8ad822e..eb895f1 100644
40253--- a/drivers/net/tun.c
40254+++ b/drivers/net/tun.c
40255@@ -1013,8 +1013,10 @@ static int zerocopy_sg_from_iovec(struct sk_buff *skb, const struct iovec *from,
40256 return -EMSGSIZE;
40257 num_pages = get_user_pages_fast(base, size, 0, &page[i]);
40258 if (num_pages != size) {
40259- for (i = 0; i < num_pages; i++)
40260- put_page(page[i]);
40261+ int j;
40262+
40263+ for (j = 0; j < num_pages; j++)
40264+ put_page(page[i + j]);
40265 return -EFAULT;
40266 }
40267 truesize = size * PAGE_SIZE;
40268@@ -1859,7 +1861,7 @@ unlock:
40269 }
40270
40271 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40272- unsigned long arg, int ifreq_len)
40273+ unsigned long arg, size_t ifreq_len)
40274 {
40275 struct tun_file *tfile = file->private_data;
40276 struct tun_struct *tun;
40277@@ -1871,6 +1873,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
40278 int vnet_hdr_sz;
40279 int ret;
40280
40281+ if (ifreq_len > sizeof ifr)
40282+ return -EFAULT;
40283+
40284 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
40285 if (copy_from_user(&ifr, argp, ifreq_len))
40286 return -EFAULT;
40287diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
40288index e2dd324..be92fcf 100644
40289--- a/drivers/net/usb/hso.c
40290+++ b/drivers/net/usb/hso.c
40291@@ -71,7 +71,7 @@
40292 #include <asm/byteorder.h>
40293 #include <linux/serial_core.h>
40294 #include <linux/serial.h>
40295-
40296+#include <asm/local.h>
40297
40298 #define MOD_AUTHOR "Option Wireless"
40299 #define MOD_DESCRIPTION "USB High Speed Option driver"
40300@@ -1180,7 +1180,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
40301 struct urb *urb;
40302
40303 urb = serial->rx_urb[0];
40304- if (serial->port.count > 0) {
40305+ if (atomic_read(&serial->port.count) > 0) {
40306 count = put_rxbuf_data(urb, serial);
40307 if (count == -1)
40308 return;
40309@@ -1216,7 +1216,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
40310 DUMP1(urb->transfer_buffer, urb->actual_length);
40311
40312 /* Anyone listening? */
40313- if (serial->port.count == 0)
40314+ if (atomic_read(&serial->port.count) == 0)
40315 return;
40316
40317 if (status == 0) {
40318@@ -1298,8 +1298,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40319 tty_port_tty_set(&serial->port, tty);
40320
40321 /* check for port already opened, if not set the termios */
40322- serial->port.count++;
40323- if (serial->port.count == 1) {
40324+ if (atomic_inc_return(&serial->port.count) == 1) {
40325 serial->rx_state = RX_IDLE;
40326 /* Force default termio settings */
40327 _hso_serial_set_termios(tty, NULL);
40328@@ -1311,7 +1310,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
40329 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
40330 if (result) {
40331 hso_stop_serial_device(serial->parent);
40332- serial->port.count--;
40333+ atomic_dec(&serial->port.count);
40334 kref_put(&serial->parent->ref, hso_serial_ref_free);
40335 }
40336 } else {
40337@@ -1348,10 +1347,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
40338
40339 /* reset the rts and dtr */
40340 /* do the actual close */
40341- serial->port.count--;
40342+ atomic_dec(&serial->port.count);
40343
40344- if (serial->port.count <= 0) {
40345- serial->port.count = 0;
40346+ if (atomic_read(&serial->port.count) <= 0) {
40347+ atomic_set(&serial->port.count, 0);
40348 tty_port_tty_set(&serial->port, NULL);
40349 if (!usb_gone)
40350 hso_stop_serial_device(serial->parent);
40351@@ -1427,7 +1426,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
40352
40353 /* the actual setup */
40354 spin_lock_irqsave(&serial->serial_lock, flags);
40355- if (serial->port.count)
40356+ if (atomic_read(&serial->port.count))
40357 _hso_serial_set_termios(tty, old);
40358 else
40359 tty->termios = *old;
40360@@ -1886,7 +1885,7 @@ static void intr_callback(struct urb *urb)
40361 D1("Pending read interrupt on port %d\n", i);
40362 spin_lock(&serial->serial_lock);
40363 if (serial->rx_state == RX_IDLE &&
40364- serial->port.count > 0) {
40365+ atomic_read(&serial->port.count) > 0) {
40366 /* Setup and send a ctrl req read on
40367 * port i */
40368 if (!serial->rx_urb_filled[0]) {
40369@@ -3066,7 +3065,7 @@ static int hso_resume(struct usb_interface *iface)
40370 /* Start all serial ports */
40371 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
40372 if (serial_table[i] && (serial_table[i]->interface == iface)) {
40373- if (dev2ser(serial_table[i])->port.count) {
40374+ if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
40375 result =
40376 hso_start_serial_device(serial_table[i], GFP_NOIO);
40377 hso_kick_transmit(dev2ser(serial_table[i]));
40378diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
40379index a4fe5f1..6c9e77f 100644
40380--- a/drivers/net/vxlan.c
40381+++ b/drivers/net/vxlan.c
40382@@ -1454,7 +1454,7 @@ nla_put_failure:
40383 return -EMSGSIZE;
40384 }
40385
40386-static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
40387+static struct rtnl_link_ops vxlan_link_ops = {
40388 .kind = "vxlan",
40389 .maxtype = IFLA_VXLAN_MAX,
40390 .policy = vxlan_policy,
40391diff --git a/drivers/net/wan/dlci.c b/drivers/net/wan/dlci.c
40392index 147614e..6a8a382 100644
40393--- a/drivers/net/wan/dlci.c
40394+++ b/drivers/net/wan/dlci.c
40395@@ -384,21 +384,37 @@ static int dlci_del(struct dlci_add *dlci)
40396 struct frad_local *flp;
40397 struct net_device *master, *slave;
40398 int err;
40399+ bool found = false;
40400+
40401+ rtnl_lock();
40402
40403 /* validate slave device */
40404 master = __dev_get_by_name(&init_net, dlci->devname);
40405- if (!master)
40406- return -ENODEV;
40407+ if (!master) {
40408+ err = -ENODEV;
40409+ goto out;
40410+ }
40411+
40412+ list_for_each_entry(dlp, &dlci_devs, list) {
40413+ if (dlp->master == master) {
40414+ found = true;
40415+ break;
40416+ }
40417+ }
40418+ if (!found) {
40419+ err = -ENODEV;
40420+ goto out;
40421+ }
40422
40423 if (netif_running(master)) {
40424- return -EBUSY;
40425+ err = -EBUSY;
40426+ goto out;
40427 }
40428
40429 dlp = netdev_priv(master);
40430 slave = dlp->slave;
40431 flp = netdev_priv(slave);
40432
40433- rtnl_lock();
40434 err = (*flp->deassoc)(slave, master);
40435 if (!err) {
40436 list_del(&dlp->list);
40437@@ -407,8 +423,8 @@ static int dlci_del(struct dlci_add *dlci)
40438
40439 dev_put(slave);
40440 }
40441+out:
40442 rtnl_unlock();
40443-
40444 return err;
40445 }
40446
40447diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
40448index 5ac5f7a..5f82012 100644
40449--- a/drivers/net/wireless/at76c50x-usb.c
40450+++ b/drivers/net/wireless/at76c50x-usb.c
40451@@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
40452 }
40453
40454 /* Convert timeout from the DFU status to jiffies */
40455-static inline unsigned long at76_get_timeout(struct dfu_status *s)
40456+static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
40457 {
40458 return msecs_to_jiffies((s->poll_timeout[2] << 16)
40459 | (s->poll_timeout[1] << 8)
40460diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40461index 8d78253..bebbb68 100644
40462--- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40463+++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
40464@@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40465 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
40466 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
40467
40468- ACCESS_ONCE(ads->ds_link) = i->link;
40469- ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
40470+ ACCESS_ONCE_RW(ads->ds_link) = i->link;
40471+ ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
40472
40473 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
40474 ctl6 = SM(i->keytype, AR_EncrType);
40475@@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40476
40477 if ((i->is_first || i->is_last) &&
40478 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
40479- ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
40480+ ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
40481 | set11nTries(i->rates, 1)
40482 | set11nTries(i->rates, 2)
40483 | set11nTries(i->rates, 3)
40484 | (i->dur_update ? AR_DurUpdateEna : 0)
40485 | SM(0, AR_BurstDur);
40486
40487- ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
40488+ ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
40489 | set11nRate(i->rates, 1)
40490 | set11nRate(i->rates, 2)
40491 | set11nRate(i->rates, 3);
40492 } else {
40493- ACCESS_ONCE(ads->ds_ctl2) = 0;
40494- ACCESS_ONCE(ads->ds_ctl3) = 0;
40495+ ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
40496+ ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
40497 }
40498
40499 if (!i->is_first) {
40500- ACCESS_ONCE(ads->ds_ctl0) = 0;
40501- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40502- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40503+ ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
40504+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40505+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40506 return;
40507 }
40508
40509@@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40510 break;
40511 }
40512
40513- ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40514+ ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
40515 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40516 | SM(i->txpower, AR_XmitPower)
40517 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40518@@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40519 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
40520 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
40521
40522- ACCESS_ONCE(ads->ds_ctl1) = ctl1;
40523- ACCESS_ONCE(ads->ds_ctl6) = ctl6;
40524+ ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
40525+ ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
40526
40527 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
40528 return;
40529
40530- ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40531+ ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
40532 | set11nPktDurRTSCTS(i->rates, 1);
40533
40534- ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40535+ ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
40536 | set11nPktDurRTSCTS(i->rates, 3);
40537
40538- ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40539+ ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
40540 | set11nRateFlags(i->rates, 1)
40541 | set11nRateFlags(i->rates, 2)
40542 | set11nRateFlags(i->rates, 3)
40543diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40544index 301bf72..3f5654f 100644
40545--- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40546+++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
40547@@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40548 (i->qcu << AR_TxQcuNum_S) | desc_len;
40549
40550 checksum += val;
40551- ACCESS_ONCE(ads->info) = val;
40552+ ACCESS_ONCE_RW(ads->info) = val;
40553
40554 checksum += i->link;
40555- ACCESS_ONCE(ads->link) = i->link;
40556+ ACCESS_ONCE_RW(ads->link) = i->link;
40557
40558 checksum += i->buf_addr[0];
40559- ACCESS_ONCE(ads->data0) = i->buf_addr[0];
40560+ ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
40561 checksum += i->buf_addr[1];
40562- ACCESS_ONCE(ads->data1) = i->buf_addr[1];
40563+ ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
40564 checksum += i->buf_addr[2];
40565- ACCESS_ONCE(ads->data2) = i->buf_addr[2];
40566+ ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
40567 checksum += i->buf_addr[3];
40568- ACCESS_ONCE(ads->data3) = i->buf_addr[3];
40569+ ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
40570
40571 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
40572- ACCESS_ONCE(ads->ctl3) = val;
40573+ ACCESS_ONCE_RW(ads->ctl3) = val;
40574 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
40575- ACCESS_ONCE(ads->ctl5) = val;
40576+ ACCESS_ONCE_RW(ads->ctl5) = val;
40577 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
40578- ACCESS_ONCE(ads->ctl7) = val;
40579+ ACCESS_ONCE_RW(ads->ctl7) = val;
40580 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
40581- ACCESS_ONCE(ads->ctl9) = val;
40582+ ACCESS_ONCE_RW(ads->ctl9) = val;
40583
40584 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
40585- ACCESS_ONCE(ads->ctl10) = checksum;
40586+ ACCESS_ONCE_RW(ads->ctl10) = checksum;
40587
40588 if (i->is_first || i->is_last) {
40589- ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
40590+ ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
40591 | set11nTries(i->rates, 1)
40592 | set11nTries(i->rates, 2)
40593 | set11nTries(i->rates, 3)
40594 | (i->dur_update ? AR_DurUpdateEna : 0)
40595 | SM(0, AR_BurstDur);
40596
40597- ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
40598+ ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
40599 | set11nRate(i->rates, 1)
40600 | set11nRate(i->rates, 2)
40601 | set11nRate(i->rates, 3);
40602 } else {
40603- ACCESS_ONCE(ads->ctl13) = 0;
40604- ACCESS_ONCE(ads->ctl14) = 0;
40605+ ACCESS_ONCE_RW(ads->ctl13) = 0;
40606+ ACCESS_ONCE_RW(ads->ctl14) = 0;
40607 }
40608
40609 ads->ctl20 = 0;
40610@@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40611
40612 ctl17 = SM(i->keytype, AR_EncrType);
40613 if (!i->is_first) {
40614- ACCESS_ONCE(ads->ctl11) = 0;
40615- ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40616- ACCESS_ONCE(ads->ctl15) = 0;
40617- ACCESS_ONCE(ads->ctl16) = 0;
40618- ACCESS_ONCE(ads->ctl17) = ctl17;
40619- ACCESS_ONCE(ads->ctl18) = 0;
40620- ACCESS_ONCE(ads->ctl19) = 0;
40621+ ACCESS_ONCE_RW(ads->ctl11) = 0;
40622+ ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
40623+ ACCESS_ONCE_RW(ads->ctl15) = 0;
40624+ ACCESS_ONCE_RW(ads->ctl16) = 0;
40625+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40626+ ACCESS_ONCE_RW(ads->ctl18) = 0;
40627+ ACCESS_ONCE_RW(ads->ctl19) = 0;
40628 return;
40629 }
40630
40631- ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40632+ ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
40633 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
40634 | SM(i->txpower, AR_XmitPower)
40635 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
40636@@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
40637 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
40638 ctl12 |= SM(val, AR_PAPRDChainMask);
40639
40640- ACCESS_ONCE(ads->ctl12) = ctl12;
40641- ACCESS_ONCE(ads->ctl17) = ctl17;
40642+ ACCESS_ONCE_RW(ads->ctl12) = ctl12;
40643+ ACCESS_ONCE_RW(ads->ctl17) = ctl17;
40644
40645- ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40646+ ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
40647 | set11nPktDurRTSCTS(i->rates, 1);
40648
40649- ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40650+ ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
40651 | set11nPktDurRTSCTS(i->rates, 3);
40652
40653- ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
40654+ ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
40655 | set11nRateFlags(i->rates, 1)
40656 | set11nRateFlags(i->rates, 2)
40657 | set11nRateFlags(i->rates, 3)
40658 | SM(i->rtscts_rate, AR_RTSCTSRate);
40659
40660- ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
40661+ ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
40662 }
40663
40664 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
40665diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
40666index 784e81c..349e01e 100644
40667--- a/drivers/net/wireless/ath/ath9k/hw.h
40668+++ b/drivers/net/wireless/ath/ath9k/hw.h
40669@@ -653,7 +653,7 @@ struct ath_hw_private_ops {
40670
40671 /* ANI */
40672 void (*ani_cache_ini_regs)(struct ath_hw *ah);
40673-};
40674+} __no_const;
40675
40676 /**
40677 * struct ath_spec_scan - parameters for Atheros spectral scan
40678@@ -722,7 +722,7 @@ struct ath_hw_ops {
40679 struct ath_spec_scan *param);
40680 void (*spectral_scan_trigger)(struct ath_hw *ah);
40681 void (*spectral_scan_wait)(struct ath_hw *ah);
40682-};
40683+} __no_const;
40684
40685 struct ath_nf_limits {
40686 s16 max;
40687diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
40688index c353b5f..62aaca2 100644
40689--- a/drivers/net/wireless/iwlegacy/3945-mac.c
40690+++ b/drivers/net/wireless/iwlegacy/3945-mac.c
40691@@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
40692 */
40693 if (il3945_mod_params.disable_hw_scan) {
40694 D_INFO("Disabling hw_scan\n");
40695- il3945_mac_ops.hw_scan = NULL;
40696+ pax_open_kernel();
40697+ *(void **)&il3945_mac_ops.hw_scan = NULL;
40698+ pax_close_kernel();
40699 }
40700
40701 D_INFO("*** LOAD DRIVER ***\n");
40702diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40703index 81d4071..f2071ea 100644
40704--- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40705+++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
40706@@ -203,7 +203,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
40707 {
40708 struct iwl_priv *priv = file->private_data;
40709 char buf[64];
40710- int buf_size;
40711+ size_t buf_size;
40712 u32 offset, len;
40713
40714 memset(buf, 0, sizeof(buf));
40715@@ -473,7 +473,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
40716 struct iwl_priv *priv = file->private_data;
40717
40718 char buf[8];
40719- int buf_size;
40720+ size_t buf_size;
40721 u32 reset_flag;
40722
40723 memset(buf, 0, sizeof(buf));
40724@@ -554,7 +554,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
40725 {
40726 struct iwl_priv *priv = file->private_data;
40727 char buf[8];
40728- int buf_size;
40729+ size_t buf_size;
40730 int ht40;
40731
40732 memset(buf, 0, sizeof(buf));
40733@@ -606,7 +606,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
40734 {
40735 struct iwl_priv *priv = file->private_data;
40736 char buf[8];
40737- int buf_size;
40738+ size_t buf_size;
40739 int value;
40740
40741 memset(buf, 0, sizeof(buf));
40742@@ -1871,7 +1871,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
40743 {
40744 struct iwl_priv *priv = file->private_data;
40745 char buf[8];
40746- int buf_size;
40747+ size_t buf_size;
40748 int clear;
40749
40750 memset(buf, 0, sizeof(buf));
40751@@ -1916,7 +1916,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
40752 {
40753 struct iwl_priv *priv = file->private_data;
40754 char buf[8];
40755- int buf_size;
40756+ size_t buf_size;
40757 int trace;
40758
40759 memset(buf, 0, sizeof(buf));
40760@@ -1987,7 +1987,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
40761 {
40762 struct iwl_priv *priv = file->private_data;
40763 char buf[8];
40764- int buf_size;
40765+ size_t buf_size;
40766 int missed;
40767
40768 memset(buf, 0, sizeof(buf));
40769@@ -2028,7 +2028,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
40770
40771 struct iwl_priv *priv = file->private_data;
40772 char buf[8];
40773- int buf_size;
40774+ size_t buf_size;
40775 int plcp;
40776
40777 memset(buf, 0, sizeof(buf));
40778@@ -2088,7 +2088,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
40779
40780 struct iwl_priv *priv = file->private_data;
40781 char buf[8];
40782- int buf_size;
40783+ size_t buf_size;
40784 int flush;
40785
40786 memset(buf, 0, sizeof(buf));
40787@@ -2178,7 +2178,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
40788
40789 struct iwl_priv *priv = file->private_data;
40790 char buf[8];
40791- int buf_size;
40792+ size_t buf_size;
40793 int rts;
40794
40795 if (!priv->cfg->ht_params)
40796@@ -2220,7 +2220,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
40797 {
40798 struct iwl_priv *priv = file->private_data;
40799 char buf[8];
40800- int buf_size;
40801+ size_t buf_size;
40802
40803 memset(buf, 0, sizeof(buf));
40804 buf_size = min(count, sizeof(buf) - 1);
40805@@ -2256,7 +2256,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
40806 struct iwl_priv *priv = file->private_data;
40807 u32 event_log_flag;
40808 char buf[8];
40809- int buf_size;
40810+ size_t buf_size;
40811
40812 /* check that the interface is up */
40813 if (!iwl_is_ready(priv))
40814@@ -2310,7 +2310,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
40815 struct iwl_priv *priv = file->private_data;
40816 char buf[8];
40817 u32 calib_disabled;
40818- int buf_size;
40819+ size_t buf_size;
40820
40821 memset(buf, 0, sizeof(buf));
40822 buf_size = min(count, sizeof(buf) - 1);
40823diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
40824index 12c4f31..484d948 100644
40825--- a/drivers/net/wireless/iwlwifi/pcie/trans.c
40826+++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
40827@@ -1328,7 +1328,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
40828 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
40829
40830 char buf[8];
40831- int buf_size;
40832+ size_t buf_size;
40833 u32 reset_flag;
40834
40835 memset(buf, 0, sizeof(buf));
40836@@ -1349,7 +1349,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
40837 {
40838 struct iwl_trans *trans = file->private_data;
40839 char buf[8];
40840- int buf_size;
40841+ size_t buf_size;
40842 int csr;
40843
40844 memset(buf, 0, sizeof(buf));
40845diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
40846index 2b49f48..14fc244 100644
40847--- a/drivers/net/wireless/mac80211_hwsim.c
40848+++ b/drivers/net/wireless/mac80211_hwsim.c
40849@@ -2143,25 +2143,19 @@ static int __init init_mac80211_hwsim(void)
40850
40851 if (channels > 1) {
40852 hwsim_if_comb.num_different_channels = channels;
40853- mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40854- mac80211_hwsim_ops.cancel_hw_scan =
40855- mac80211_hwsim_cancel_hw_scan;
40856- mac80211_hwsim_ops.sw_scan_start = NULL;
40857- mac80211_hwsim_ops.sw_scan_complete = NULL;
40858- mac80211_hwsim_ops.remain_on_channel =
40859- mac80211_hwsim_roc;
40860- mac80211_hwsim_ops.cancel_remain_on_channel =
40861- mac80211_hwsim_croc;
40862- mac80211_hwsim_ops.add_chanctx =
40863- mac80211_hwsim_add_chanctx;
40864- mac80211_hwsim_ops.remove_chanctx =
40865- mac80211_hwsim_remove_chanctx;
40866- mac80211_hwsim_ops.change_chanctx =
40867- mac80211_hwsim_change_chanctx;
40868- mac80211_hwsim_ops.assign_vif_chanctx =
40869- mac80211_hwsim_assign_vif_chanctx;
40870- mac80211_hwsim_ops.unassign_vif_chanctx =
40871- mac80211_hwsim_unassign_vif_chanctx;
40872+ pax_open_kernel();
40873+ *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
40874+ *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
40875+ *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
40876+ *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
40877+ *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
40878+ *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
40879+ *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
40880+ *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
40881+ *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
40882+ *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
40883+ *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
40884+ pax_close_kernel();
40885 }
40886
40887 spin_lock_init(&hwsim_radio_lock);
40888diff --git a/drivers/net/wireless/mwifiex/debugfs.c b/drivers/net/wireless/mwifiex/debugfs.c
40889index 753b568..a5f9875 100644
40890--- a/drivers/net/wireless/mwifiex/debugfs.c
40891+++ b/drivers/net/wireless/mwifiex/debugfs.c
40892@@ -26,10 +26,17 @@
40893 static struct dentry *mwifiex_dfs_dir;
40894
40895 static char *bss_modes[] = {
40896- "Unknown",
40897- "Ad-hoc",
40898- "Managed",
40899- "Auto"
40900+ "UNSPECIFIED",
40901+ "ADHOC",
40902+ "STATION",
40903+ "AP",
40904+ "AP_VLAN",
40905+ "WDS",
40906+ "MONITOR",
40907+ "MESH_POINT",
40908+ "P2P_CLIENT",
40909+ "P2P_GO",
40910+ "P2P_DEVICE",
40911 };
40912
40913 /* size/addr for mwifiex_debug_info */
40914@@ -200,7 +207,12 @@ mwifiex_info_read(struct file *file, char __user *ubuf,
40915 p += sprintf(p, "driver_version = %s", fmt);
40916 p += sprintf(p, "\nverext = %s", priv->version_str);
40917 p += sprintf(p, "\ninterface_name=\"%s\"\n", netdev->name);
40918- p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
40919+
40920+ if (info.bss_mode >= ARRAY_SIZE(bss_modes))
40921+ p += sprintf(p, "bss_mode=\"%d\"\n", info.bss_mode);
40922+ else
40923+ p += sprintf(p, "bss_mode=\"%s\"\n", bss_modes[info.bss_mode]);
40924+
40925 p += sprintf(p, "media_state=\"%s\"\n",
40926 (!priv->media_connected ? "Disconnected" : "Connected"));
40927 p += sprintf(p, "mac_address=\"%pM\"\n", netdev->dev_addr);
40928diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
40929index 525fd75..6c9f791 100644
40930--- a/drivers/net/wireless/rndis_wlan.c
40931+++ b/drivers/net/wireless/rndis_wlan.c
40932@@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
40933
40934 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
40935
40936- if (rts_threshold < 0 || rts_threshold > 2347)
40937+ if (rts_threshold > 2347)
40938 rts_threshold = 2347;
40939
40940 tmp = cpu_to_le32(rts_threshold);
40941diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
40942index 086abb4..8279c30 100644
40943--- a/drivers/net/wireless/rt2x00/rt2x00.h
40944+++ b/drivers/net/wireless/rt2x00/rt2x00.h
40945@@ -396,7 +396,7 @@ struct rt2x00_intf {
40946 * for hardware which doesn't support hardware
40947 * sequence counting.
40948 */
40949- atomic_t seqno;
40950+ atomic_unchecked_t seqno;
40951 };
40952
40953 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
40954diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
40955index 4d91795..62fccff 100644
40956--- a/drivers/net/wireless/rt2x00/rt2x00queue.c
40957+++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
40958@@ -251,9 +251,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
40959 * sequence counter given by mac80211.
40960 */
40961 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
40962- seqno = atomic_add_return(0x10, &intf->seqno);
40963+ seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
40964 else
40965- seqno = atomic_read(&intf->seqno);
40966+ seqno = atomic_read_unchecked(&intf->seqno);
40967
40968 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
40969 hdr->seq_ctrl |= cpu_to_le16(seqno);
40970diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
40971index e57ee48..541cf6c 100644
40972--- a/drivers/net/wireless/ti/wl1251/sdio.c
40973+++ b/drivers/net/wireless/ti/wl1251/sdio.c
40974@@ -269,13 +269,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
40975
40976 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
40977
40978- wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40979- wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40980+ pax_open_kernel();
40981+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
40982+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
40983+ pax_close_kernel();
40984
40985 wl1251_info("using dedicated interrupt line");
40986 } else {
40987- wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40988- wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40989+ pax_open_kernel();
40990+ *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
40991+ *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
40992+ pax_close_kernel();
40993
40994 wl1251_info("using SDIO interrupt");
40995 }
40996diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
40997index 09694e3..24ccec7 100644
40998--- a/drivers/net/wireless/ti/wl12xx/main.c
40999+++ b/drivers/net/wireless/ti/wl12xx/main.c
41000@@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41001 sizeof(wl->conf.mem));
41002
41003 /* read data preparation is only needed by wl127x */
41004- wl->ops->prepare_read = wl127x_prepare_read;
41005+ pax_open_kernel();
41006+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41007+ pax_close_kernel();
41008
41009 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41010 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41011@@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
41012 sizeof(wl->conf.mem));
41013
41014 /* read data preparation is only needed by wl127x */
41015- wl->ops->prepare_read = wl127x_prepare_read;
41016+ pax_open_kernel();
41017+ *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
41018+ pax_close_kernel();
41019
41020 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
41021 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
41022diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
41023index da3ef1b..4790b95 100644
41024--- a/drivers/net/wireless/ti/wl18xx/main.c
41025+++ b/drivers/net/wireless/ti/wl18xx/main.c
41026@@ -1664,8 +1664,10 @@ static int wl18xx_setup(struct wl1271 *wl)
41027 }
41028
41029 if (!checksum_param) {
41030- wl18xx_ops.set_rx_csum = NULL;
41031- wl18xx_ops.init_vif = NULL;
41032+ pax_open_kernel();
41033+ *(void **)&wl18xx_ops.set_rx_csum = NULL;
41034+ *(void **)&wl18xx_ops.init_vif = NULL;
41035+ pax_close_kernel();
41036 }
41037
41038 /* Enable 11a Band only if we have 5G antennas */
41039diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
41040index 7ef0b4a..ff65c28 100644
41041--- a/drivers/net/wireless/zd1211rw/zd_usb.c
41042+++ b/drivers/net/wireless/zd1211rw/zd_usb.c
41043@@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
41044 {
41045 struct zd_usb *usb = urb->context;
41046 struct zd_usb_interrupt *intr = &usb->intr;
41047- int len;
41048+ unsigned int len;
41049 u16 int_num;
41050
41051 ZD_ASSERT(in_interrupt());
41052diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
41053index d93b2b6..ae50401 100644
41054--- a/drivers/oprofile/buffer_sync.c
41055+++ b/drivers/oprofile/buffer_sync.c
41056@@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
41057 if (cookie == NO_COOKIE)
41058 offset = pc;
41059 if (cookie == INVALID_COOKIE) {
41060- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41061+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41062 offset = pc;
41063 }
41064 if (cookie != last_cookie) {
41065@@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
41066 /* add userspace sample */
41067
41068 if (!mm) {
41069- atomic_inc(&oprofile_stats.sample_lost_no_mm);
41070+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
41071 return 0;
41072 }
41073
41074 cookie = lookup_dcookie(mm, s->eip, &offset);
41075
41076 if (cookie == INVALID_COOKIE) {
41077- atomic_inc(&oprofile_stats.sample_lost_no_mapping);
41078+ atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
41079 return 0;
41080 }
41081
41082@@ -552,7 +552,7 @@ void sync_buffer(int cpu)
41083 /* ignore backtraces if failed to add a sample */
41084 if (state == sb_bt_start) {
41085 state = sb_bt_ignore;
41086- atomic_inc(&oprofile_stats.bt_lost_no_mapping);
41087+ atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
41088 }
41089 }
41090 release_mm(mm);
41091diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
41092index c0cc4e7..44d4e54 100644
41093--- a/drivers/oprofile/event_buffer.c
41094+++ b/drivers/oprofile/event_buffer.c
41095@@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
41096 }
41097
41098 if (buffer_pos == buffer_size) {
41099- atomic_inc(&oprofile_stats.event_lost_overflow);
41100+ atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
41101 return;
41102 }
41103
41104diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
41105index ed2c3ec..deda85a 100644
41106--- a/drivers/oprofile/oprof.c
41107+++ b/drivers/oprofile/oprof.c
41108@@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
41109 if (oprofile_ops.switch_events())
41110 return;
41111
41112- atomic_inc(&oprofile_stats.multiplex_counter);
41113+ atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
41114 start_switch_worker();
41115 }
41116
41117diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
41118index 84a208d..d61b0a1 100644
41119--- a/drivers/oprofile/oprofile_files.c
41120+++ b/drivers/oprofile/oprofile_files.c
41121@@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
41122
41123 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
41124
41125-static ssize_t timeout_read(struct file *file, char __user *buf,
41126+static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
41127 size_t count, loff_t *offset)
41128 {
41129 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
41130diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
41131index 917d28e..d62d981 100644
41132--- a/drivers/oprofile/oprofile_stats.c
41133+++ b/drivers/oprofile/oprofile_stats.c
41134@@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
41135 cpu_buf->sample_invalid_eip = 0;
41136 }
41137
41138- atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
41139- atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
41140- atomic_set(&oprofile_stats.event_lost_overflow, 0);
41141- atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
41142- atomic_set(&oprofile_stats.multiplex_counter, 0);
41143+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
41144+ atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
41145+ atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
41146+ atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
41147+ atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
41148 }
41149
41150
41151diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
41152index 38b6fc0..b5cbfce 100644
41153--- a/drivers/oprofile/oprofile_stats.h
41154+++ b/drivers/oprofile/oprofile_stats.h
41155@@ -13,11 +13,11 @@
41156 #include <linux/atomic.h>
41157
41158 struct oprofile_stat_struct {
41159- atomic_t sample_lost_no_mm;
41160- atomic_t sample_lost_no_mapping;
41161- atomic_t bt_lost_no_mapping;
41162- atomic_t event_lost_overflow;
41163- atomic_t multiplex_counter;
41164+ atomic_unchecked_t sample_lost_no_mm;
41165+ atomic_unchecked_t sample_lost_no_mapping;
41166+ atomic_unchecked_t bt_lost_no_mapping;
41167+ atomic_unchecked_t event_lost_overflow;
41168+ atomic_unchecked_t multiplex_counter;
41169 };
41170
41171 extern struct oprofile_stat_struct oprofile_stats;
41172diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
41173index 7c12d9c..558bf3bb 100644
41174--- a/drivers/oprofile/oprofilefs.c
41175+++ b/drivers/oprofile/oprofilefs.c
41176@@ -190,7 +190,7 @@ static const struct file_operations atomic_ro_fops = {
41177
41178
41179 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
41180- char const *name, atomic_t *val)
41181+ char const *name, atomic_unchecked_t *val)
41182 {
41183 return __oprofilefs_create_file(sb, root, name,
41184 &atomic_ro_fops, 0444, val);
41185diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
41186index 93404f7..4a313d8 100644
41187--- a/drivers/oprofile/timer_int.c
41188+++ b/drivers/oprofile/timer_int.c
41189@@ -93,7 +93,7 @@ static int __cpuinit oprofile_cpu_notify(struct notifier_block *self,
41190 return NOTIFY_OK;
41191 }
41192
41193-static struct notifier_block __refdata oprofile_cpu_notifier = {
41194+static struct notifier_block oprofile_cpu_notifier = {
41195 .notifier_call = oprofile_cpu_notify,
41196 };
41197
41198diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
41199index 3f56bc0..707d642 100644
41200--- a/drivers/parport/procfs.c
41201+++ b/drivers/parport/procfs.c
41202@@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
41203
41204 *ppos += len;
41205
41206- return copy_to_user(result, buffer, len) ? -EFAULT : 0;
41207+ return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
41208 }
41209
41210 #ifdef CONFIG_PARPORT_1284
41211@@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
41212
41213 *ppos += len;
41214
41215- return copy_to_user (result, buffer, len) ? -EFAULT : 0;
41216+ return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
41217 }
41218 #endif /* IEEE1284.3 support. */
41219
41220diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
41221index c35e8ad..fc33beb 100644
41222--- a/drivers/pci/hotplug/acpiphp_ibm.c
41223+++ b/drivers/pci/hotplug/acpiphp_ibm.c
41224@@ -464,7 +464,9 @@ static int __init ibm_acpiphp_init(void)
41225 goto init_cleanup;
41226 }
41227
41228- ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41229+ pax_open_kernel();
41230+ *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
41231+ pax_close_kernel();
41232 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
41233
41234 return retval;
41235diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
41236index a6a71c4..c91097b 100644
41237--- a/drivers/pci/hotplug/cpcihp_generic.c
41238+++ b/drivers/pci/hotplug/cpcihp_generic.c
41239@@ -73,7 +73,6 @@ static u16 port;
41240 static unsigned int enum_bit;
41241 static u8 enum_mask;
41242
41243-static struct cpci_hp_controller_ops generic_hpc_ops;
41244 static struct cpci_hp_controller generic_hpc;
41245
41246 static int __init validate_parameters(void)
41247@@ -139,6 +138,10 @@ static int query_enum(void)
41248 return ((value & enum_mask) == enum_mask);
41249 }
41250
41251+static struct cpci_hp_controller_ops generic_hpc_ops = {
41252+ .query_enum = query_enum,
41253+};
41254+
41255 static int __init cpcihp_generic_init(void)
41256 {
41257 int status;
41258@@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
41259 pci_dev_put(dev);
41260
41261 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
41262- generic_hpc_ops.query_enum = query_enum;
41263 generic_hpc.ops = &generic_hpc_ops;
41264
41265 status = cpci_hp_register_controller(&generic_hpc);
41266diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
41267index 449b4bb..257e2e8 100644
41268--- a/drivers/pci/hotplug/cpcihp_zt5550.c
41269+++ b/drivers/pci/hotplug/cpcihp_zt5550.c
41270@@ -59,7 +59,6 @@
41271 /* local variables */
41272 static bool debug;
41273 static bool poll;
41274-static struct cpci_hp_controller_ops zt5550_hpc_ops;
41275 static struct cpci_hp_controller zt5550_hpc;
41276
41277 /* Primary cPCI bus bridge device */
41278@@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
41279 return 0;
41280 }
41281
41282+static struct cpci_hp_controller_ops zt5550_hpc_ops = {
41283+ .query_enum = zt5550_hc_query_enum,
41284+};
41285+
41286 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
41287 {
41288 int status;
41289@@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
41290 dbg("returned from zt5550_hc_config");
41291
41292 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
41293- zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
41294 zt5550_hpc.ops = &zt5550_hpc_ops;
41295 if(!poll) {
41296 zt5550_hpc.irq = hc_dev->irq;
41297 zt5550_hpc.irq_flags = IRQF_SHARED;
41298 zt5550_hpc.dev_id = hc_dev;
41299
41300- zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41301- zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41302- zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41303+ pax_open_kernel();
41304+ *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
41305+ *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
41306+ *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
41307+ pax_open_kernel();
41308 } else {
41309 info("using ENUM# polling mode");
41310 }
41311diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
41312index 76ba8a1..20ca857 100644
41313--- a/drivers/pci/hotplug/cpqphp_nvram.c
41314+++ b/drivers/pci/hotplug/cpqphp_nvram.c
41315@@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
41316
41317 void compaq_nvram_init (void __iomem *rom_start)
41318 {
41319+
41320+#ifndef CONFIG_PAX_KERNEXEC
41321 if (rom_start) {
41322 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
41323 }
41324+#endif
41325+
41326 dbg("int15 entry = %p\n", compaq_int15_entry_point);
41327
41328 /* initialize our int15 lock */
41329diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
41330index 202f4a9..8ee47d0 100644
41331--- a/drivers/pci/hotplug/pci_hotplug_core.c
41332+++ b/drivers/pci/hotplug/pci_hotplug_core.c
41333@@ -448,8 +448,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
41334 return -EINVAL;
41335 }
41336
41337- slot->ops->owner = owner;
41338- slot->ops->mod_name = mod_name;
41339+ pax_open_kernel();
41340+ *(struct module **)&slot->ops->owner = owner;
41341+ *(const char **)&slot->ops->mod_name = mod_name;
41342+ pax_close_kernel();
41343
41344 mutex_lock(&pci_hp_mutex);
41345 /*
41346diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
41347index 7d72c5e..edce02c 100644
41348--- a/drivers/pci/hotplug/pciehp_core.c
41349+++ b/drivers/pci/hotplug/pciehp_core.c
41350@@ -91,7 +91,7 @@ static int init_slot(struct controller *ctrl)
41351 struct slot *slot = ctrl->slot;
41352 struct hotplug_slot *hotplug = NULL;
41353 struct hotplug_slot_info *info = NULL;
41354- struct hotplug_slot_ops *ops = NULL;
41355+ hotplug_slot_ops_no_const *ops = NULL;
41356 char name[SLOT_NAME_SIZE];
41357 int retval = -ENOMEM;
41358
41359diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
41360index 9c6e9bb..2916736 100644
41361--- a/drivers/pci/pci-sysfs.c
41362+++ b/drivers/pci/pci-sysfs.c
41363@@ -1071,7 +1071,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
41364 {
41365 /* allocate attribute structure, piggyback attribute name */
41366 int name_len = write_combine ? 13 : 10;
41367- struct bin_attribute *res_attr;
41368+ bin_attribute_no_const *res_attr;
41369 int retval;
41370
41371 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
41372@@ -1256,7 +1256,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
41373 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
41374 {
41375 int retval;
41376- struct bin_attribute *attr;
41377+ bin_attribute_no_const *attr;
41378
41379 /* If the device has VPD, try to expose it in sysfs. */
41380 if (dev->vpd) {
41381@@ -1303,7 +1303,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
41382 {
41383 int retval;
41384 int rom_size = 0;
41385- struct bin_attribute *attr;
41386+ bin_attribute_no_const *attr;
41387
41388 if (!sysfs_initialized)
41389 return -EACCES;
41390diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
41391index 7346ee6..41520eb 100644
41392--- a/drivers/pci/pci.h
41393+++ b/drivers/pci/pci.h
41394@@ -93,7 +93,7 @@ struct pci_vpd_ops {
41395 struct pci_vpd {
41396 unsigned int len;
41397 const struct pci_vpd_ops *ops;
41398- struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
41399+ bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
41400 };
41401
41402 extern int pci_vpd_pci22_init(struct pci_dev *dev);
41403diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
41404index d320df6..ca9a8f6 100644
41405--- a/drivers/pci/pcie/aspm.c
41406+++ b/drivers/pci/pcie/aspm.c
41407@@ -27,9 +27,9 @@
41408 #define MODULE_PARAM_PREFIX "pcie_aspm."
41409
41410 /* Note: those are not register definitions */
41411-#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
41412-#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
41413-#define ASPM_STATE_L1 (4) /* L1 state */
41414+#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
41415+#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
41416+#define ASPM_STATE_L1 (4U) /* L1 state */
41417 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
41418 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
41419
41420diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
41421index 563771f..4e3c368 100644
41422--- a/drivers/pci/probe.c
41423+++ b/drivers/pci/probe.c
41424@@ -173,7 +173,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
41425 struct pci_bus_region region;
41426 bool bar_too_big = false, bar_disabled = false;
41427
41428- mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
41429+ mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
41430
41431 /* No printks while decoding is disabled! */
41432 if (!dev->mmio_always_on) {
41433diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
41434index 0b00947..64f7c0a 100644
41435--- a/drivers/pci/proc.c
41436+++ b/drivers/pci/proc.c
41437@@ -465,7 +465,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
41438 static int __init pci_proc_init(void)
41439 {
41440 struct pci_dev *dev = NULL;
41441+
41442+#ifdef CONFIG_GRKERNSEC_PROC_ADD
41443+#ifdef CONFIG_GRKERNSEC_PROC_USER
41444+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
41445+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
41446+ proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
41447+#endif
41448+#else
41449 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
41450+#endif
41451 proc_create("devices", 0, proc_bus_pci_dir,
41452 &proc_bus_pci_dev_operations);
41453 proc_initialized = 1;
41454diff --git a/drivers/platform/x86/chromeos_laptop.c b/drivers/platform/x86/chromeos_laptop.c
41455index 3e5b4497..dcdfb70 100644
41456--- a/drivers/platform/x86/chromeos_laptop.c
41457+++ b/drivers/platform/x86/chromeos_laptop.c
41458@@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
41459 return 0;
41460 }
41461
41462-static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
41463+static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
41464 {
41465 .ident = "Samsung Series 5 550 - Touchpad",
41466 .matches = {
41467diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
41468index 6b22938..bc9700e 100644
41469--- a/drivers/platform/x86/msi-laptop.c
41470+++ b/drivers/platform/x86/msi-laptop.c
41471@@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
41472
41473 if (!quirks->ec_read_only) {
41474 /* allow userland write sysfs file */
41475- dev_attr_bluetooth.store = store_bluetooth;
41476- dev_attr_wlan.store = store_wlan;
41477- dev_attr_threeg.store = store_threeg;
41478- dev_attr_bluetooth.attr.mode |= S_IWUSR;
41479- dev_attr_wlan.attr.mode |= S_IWUSR;
41480- dev_attr_threeg.attr.mode |= S_IWUSR;
41481+ pax_open_kernel();
41482+ *(void **)&dev_attr_bluetooth.store = store_bluetooth;
41483+ *(void **)&dev_attr_wlan.store = store_wlan;
41484+ *(void **)&dev_attr_threeg.store = store_threeg;
41485+ *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
41486+ *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
41487+ *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
41488+ pax_close_kernel();
41489 }
41490
41491 /* disable hardware control by fn key */
41492diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
41493index 14d4dce..b129917 100644
41494--- a/drivers/platform/x86/sony-laptop.c
41495+++ b/drivers/platform/x86/sony-laptop.c
41496@@ -2465,7 +2465,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
41497 }
41498
41499 /* High speed charging function */
41500-static struct device_attribute *hsc_handle;
41501+static device_attribute_no_const *hsc_handle;
41502
41503 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
41504 struct device_attribute *attr,
41505diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
41506index edec135..59a24a3 100644
41507--- a/drivers/platform/x86/thinkpad_acpi.c
41508+++ b/drivers/platform/x86/thinkpad_acpi.c
41509@@ -2093,7 +2093,7 @@ static int hotkey_mask_get(void)
41510 return 0;
41511 }
41512
41513-void static hotkey_mask_warn_incomplete_mask(void)
41514+static void hotkey_mask_warn_incomplete_mask(void)
41515 {
41516 /* log only what the user can fix... */
41517 const u32 wantedmask = hotkey_driver_mask &
41518@@ -2324,11 +2324,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
41519 }
41520 }
41521
41522-static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41523- struct tp_nvram_state *newn,
41524- const u32 event_mask)
41525-{
41526-
41527 #define TPACPI_COMPARE_KEY(__scancode, __member) \
41528 do { \
41529 if ((event_mask & (1 << __scancode)) && \
41530@@ -2342,36 +2337,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41531 tpacpi_hotkey_send_key(__scancode); \
41532 } while (0)
41533
41534- void issue_volchange(const unsigned int oldvol,
41535- const unsigned int newvol)
41536- {
41537- unsigned int i = oldvol;
41538+static void issue_volchange(const unsigned int oldvol,
41539+ const unsigned int newvol,
41540+ const u32 event_mask)
41541+{
41542+ unsigned int i = oldvol;
41543
41544- while (i > newvol) {
41545- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41546- i--;
41547- }
41548- while (i < newvol) {
41549- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41550- i++;
41551- }
41552+ while (i > newvol) {
41553+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
41554+ i--;
41555 }
41556+ while (i < newvol) {
41557+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41558+ i++;
41559+ }
41560+}
41561
41562- void issue_brightnesschange(const unsigned int oldbrt,
41563- const unsigned int newbrt)
41564- {
41565- unsigned int i = oldbrt;
41566+static void issue_brightnesschange(const unsigned int oldbrt,
41567+ const unsigned int newbrt,
41568+ const u32 event_mask)
41569+{
41570+ unsigned int i = oldbrt;
41571
41572- while (i > newbrt) {
41573- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41574- i--;
41575- }
41576- while (i < newbrt) {
41577- TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41578- i++;
41579- }
41580+ while (i > newbrt) {
41581+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
41582+ i--;
41583+ }
41584+ while (i < newbrt) {
41585+ TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41586+ i++;
41587 }
41588+}
41589
41590+static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41591+ struct tp_nvram_state *newn,
41592+ const u32 event_mask)
41593+{
41594 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
41595 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
41596 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
41597@@ -2405,7 +2406,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41598 oldn->volume_level != newn->volume_level) {
41599 /* recently muted, or repeated mute keypress, or
41600 * multiple presses ending in mute */
41601- issue_volchange(oldn->volume_level, newn->volume_level);
41602+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41603 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
41604 }
41605 } else {
41606@@ -2415,7 +2416,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41607 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
41608 }
41609 if (oldn->volume_level != newn->volume_level) {
41610- issue_volchange(oldn->volume_level, newn->volume_level);
41611+ issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
41612 } else if (oldn->volume_toggle != newn->volume_toggle) {
41613 /* repeated vol up/down keypress at end of scale ? */
41614 if (newn->volume_level == 0)
41615@@ -2428,7 +2429,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41616 /* handle brightness */
41617 if (oldn->brightness_level != newn->brightness_level) {
41618 issue_brightnesschange(oldn->brightness_level,
41619- newn->brightness_level);
41620+ newn->brightness_level,
41621+ event_mask);
41622 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
41623 /* repeated key presses that didn't change state */
41624 if (newn->brightness_level == 0)
41625@@ -2437,10 +2439,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
41626 && !tp_features.bright_unkfw)
41627 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
41628 }
41629+}
41630
41631 #undef TPACPI_COMPARE_KEY
41632 #undef TPACPI_MAY_SEND_KEY
41633-}
41634
41635 /*
41636 * Polling driver
41637diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
41638index 769d265..a3a05ca 100644
41639--- a/drivers/pnp/pnpbios/bioscalls.c
41640+++ b/drivers/pnp/pnpbios/bioscalls.c
41641@@ -58,7 +58,7 @@ do { \
41642 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
41643 } while(0)
41644
41645-static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
41646+static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
41647 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
41648
41649 /*
41650@@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41651
41652 cpu = get_cpu();
41653 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
41654+
41655+ pax_open_kernel();
41656 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
41657+ pax_close_kernel();
41658
41659 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
41660 spin_lock_irqsave(&pnp_bios_lock, flags);
41661@@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
41662 :"memory");
41663 spin_unlock_irqrestore(&pnp_bios_lock, flags);
41664
41665+ pax_open_kernel();
41666 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
41667+ pax_close_kernel();
41668+
41669 put_cpu();
41670
41671 /* If we get here and this is set then the PnP BIOS faulted on us. */
41672@@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
41673 return status;
41674 }
41675
41676-void pnpbios_calls_init(union pnp_bios_install_struct *header)
41677+void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
41678 {
41679 int i;
41680
41681@@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41682 pnp_bios_callpoint.offset = header->fields.pm16offset;
41683 pnp_bios_callpoint.segment = PNP_CS16;
41684
41685+ pax_open_kernel();
41686+
41687 for_each_possible_cpu(i) {
41688 struct desc_struct *gdt = get_cpu_gdt_table(i);
41689 if (!gdt)
41690@@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
41691 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
41692 (unsigned long)__va(header->fields.pm16dseg));
41693 }
41694+
41695+ pax_close_kernel();
41696 }
41697diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
41698index 3e6db1c..1fbbdae 100644
41699--- a/drivers/pnp/resource.c
41700+++ b/drivers/pnp/resource.c
41701@@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
41702 return 1;
41703
41704 /* check if the resource is valid */
41705- if (*irq < 0 || *irq > 15)
41706+ if (*irq > 15)
41707 return 0;
41708
41709 /* check if the resource is reserved */
41710@@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
41711 return 1;
41712
41713 /* check if the resource is valid */
41714- if (*dma < 0 || *dma == 4 || *dma > 7)
41715+ if (*dma == 4 || *dma > 7)
41716 return 0;
41717
41718 /* check if the resource is reserved */
41719diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
41720index 7df7c5f..bd48c47 100644
41721--- a/drivers/power/pda_power.c
41722+++ b/drivers/power/pda_power.c
41723@@ -37,7 +37,11 @@ static int polling;
41724
41725 #ifdef CONFIG_USB_OTG_UTILS
41726 static struct usb_phy *transceiver;
41727-static struct notifier_block otg_nb;
41728+static int otg_handle_notification(struct notifier_block *nb,
41729+ unsigned long event, void *unused);
41730+static struct notifier_block otg_nb = {
41731+ .notifier_call = otg_handle_notification
41732+};
41733 #endif
41734
41735 static struct regulator *ac_draw;
41736@@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
41737
41738 #ifdef CONFIG_USB_OTG_UTILS
41739 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
41740- otg_nb.notifier_call = otg_handle_notification;
41741 ret = usb_register_notifier(transceiver, &otg_nb);
41742 if (ret) {
41743 dev_err(dev, "failure to register otg notifier\n");
41744diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
41745index cc439fd..8fa30df 100644
41746--- a/drivers/power/power_supply.h
41747+++ b/drivers/power/power_supply.h
41748@@ -16,12 +16,12 @@ struct power_supply;
41749
41750 #ifdef CONFIG_SYSFS
41751
41752-extern void power_supply_init_attrs(struct device_type *dev_type);
41753+extern void power_supply_init_attrs(void);
41754 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
41755
41756 #else
41757
41758-static inline void power_supply_init_attrs(struct device_type *dev_type) {}
41759+static inline void power_supply_init_attrs(void) {}
41760 #define power_supply_uevent NULL
41761
41762 #endif /* CONFIG_SYSFS */
41763diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
41764index 5deac43..608c5ff 100644
41765--- a/drivers/power/power_supply_core.c
41766+++ b/drivers/power/power_supply_core.c
41767@@ -24,7 +24,10 @@
41768 struct class *power_supply_class;
41769 EXPORT_SYMBOL_GPL(power_supply_class);
41770
41771-static struct device_type power_supply_dev_type;
41772+extern const struct attribute_group *power_supply_attr_groups[];
41773+static struct device_type power_supply_dev_type = {
41774+ .groups = power_supply_attr_groups,
41775+};
41776
41777 static int __power_supply_changed_work(struct device *dev, void *data)
41778 {
41779@@ -393,7 +396,7 @@ static int __init power_supply_class_init(void)
41780 return PTR_ERR(power_supply_class);
41781
41782 power_supply_class->dev_uevent = power_supply_uevent;
41783- power_supply_init_attrs(&power_supply_dev_type);
41784+ power_supply_init_attrs();
41785
41786 return 0;
41787 }
41788diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
41789index 29178f7..c65f324 100644
41790--- a/drivers/power/power_supply_sysfs.c
41791+++ b/drivers/power/power_supply_sysfs.c
41792@@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
41793 .is_visible = power_supply_attr_is_visible,
41794 };
41795
41796-static const struct attribute_group *power_supply_attr_groups[] = {
41797+const struct attribute_group *power_supply_attr_groups[] = {
41798 &power_supply_attr_group,
41799 NULL,
41800 };
41801
41802-void power_supply_init_attrs(struct device_type *dev_type)
41803+void power_supply_init_attrs(void)
41804 {
41805 int i;
41806
41807- dev_type->groups = power_supply_attr_groups;
41808-
41809 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
41810 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
41811 }
41812diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
41813index 4d7c635..9860196 100644
41814--- a/drivers/regulator/max8660.c
41815+++ b/drivers/regulator/max8660.c
41816@@ -333,8 +333,10 @@ static int max8660_probe(struct i2c_client *client,
41817 max8660->shadow_regs[MAX8660_OVER1] = 5;
41818 } else {
41819 /* Otherwise devices can be toggled via software */
41820- max8660_dcdc_ops.enable = max8660_dcdc_enable;
41821- max8660_dcdc_ops.disable = max8660_dcdc_disable;
41822+ pax_open_kernel();
41823+ *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
41824+ *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
41825+ pax_close_kernel();
41826 }
41827
41828 /*
41829diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
41830index 9a8ea91..c483dd9 100644
41831--- a/drivers/regulator/max8973-regulator.c
41832+++ b/drivers/regulator/max8973-regulator.c
41833@@ -401,9 +401,11 @@ static int max8973_probe(struct i2c_client *client,
41834 if (!pdata->enable_ext_control) {
41835 max->desc.enable_reg = MAX8973_VOUT;
41836 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
41837- max8973_dcdc_ops.enable = regulator_enable_regmap;
41838- max8973_dcdc_ops.disable = regulator_disable_regmap;
41839- max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41840+ pax_open_kernel();
41841+ *(void **)&max8973_dcdc_ops.enable = regulator_enable_regmap;
41842+ *(void **)&max8973_dcdc_ops.disable = regulator_disable_regmap;
41843+ *(void **)&max8973_dcdc_ops.is_enabled = regulator_is_enabled_regmap;
41844+ pax_close_kernel();
41845 }
41846
41847 max->enable_external_control = pdata->enable_ext_control;
41848diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
41849index 9891aec..beb3083 100644
41850--- a/drivers/regulator/mc13892-regulator.c
41851+++ b/drivers/regulator/mc13892-regulator.c
41852@@ -583,10 +583,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
41853 }
41854 mc13xxx_unlock(mc13892);
41855
41856- mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41857+ pax_open_kernel();
41858+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
41859 = mc13892_vcam_set_mode;
41860- mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41861+ *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
41862 = mc13892_vcam_get_mode;
41863+ pax_close_kernel();
41864
41865 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
41866 ARRAY_SIZE(mc13892_regulators),
41867diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
41868index cc5bea9..689f7d9 100644
41869--- a/drivers/rtc/rtc-cmos.c
41870+++ b/drivers/rtc/rtc-cmos.c
41871@@ -724,7 +724,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
41872 hpet_rtc_timer_init();
41873
41874 /* export at least the first block of NVRAM */
41875- nvram.size = address_space - NVRAM_OFFSET;
41876+ pax_open_kernel();
41877+ *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
41878+ pax_close_kernel();
41879 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
41880 if (retval < 0) {
41881 dev_dbg(dev, "can't create nvram file? %d\n", retval);
41882diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
41883index d049393..bb20be0 100644
41884--- a/drivers/rtc/rtc-dev.c
41885+++ b/drivers/rtc/rtc-dev.c
41886@@ -16,6 +16,7 @@
41887 #include <linux/module.h>
41888 #include <linux/rtc.h>
41889 #include <linux/sched.h>
41890+#include <linux/grsecurity.h>
41891 #include "rtc-core.h"
41892
41893 static dev_t rtc_devt;
41894@@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
41895 if (copy_from_user(&tm, uarg, sizeof(tm)))
41896 return -EFAULT;
41897
41898+ gr_log_timechange();
41899+
41900 return rtc_set_time(rtc, &tm);
41901
41902 case RTC_PIE_ON:
41903diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
41904index 970a236..3613169 100644
41905--- a/drivers/rtc/rtc-ds1307.c
41906+++ b/drivers/rtc/rtc-ds1307.c
41907@@ -106,7 +106,7 @@ struct ds1307 {
41908 u8 offset; /* register's offset */
41909 u8 regs[11];
41910 u16 nvram_offset;
41911- struct bin_attribute *nvram;
41912+ bin_attribute_no_const *nvram;
41913 enum ds_type type;
41914 unsigned long flags;
41915 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
41916diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
41917index 130f29a..6179d03 100644
41918--- a/drivers/rtc/rtc-m48t59.c
41919+++ b/drivers/rtc/rtc-m48t59.c
41920@@ -482,7 +482,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
41921 goto out;
41922 }
41923
41924- m48t59_nvram_attr.size = pdata->offset;
41925+ pax_open_kernel();
41926+ *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
41927+ pax_close_kernel();
41928
41929 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
41930 if (ret) {
41931diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
41932index e693af6..2e525b6 100644
41933--- a/drivers/scsi/bfa/bfa_fcpim.h
41934+++ b/drivers/scsi/bfa/bfa_fcpim.h
41935@@ -36,7 +36,7 @@ struct bfa_iotag_s {
41936
41937 struct bfa_itn_s {
41938 bfa_isr_func_t isr;
41939-};
41940+} __no_const;
41941
41942 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
41943 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
41944diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
41945index 23a90e7..9cf04ee 100644
41946--- a/drivers/scsi/bfa/bfa_ioc.h
41947+++ b/drivers/scsi/bfa/bfa_ioc.h
41948@@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
41949 bfa_ioc_disable_cbfn_t disable_cbfn;
41950 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
41951 bfa_ioc_reset_cbfn_t reset_cbfn;
41952-};
41953+} __no_const;
41954
41955 /*
41956 * IOC event notification mechanism.
41957@@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
41958 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
41959 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
41960 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
41961-};
41962+} __no_const;
41963
41964 /*
41965 * Queue element to wait for room in request queue. FIFO order is
41966diff --git a/drivers/scsi/bfa/bfad_debugfs.c b/drivers/scsi/bfa/bfad_debugfs.c
41967index 439c012..b63d534 100644
41968--- a/drivers/scsi/bfa/bfad_debugfs.c
41969+++ b/drivers/scsi/bfa/bfad_debugfs.c
41970@@ -186,7 +186,7 @@ bfad_debugfs_lseek(struct file *file, loff_t offset, int orig)
41971 file->f_pos += offset;
41972 break;
41973 case 2:
41974- file->f_pos = debug->buffer_len - offset;
41975+ file->f_pos = debug->buffer_len + offset;
41976 break;
41977 default:
41978 return -EINVAL;
41979diff --git a/drivers/scsi/fnic/fnic_debugfs.c b/drivers/scsi/fnic/fnic_debugfs.c
41980index adc1f7f..85e1ffd 100644
41981--- a/drivers/scsi/fnic/fnic_debugfs.c
41982+++ b/drivers/scsi/fnic/fnic_debugfs.c
41983@@ -174,7 +174,7 @@ static loff_t fnic_trace_debugfs_lseek(struct file *file,
41984 pos = file->f_pos + offset;
41985 break;
41986 case 2:
41987- pos = fnic_dbg_prt->buffer_len - offset;
41988+ pos = fnic_dbg_prt->buffer_len + offset;
41989 }
41990 return (pos < 0 || pos > fnic_dbg_prt->buffer_len) ?
41991 -EINVAL : (file->f_pos = pos);
41992diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
41993index df0c3c7..b00e1d0 100644
41994--- a/drivers/scsi/hosts.c
41995+++ b/drivers/scsi/hosts.c
41996@@ -42,7 +42,7 @@
41997 #include "scsi_logging.h"
41998
41999
42000-static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42001+static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
42002
42003
42004 static void scsi_host_cls_release(struct device *dev)
42005@@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
42006 * subtract one because we increment first then return, but we need to
42007 * know what the next host number was before increment
42008 */
42009- shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
42010+ shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
42011 shost->dma_channel = 0xff;
42012
42013 /* These three are default values which can be overridden */
42014diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
42015index 7f4f790..b75b92a 100644
42016--- a/drivers/scsi/hpsa.c
42017+++ b/drivers/scsi/hpsa.c
42018@@ -554,7 +554,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
42019 unsigned long flags;
42020
42021 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
42022- return h->access.command_completed(h, q);
42023+ return h->access->command_completed(h, q);
42024
42025 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
42026 a = rq->head[rq->current_entry];
42027@@ -3422,7 +3422,7 @@ static void start_io(struct ctlr_info *h)
42028 while (!list_empty(&h->reqQ)) {
42029 c = list_entry(h->reqQ.next, struct CommandList, list);
42030 /* can't do anything if fifo is full */
42031- if ((h->access.fifo_full(h))) {
42032+ if ((h->access->fifo_full(h))) {
42033 dev_warn(&h->pdev->dev, "fifo full\n");
42034 break;
42035 }
42036@@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
42037
42038 /* Tell the controller execute command */
42039 spin_unlock_irqrestore(&h->lock, flags);
42040- h->access.submit_command(h, c);
42041+ h->access->submit_command(h, c);
42042 spin_lock_irqsave(&h->lock, flags);
42043 }
42044 spin_unlock_irqrestore(&h->lock, flags);
42045@@ -3452,17 +3452,17 @@ static void start_io(struct ctlr_info *h)
42046
42047 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
42048 {
42049- return h->access.command_completed(h, q);
42050+ return h->access->command_completed(h, q);
42051 }
42052
42053 static inline bool interrupt_pending(struct ctlr_info *h)
42054 {
42055- return h->access.intr_pending(h);
42056+ return h->access->intr_pending(h);
42057 }
42058
42059 static inline long interrupt_not_for_us(struct ctlr_info *h)
42060 {
42061- return (h->access.intr_pending(h) == 0) ||
42062+ return (h->access->intr_pending(h) == 0) ||
42063 (h->interrupts_enabled == 0);
42064 }
42065
42066@@ -4364,7 +4364,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
42067 if (prod_index < 0)
42068 return -ENODEV;
42069 h->product_name = products[prod_index].product_name;
42070- h->access = *(products[prod_index].access);
42071+ h->access = products[prod_index].access;
42072
42073 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
42074 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
42075@@ -4646,7 +4646,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
42076
42077 assert_spin_locked(&lockup_detector_lock);
42078 remove_ctlr_from_lockup_detector_list(h);
42079- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42080+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42081 spin_lock_irqsave(&h->lock, flags);
42082 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
42083 spin_unlock_irqrestore(&h->lock, flags);
42084@@ -4823,7 +4823,7 @@ reinit_after_soft_reset:
42085 }
42086
42087 /* make sure the board interrupts are off */
42088- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42089+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42090
42091 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
42092 goto clean2;
42093@@ -4857,7 +4857,7 @@ reinit_after_soft_reset:
42094 * fake ones to scoop up any residual completions.
42095 */
42096 spin_lock_irqsave(&h->lock, flags);
42097- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42098+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42099 spin_unlock_irqrestore(&h->lock, flags);
42100 free_irqs(h);
42101 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
42102@@ -4876,9 +4876,9 @@ reinit_after_soft_reset:
42103 dev_info(&h->pdev->dev, "Board READY.\n");
42104 dev_info(&h->pdev->dev,
42105 "Waiting for stale completions to drain.\n");
42106- h->access.set_intr_mask(h, HPSA_INTR_ON);
42107+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42108 msleep(10000);
42109- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42110+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42111
42112 rc = controller_reset_failed(h->cfgtable);
42113 if (rc)
42114@@ -4899,7 +4899,7 @@ reinit_after_soft_reset:
42115 }
42116
42117 /* Turn the interrupts on so we can service requests */
42118- h->access.set_intr_mask(h, HPSA_INTR_ON);
42119+ h->access->set_intr_mask(h, HPSA_INTR_ON);
42120
42121 hpsa_hba_inquiry(h);
42122 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
42123@@ -4954,7 +4954,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
42124 * To write all data in the battery backed cache to disks
42125 */
42126 hpsa_flush_cache(h);
42127- h->access.set_intr_mask(h, HPSA_INTR_OFF);
42128+ h->access->set_intr_mask(h, HPSA_INTR_OFF);
42129 hpsa_free_irqs_and_disable_msix(h);
42130 }
42131
42132@@ -5122,7 +5122,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
42133 return;
42134 }
42135 /* Change the access methods to the performant access methods */
42136- h->access = SA5_performant_access;
42137+ h->access = &SA5_performant_access;
42138 h->transMethod = CFGTBL_Trans_Performant;
42139 }
42140
42141diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
42142index 9816479..c5d4e97 100644
42143--- a/drivers/scsi/hpsa.h
42144+++ b/drivers/scsi/hpsa.h
42145@@ -79,7 +79,7 @@ struct ctlr_info {
42146 unsigned int msix_vector;
42147 unsigned int msi_vector;
42148 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
42149- struct access_method access;
42150+ struct access_method *access;
42151
42152 /* queue and queue Info */
42153 struct list_head reqQ;
42154diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
42155index c772d8d..35c362c 100644
42156--- a/drivers/scsi/libfc/fc_exch.c
42157+++ b/drivers/scsi/libfc/fc_exch.c
42158@@ -100,12 +100,12 @@ struct fc_exch_mgr {
42159 u16 pool_max_index;
42160
42161 struct {
42162- atomic_t no_free_exch;
42163- atomic_t no_free_exch_xid;
42164- atomic_t xid_not_found;
42165- atomic_t xid_busy;
42166- atomic_t seq_not_found;
42167- atomic_t non_bls_resp;
42168+ atomic_unchecked_t no_free_exch;
42169+ atomic_unchecked_t no_free_exch_xid;
42170+ atomic_unchecked_t xid_not_found;
42171+ atomic_unchecked_t xid_busy;
42172+ atomic_unchecked_t seq_not_found;
42173+ atomic_unchecked_t non_bls_resp;
42174 } stats;
42175 };
42176
42177@@ -725,7 +725,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
42178 /* allocate memory for exchange */
42179 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
42180 if (!ep) {
42181- atomic_inc(&mp->stats.no_free_exch);
42182+ atomic_inc_unchecked(&mp->stats.no_free_exch);
42183 goto out;
42184 }
42185 memset(ep, 0, sizeof(*ep));
42186@@ -786,7 +786,7 @@ out:
42187 return ep;
42188 err:
42189 spin_unlock_bh(&pool->lock);
42190- atomic_inc(&mp->stats.no_free_exch_xid);
42191+ atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
42192 mempool_free(ep, mp->ep_pool);
42193 return NULL;
42194 }
42195@@ -929,7 +929,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42196 xid = ntohs(fh->fh_ox_id); /* we originated exch */
42197 ep = fc_exch_find(mp, xid);
42198 if (!ep) {
42199- atomic_inc(&mp->stats.xid_not_found);
42200+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42201 reject = FC_RJT_OX_ID;
42202 goto out;
42203 }
42204@@ -959,7 +959,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42205 ep = fc_exch_find(mp, xid);
42206 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
42207 if (ep) {
42208- atomic_inc(&mp->stats.xid_busy);
42209+ atomic_inc_unchecked(&mp->stats.xid_busy);
42210 reject = FC_RJT_RX_ID;
42211 goto rel;
42212 }
42213@@ -970,7 +970,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42214 }
42215 xid = ep->xid; /* get our XID */
42216 } else if (!ep) {
42217- atomic_inc(&mp->stats.xid_not_found);
42218+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42219 reject = FC_RJT_RX_ID; /* XID not found */
42220 goto out;
42221 }
42222@@ -987,7 +987,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
42223 } else {
42224 sp = &ep->seq;
42225 if (sp->id != fh->fh_seq_id) {
42226- atomic_inc(&mp->stats.seq_not_found);
42227+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42228 if (f_ctl & FC_FC_END_SEQ) {
42229 /*
42230 * Update sequence_id based on incoming last
42231@@ -1437,22 +1437,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42232
42233 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
42234 if (!ep) {
42235- atomic_inc(&mp->stats.xid_not_found);
42236+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42237 goto out;
42238 }
42239 if (ep->esb_stat & ESB_ST_COMPLETE) {
42240- atomic_inc(&mp->stats.xid_not_found);
42241+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42242 goto rel;
42243 }
42244 if (ep->rxid == FC_XID_UNKNOWN)
42245 ep->rxid = ntohs(fh->fh_rx_id);
42246 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
42247- atomic_inc(&mp->stats.xid_not_found);
42248+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42249 goto rel;
42250 }
42251 if (ep->did != ntoh24(fh->fh_s_id) &&
42252 ep->did != FC_FID_FLOGI) {
42253- atomic_inc(&mp->stats.xid_not_found);
42254+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42255 goto rel;
42256 }
42257 sof = fr_sof(fp);
42258@@ -1461,7 +1461,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42259 sp->ssb_stat |= SSB_ST_RESP;
42260 sp->id = fh->fh_seq_id;
42261 } else if (sp->id != fh->fh_seq_id) {
42262- atomic_inc(&mp->stats.seq_not_found);
42263+ atomic_inc_unchecked(&mp->stats.seq_not_found);
42264 goto rel;
42265 }
42266
42267@@ -1525,9 +1525,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
42268 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
42269
42270 if (!sp)
42271- atomic_inc(&mp->stats.xid_not_found);
42272+ atomic_inc_unchecked(&mp->stats.xid_not_found);
42273 else
42274- atomic_inc(&mp->stats.non_bls_resp);
42275+ atomic_inc_unchecked(&mp->stats.non_bls_resp);
42276
42277 fc_frame_free(fp);
42278 }
42279@@ -2174,13 +2174,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
42280
42281 list_for_each_entry(ema, &lport->ema_list, ema_list) {
42282 mp = ema->mp;
42283- st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
42284+ st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
42285 st->fc_no_free_exch_xid +=
42286- atomic_read(&mp->stats.no_free_exch_xid);
42287- st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
42288- st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
42289- st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
42290- st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
42291+ atomic_read_unchecked(&mp->stats.no_free_exch_xid);
42292+ st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
42293+ st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
42294+ st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
42295+ st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
42296 }
42297 }
42298 EXPORT_SYMBOL(fc_exch_update_stats);
42299diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
42300index bdb81cd..d3c7c2c 100644
42301--- a/drivers/scsi/libsas/sas_ata.c
42302+++ b/drivers/scsi/libsas/sas_ata.c
42303@@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
42304 .postreset = ata_std_postreset,
42305 .error_handler = ata_std_error_handler,
42306 .post_internal_cmd = sas_ata_post_internal,
42307- .qc_defer = ata_std_qc_defer,
42308+ .qc_defer = ata_std_qc_defer,
42309 .qc_prep = ata_noop_qc_prep,
42310 .qc_issue = sas_ata_qc_issue,
42311 .qc_fill_rtf = sas_ata_qc_fill_rtf,
42312diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
42313index 7706c99..3b4fc0c 100644
42314--- a/drivers/scsi/lpfc/lpfc.h
42315+++ b/drivers/scsi/lpfc/lpfc.h
42316@@ -424,7 +424,7 @@ struct lpfc_vport {
42317 struct dentry *debug_nodelist;
42318 struct dentry *vport_debugfs_root;
42319 struct lpfc_debugfs_trc *disc_trc;
42320- atomic_t disc_trc_cnt;
42321+ atomic_unchecked_t disc_trc_cnt;
42322 #endif
42323 uint8_t stat_data_enabled;
42324 uint8_t stat_data_blocked;
42325@@ -853,8 +853,8 @@ struct lpfc_hba {
42326 struct timer_list fabric_block_timer;
42327 unsigned long bit_flags;
42328 #define FABRIC_COMANDS_BLOCKED 0
42329- atomic_t num_rsrc_err;
42330- atomic_t num_cmd_success;
42331+ atomic_unchecked_t num_rsrc_err;
42332+ atomic_unchecked_t num_cmd_success;
42333 unsigned long last_rsrc_error_time;
42334 unsigned long last_ramp_down_time;
42335 unsigned long last_ramp_up_time;
42336@@ -890,7 +890,7 @@ struct lpfc_hba {
42337
42338 struct dentry *debug_slow_ring_trc;
42339 struct lpfc_debugfs_trc *slow_ring_trc;
42340- atomic_t slow_ring_trc_cnt;
42341+ atomic_unchecked_t slow_ring_trc_cnt;
42342 /* iDiag debugfs sub-directory */
42343 struct dentry *idiag_root;
42344 struct dentry *idiag_pci_cfg;
42345diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
42346index f63f5ff..32549a4 100644
42347--- a/drivers/scsi/lpfc/lpfc_debugfs.c
42348+++ b/drivers/scsi/lpfc/lpfc_debugfs.c
42349@@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
42350
42351 #include <linux/debugfs.h>
42352
42353-static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42354+static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
42355 static unsigned long lpfc_debugfs_start_time = 0L;
42356
42357 /* iDiag */
42358@@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
42359 lpfc_debugfs_enable = 0;
42360
42361 len = 0;
42362- index = (atomic_read(&vport->disc_trc_cnt) + 1) &
42363+ index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
42364 (lpfc_debugfs_max_disc_trc - 1);
42365 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
42366 dtp = vport->disc_trc + i;
42367@@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
42368 lpfc_debugfs_enable = 0;
42369
42370 len = 0;
42371- index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
42372+ index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
42373 (lpfc_debugfs_max_slow_ring_trc - 1);
42374 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
42375 dtp = phba->slow_ring_trc + i;
42376@@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
42377 !vport || !vport->disc_trc)
42378 return;
42379
42380- index = atomic_inc_return(&vport->disc_trc_cnt) &
42381+ index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
42382 (lpfc_debugfs_max_disc_trc - 1);
42383 dtp = vport->disc_trc + index;
42384 dtp->fmt = fmt;
42385 dtp->data1 = data1;
42386 dtp->data2 = data2;
42387 dtp->data3 = data3;
42388- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42389+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42390 dtp->jif = jiffies;
42391 #endif
42392 return;
42393@@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
42394 !phba || !phba->slow_ring_trc)
42395 return;
42396
42397- index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
42398+ index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
42399 (lpfc_debugfs_max_slow_ring_trc - 1);
42400 dtp = phba->slow_ring_trc + index;
42401 dtp->fmt = fmt;
42402 dtp->data1 = data1;
42403 dtp->data2 = data2;
42404 dtp->data3 = data3;
42405- dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
42406+ dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
42407 dtp->jif = jiffies;
42408 #endif
42409 return;
42410@@ -1178,7 +1178,7 @@ lpfc_debugfs_lseek(struct file *file, loff_t off, int whence)
42411 pos = file->f_pos + off;
42412 break;
42413 case 2:
42414- pos = debug->len - off;
42415+ pos = debug->len + off;
42416 }
42417 return (pos < 0 || pos > debug->len) ? -EINVAL : (file->f_pos = pos);
42418 }
42419@@ -4182,7 +4182,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42420 "slow_ring buffer\n");
42421 goto debug_failed;
42422 }
42423- atomic_set(&phba->slow_ring_trc_cnt, 0);
42424+ atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
42425 memset(phba->slow_ring_trc, 0,
42426 (sizeof(struct lpfc_debugfs_trc) *
42427 lpfc_debugfs_max_slow_ring_trc));
42428@@ -4228,7 +4228,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
42429 "buffer\n");
42430 goto debug_failed;
42431 }
42432- atomic_set(&vport->disc_trc_cnt, 0);
42433+ atomic_set_unchecked(&vport->disc_trc_cnt, 0);
42434
42435 snprintf(name, sizeof(name), "discovery_trace");
42436 vport->debug_disc_trc =
42437diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
42438index 314b4f6..7005d10 100644
42439--- a/drivers/scsi/lpfc/lpfc_init.c
42440+++ b/drivers/scsi/lpfc/lpfc_init.c
42441@@ -10551,8 +10551,10 @@ lpfc_init(void)
42442 "misc_register returned with status %d", error);
42443
42444 if (lpfc_enable_npiv) {
42445- lpfc_transport_functions.vport_create = lpfc_vport_create;
42446- lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42447+ pax_open_kernel();
42448+ *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
42449+ *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
42450+ pax_close_kernel();
42451 }
42452 lpfc_transport_template =
42453 fc_attach_transport(&lpfc_transport_functions);
42454diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
42455index 98af07c..7625fb5 100644
42456--- a/drivers/scsi/lpfc/lpfc_scsi.c
42457+++ b/drivers/scsi/lpfc/lpfc_scsi.c
42458@@ -325,7 +325,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
42459 uint32_t evt_posted;
42460
42461 spin_lock_irqsave(&phba->hbalock, flags);
42462- atomic_inc(&phba->num_rsrc_err);
42463+ atomic_inc_unchecked(&phba->num_rsrc_err);
42464 phba->last_rsrc_error_time = jiffies;
42465
42466 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
42467@@ -366,7 +366,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
42468 unsigned long flags;
42469 struct lpfc_hba *phba = vport->phba;
42470 uint32_t evt_posted;
42471- atomic_inc(&phba->num_cmd_success);
42472+ atomic_inc_unchecked(&phba->num_cmd_success);
42473
42474 if (vport->cfg_lun_queue_depth <= queue_depth)
42475 return;
42476@@ -410,8 +410,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42477 unsigned long num_rsrc_err, num_cmd_success;
42478 int i;
42479
42480- num_rsrc_err = atomic_read(&phba->num_rsrc_err);
42481- num_cmd_success = atomic_read(&phba->num_cmd_success);
42482+ num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
42483+ num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
42484
42485 /*
42486 * The error and success command counters are global per
42487@@ -439,8 +439,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
42488 }
42489 }
42490 lpfc_destroy_vport_work_array(phba, vports);
42491- atomic_set(&phba->num_rsrc_err, 0);
42492- atomic_set(&phba->num_cmd_success, 0);
42493+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42494+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42495 }
42496
42497 /**
42498@@ -474,8 +474,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
42499 }
42500 }
42501 lpfc_destroy_vport_work_array(phba, vports);
42502- atomic_set(&phba->num_rsrc_err, 0);
42503- atomic_set(&phba->num_cmd_success, 0);
42504+ atomic_set_unchecked(&phba->num_rsrc_err, 0);
42505+ atomic_set_unchecked(&phba->num_cmd_success, 0);
42506 }
42507
42508 /**
42509diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
42510index b46f5e9..c4c4ccb 100644
42511--- a/drivers/scsi/pmcraid.c
42512+++ b/drivers/scsi/pmcraid.c
42513@@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
42514 res->scsi_dev = scsi_dev;
42515 scsi_dev->hostdata = res;
42516 res->change_detected = 0;
42517- atomic_set(&res->read_failures, 0);
42518- atomic_set(&res->write_failures, 0);
42519+ atomic_set_unchecked(&res->read_failures, 0);
42520+ atomic_set_unchecked(&res->write_failures, 0);
42521 rc = 0;
42522 }
42523 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
42524@@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
42525
42526 /* If this was a SCSI read/write command keep count of errors */
42527 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
42528- atomic_inc(&res->read_failures);
42529+ atomic_inc_unchecked(&res->read_failures);
42530 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
42531- atomic_inc(&res->write_failures);
42532+ atomic_inc_unchecked(&res->write_failures);
42533
42534 if (!RES_IS_GSCSI(res->cfg_entry) &&
42535 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
42536@@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
42537 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42538 * hrrq_id assigned here in queuecommand
42539 */
42540- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42541+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42542 pinstance->num_hrrq;
42543 cmd->cmd_done = pmcraid_io_done;
42544
42545@@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
42546 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
42547 * hrrq_id assigned here in queuecommand
42548 */
42549- ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
42550+ ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
42551 pinstance->num_hrrq;
42552
42553 if (request_size) {
42554@@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
42555
42556 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
42557 /* add resources only after host is added into system */
42558- if (!atomic_read(&pinstance->expose_resources))
42559+ if (!atomic_read_unchecked(&pinstance->expose_resources))
42560 return;
42561
42562 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
42563@@ -5324,8 +5324,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
42564 init_waitqueue_head(&pinstance->reset_wait_q);
42565
42566 atomic_set(&pinstance->outstanding_cmds, 0);
42567- atomic_set(&pinstance->last_message_id, 0);
42568- atomic_set(&pinstance->expose_resources, 0);
42569+ atomic_set_unchecked(&pinstance->last_message_id, 0);
42570+ atomic_set_unchecked(&pinstance->expose_resources, 0);
42571
42572 INIT_LIST_HEAD(&pinstance->free_res_q);
42573 INIT_LIST_HEAD(&pinstance->used_res_q);
42574@@ -6038,7 +6038,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
42575 /* Schedule worker thread to handle CCN and take care of adding and
42576 * removing devices to OS
42577 */
42578- atomic_set(&pinstance->expose_resources, 1);
42579+ atomic_set_unchecked(&pinstance->expose_resources, 1);
42580 schedule_work(&pinstance->worker_q);
42581 return rc;
42582
42583diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
42584index e1d150f..6c6df44 100644
42585--- a/drivers/scsi/pmcraid.h
42586+++ b/drivers/scsi/pmcraid.h
42587@@ -748,7 +748,7 @@ struct pmcraid_instance {
42588 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
42589
42590 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
42591- atomic_t last_message_id;
42592+ atomic_unchecked_t last_message_id;
42593
42594 /* configuration table */
42595 struct pmcraid_config_table *cfg_table;
42596@@ -777,7 +777,7 @@ struct pmcraid_instance {
42597 atomic_t outstanding_cmds;
42598
42599 /* should add/delete resources to mid-layer now ?*/
42600- atomic_t expose_resources;
42601+ atomic_unchecked_t expose_resources;
42602
42603
42604
42605@@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
42606 struct pmcraid_config_table_entry_ext cfg_entry_ext;
42607 };
42608 struct scsi_device *scsi_dev; /* Link scsi_device structure */
42609- atomic_t read_failures; /* count of failed READ commands */
42610- atomic_t write_failures; /* count of failed WRITE commands */
42611+ atomic_unchecked_t read_failures; /* count of failed READ commands */
42612+ atomic_unchecked_t write_failures; /* count of failed WRITE commands */
42613
42614 /* To indicate add/delete/modify during CCN */
42615 u8 change_detected;
42616diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
42617index b3db9dc..c3b1756 100644
42618--- a/drivers/scsi/qla2xxx/qla_attr.c
42619+++ b/drivers/scsi/qla2xxx/qla_attr.c
42620@@ -1971,7 +1971,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
42621 return 0;
42622 }
42623
42624-struct fc_function_template qla2xxx_transport_functions = {
42625+fc_function_template_no_const qla2xxx_transport_functions = {
42626
42627 .show_host_node_name = 1,
42628 .show_host_port_name = 1,
42629@@ -2018,7 +2018,7 @@ struct fc_function_template qla2xxx_transport_functions = {
42630 .bsg_timeout = qla24xx_bsg_timeout,
42631 };
42632
42633-struct fc_function_template qla2xxx_transport_vport_functions = {
42634+fc_function_template_no_const qla2xxx_transport_vport_functions = {
42635
42636 .show_host_node_name = 1,
42637 .show_host_port_name = 1,
42638diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
42639index b310fa9..b9b3944 100644
42640--- a/drivers/scsi/qla2xxx/qla_gbl.h
42641+++ b/drivers/scsi/qla2xxx/qla_gbl.h
42642@@ -523,8 +523,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
42643 struct device_attribute;
42644 extern struct device_attribute *qla2x00_host_attrs[];
42645 struct fc_function_template;
42646-extern struct fc_function_template qla2xxx_transport_functions;
42647-extern struct fc_function_template qla2xxx_transport_vport_functions;
42648+extern fc_function_template_no_const qla2xxx_transport_functions;
42649+extern fc_function_template_no_const qla2xxx_transport_vport_functions;
42650 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
42651 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
42652 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
42653diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
42654index 2c6dd3d..e5ecd82 100644
42655--- a/drivers/scsi/qla2xxx/qla_os.c
42656+++ b/drivers/scsi/qla2xxx/qla_os.c
42657@@ -1554,8 +1554,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
42658 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
42659 /* Ok, a 64bit DMA mask is applicable. */
42660 ha->flags.enable_64bit_addressing = 1;
42661- ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42662- ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42663+ pax_open_kernel();
42664+ *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
42665+ *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
42666+ pax_close_kernel();
42667 return;
42668 }
42669 }
42670diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
42671index 129f5dd..ade53e8 100644
42672--- a/drivers/scsi/qla4xxx/ql4_def.h
42673+++ b/drivers/scsi/qla4xxx/ql4_def.h
42674@@ -275,7 +275,7 @@ struct ddb_entry {
42675 * (4000 only) */
42676 atomic_t relogin_timer; /* Max Time to wait for
42677 * relogin to complete */
42678- atomic_t relogin_retry_count; /* Num of times relogin has been
42679+ atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
42680 * retried */
42681 uint32_t default_time2wait; /* Default Min time between
42682 * relogins (+aens) */
42683diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
42684index 6142729..b6a85c9 100644
42685--- a/drivers/scsi/qla4xxx/ql4_os.c
42686+++ b/drivers/scsi/qla4xxx/ql4_os.c
42687@@ -2622,12 +2622,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
42688 */
42689 if (!iscsi_is_session_online(cls_sess)) {
42690 /* Reset retry relogin timer */
42691- atomic_inc(&ddb_entry->relogin_retry_count);
42692+ atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
42693 DEBUG2(ql4_printk(KERN_INFO, ha,
42694 "%s: index[%d] relogin timed out-retrying"
42695 " relogin (%d), retry (%d)\n", __func__,
42696 ddb_entry->fw_ddb_index,
42697- atomic_read(&ddb_entry->relogin_retry_count),
42698+ atomic_read_unchecked(&ddb_entry->relogin_retry_count),
42699 ddb_entry->default_time2wait + 4));
42700 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
42701 atomic_set(&ddb_entry->retry_relogin_timer,
42702@@ -4742,7 +4742,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
42703
42704 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
42705 atomic_set(&ddb_entry->relogin_timer, 0);
42706- atomic_set(&ddb_entry->relogin_retry_count, 0);
42707+ atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
42708 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
42709 ddb_entry->default_relogin_timeout =
42710 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
42711diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
42712index 2c0d0ec..4e8681a 100644
42713--- a/drivers/scsi/scsi.c
42714+++ b/drivers/scsi/scsi.c
42715@@ -661,7 +661,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
42716 unsigned long timeout;
42717 int rtn = 0;
42718
42719- atomic_inc(&cmd->device->iorequest_cnt);
42720+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42721
42722 /* check if the device is still usable */
42723 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
42724diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
42725index c31187d..0ead8c3 100644
42726--- a/drivers/scsi/scsi_lib.c
42727+++ b/drivers/scsi/scsi_lib.c
42728@@ -1459,7 +1459,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
42729 shost = sdev->host;
42730 scsi_init_cmd_errh(cmd);
42731 cmd->result = DID_NO_CONNECT << 16;
42732- atomic_inc(&cmd->device->iorequest_cnt);
42733+ atomic_inc_unchecked(&cmd->device->iorequest_cnt);
42734
42735 /*
42736 * SCSI request completion path will do scsi_device_unbusy(),
42737@@ -1485,9 +1485,9 @@ static void scsi_softirq_done(struct request *rq)
42738
42739 INIT_LIST_HEAD(&cmd->eh_entry);
42740
42741- atomic_inc(&cmd->device->iodone_cnt);
42742+ atomic_inc_unchecked(&cmd->device->iodone_cnt);
42743 if (cmd->result)
42744- atomic_inc(&cmd->device->ioerr_cnt);
42745+ atomic_inc_unchecked(&cmd->device->ioerr_cnt);
42746
42747 disposition = scsi_decide_disposition(cmd);
42748 if (disposition != SUCCESS &&
42749diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
42750index 931a7d9..0c2a754 100644
42751--- a/drivers/scsi/scsi_sysfs.c
42752+++ b/drivers/scsi/scsi_sysfs.c
42753@@ -658,7 +658,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
42754 char *buf) \
42755 { \
42756 struct scsi_device *sdev = to_scsi_device(dev); \
42757- unsigned long long count = atomic_read(&sdev->field); \
42758+ unsigned long long count = atomic_read_unchecked(&sdev->field); \
42759 return snprintf(buf, 20, "0x%llx\n", count); \
42760 } \
42761 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
42762diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
42763index 84a1fdf..693b0d6 100644
42764--- a/drivers/scsi/scsi_tgt_lib.c
42765+++ b/drivers/scsi/scsi_tgt_lib.c
42766@@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
42767 int err;
42768
42769 dprintk("%lx %u\n", uaddr, len);
42770- err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
42771+ err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
42772 if (err) {
42773 /*
42774 * TODO: need to fixup sg_tablesize, max_segment_size,
42775diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
42776index e894ca7..de9d7660 100644
42777--- a/drivers/scsi/scsi_transport_fc.c
42778+++ b/drivers/scsi/scsi_transport_fc.c
42779@@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
42780 * Netlink Infrastructure
42781 */
42782
42783-static atomic_t fc_event_seq;
42784+static atomic_unchecked_t fc_event_seq;
42785
42786 /**
42787 * fc_get_event_number - Obtain the next sequential FC event number
42788@@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
42789 u32
42790 fc_get_event_number(void)
42791 {
42792- return atomic_add_return(1, &fc_event_seq);
42793+ return atomic_add_return_unchecked(1, &fc_event_seq);
42794 }
42795 EXPORT_SYMBOL(fc_get_event_number);
42796
42797@@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
42798 {
42799 int error;
42800
42801- atomic_set(&fc_event_seq, 0);
42802+ atomic_set_unchecked(&fc_event_seq, 0);
42803
42804 error = transport_class_register(&fc_host_class);
42805 if (error)
42806@@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
42807 char *cp;
42808
42809 *val = simple_strtoul(buf, &cp, 0);
42810- if ((*cp && (*cp != '\n')) || (*val < 0))
42811+ if (*cp && (*cp != '\n'))
42812 return -EINVAL;
42813 /*
42814 * Check for overflow; dev_loss_tmo is u32
42815diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
42816index 0a74b97..fa8d648 100644
42817--- a/drivers/scsi/scsi_transport_iscsi.c
42818+++ b/drivers/scsi/scsi_transport_iscsi.c
42819@@ -79,7 +79,7 @@ struct iscsi_internal {
42820 struct transport_container session_cont;
42821 };
42822
42823-static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
42824+static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
42825 static struct workqueue_struct *iscsi_eh_timer_workq;
42826
42827 static DEFINE_IDA(iscsi_sess_ida);
42828@@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
42829 int err;
42830
42831 ihost = shost->shost_data;
42832- session->sid = atomic_add_return(1, &iscsi_session_nr);
42833+ session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
42834
42835 if (target_id == ISCSI_MAX_TARGET) {
42836 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
42837@@ -2955,7 +2955,7 @@ static __init int iscsi_transport_init(void)
42838 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
42839 ISCSI_TRANSPORT_VERSION);
42840
42841- atomic_set(&iscsi_session_nr, 0);
42842+ atomic_set_unchecked(&iscsi_session_nr, 0);
42843
42844 err = class_register(&iscsi_transport_class);
42845 if (err)
42846diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
42847index f379c7f..e8fc69c 100644
42848--- a/drivers/scsi/scsi_transport_srp.c
42849+++ b/drivers/scsi/scsi_transport_srp.c
42850@@ -33,7 +33,7 @@
42851 #include "scsi_transport_srp_internal.h"
42852
42853 struct srp_host_attrs {
42854- atomic_t next_port_id;
42855+ atomic_unchecked_t next_port_id;
42856 };
42857 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
42858
42859@@ -61,7 +61,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
42860 struct Scsi_Host *shost = dev_to_shost(dev);
42861 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
42862
42863- atomic_set(&srp_host->next_port_id, 0);
42864+ atomic_set_unchecked(&srp_host->next_port_id, 0);
42865 return 0;
42866 }
42867
42868@@ -210,7 +210,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
42869 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
42870 rport->roles = ids->roles;
42871
42872- id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
42873+ id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
42874 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
42875
42876 transport_setup_device(&rport->dev);
42877diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
42878index 82910cc..7c350ad 100644
42879--- a/drivers/scsi/sd.c
42880+++ b/drivers/scsi/sd.c
42881@@ -2929,7 +2929,7 @@ static int sd_probe(struct device *dev)
42882 sdkp->disk = gd;
42883 sdkp->index = index;
42884 atomic_set(&sdkp->openers, 0);
42885- atomic_set(&sdkp->device->ioerr_cnt, 0);
42886+ atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
42887
42888 if (!sdp->request_queue->rq_timeout) {
42889 if (sdp->type != TYPE_MOD)
42890diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
42891index 9f0c465..47194ee 100644
42892--- a/drivers/scsi/sg.c
42893+++ b/drivers/scsi/sg.c
42894@@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
42895 sdp->disk->disk_name,
42896 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
42897 NULL,
42898- (char *)arg);
42899+ (char __user *)arg);
42900 case BLKTRACESTART:
42901 return blk_trace_startstop(sdp->device->request_queue, 1);
42902 case BLKTRACESTOP:
42903diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
42904index 004b10f..7c98d51 100644
42905--- a/drivers/spi/spi.c
42906+++ b/drivers/spi/spi.c
42907@@ -1620,7 +1620,7 @@ int spi_bus_unlock(struct spi_master *master)
42908 EXPORT_SYMBOL_GPL(spi_bus_unlock);
42909
42910 /* portable code must never pass more than 32 bytes */
42911-#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
42912+#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
42913
42914 static u8 *buf;
42915
42916diff --git a/drivers/staging/iio/iio_hwmon.c b/drivers/staging/iio/iio_hwmon.c
42917index 93af756..a4bc5bf 100644
42918--- a/drivers/staging/iio/iio_hwmon.c
42919+++ b/drivers/staging/iio/iio_hwmon.c
42920@@ -67,7 +67,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
42921 {
42922 struct device *dev = &pdev->dev;
42923 struct iio_hwmon_state *st;
42924- struct sensor_device_attribute *a;
42925+ sensor_device_attribute_no_const *a;
42926 int ret, i;
42927 int in_i = 1, temp_i = 1, curr_i = 1;
42928 enum iio_chan_type type;
42929diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
42930index 34afc16..ffe44dd 100644
42931--- a/drivers/staging/octeon/ethernet-rx.c
42932+++ b/drivers/staging/octeon/ethernet-rx.c
42933@@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42934 /* Increment RX stats for virtual ports */
42935 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
42936 #ifdef CONFIG_64BIT
42937- atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
42938- atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
42939+ atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
42940+ atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
42941 #else
42942- atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
42943- atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
42944+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
42945+ atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
42946 #endif
42947 }
42948 netif_receive_skb(skb);
42949@@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
42950 dev->name);
42951 */
42952 #ifdef CONFIG_64BIT
42953- atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
42954+ atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42955 #else
42956- atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
42957+ atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
42958 #endif
42959 dev_kfree_skb_irq(skb);
42960 }
42961diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
42962index c3a90e7..023619a 100644
42963--- a/drivers/staging/octeon/ethernet.c
42964+++ b/drivers/staging/octeon/ethernet.c
42965@@ -252,11 +252,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
42966 * since the RX tasklet also increments it.
42967 */
42968 #ifdef CONFIG_64BIT
42969- atomic64_add(rx_status.dropped_packets,
42970- (atomic64_t *)&priv->stats.rx_dropped);
42971+ atomic64_add_unchecked(rx_status.dropped_packets,
42972+ (atomic64_unchecked_t *)&priv->stats.rx_dropped);
42973 #else
42974- atomic_add(rx_status.dropped_packets,
42975- (atomic_t *)&priv->stats.rx_dropped);
42976+ atomic_add_unchecked(rx_status.dropped_packets,
42977+ (atomic_unchecked_t *)&priv->stats.rx_dropped);
42978 #endif
42979 }
42980
42981diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
42982index dc23395..cf7e9b1 100644
42983--- a/drivers/staging/rtl8712/rtl871x_io.h
42984+++ b/drivers/staging/rtl8712/rtl871x_io.h
42985@@ -108,7 +108,7 @@ struct _io_ops {
42986 u8 *pmem);
42987 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
42988 u8 *pmem);
42989-};
42990+} __no_const;
42991
42992 struct io_req {
42993 struct list_head list;
42994diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
42995index 1f5088b..0e59820 100644
42996--- a/drivers/staging/sbe-2t3e3/netdev.c
42997+++ b/drivers/staging/sbe-2t3e3/netdev.c
42998@@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
42999 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
43000
43001 if (rlen)
43002- if (copy_to_user(data, &resp, rlen))
43003+ if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
43004 return -EFAULT;
43005
43006 return 0;
43007diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
43008index 5dddc4d..34fcb2f 100644
43009--- a/drivers/staging/usbip/vhci.h
43010+++ b/drivers/staging/usbip/vhci.h
43011@@ -83,7 +83,7 @@ struct vhci_hcd {
43012 unsigned resuming:1;
43013 unsigned long re_timeout;
43014
43015- atomic_t seqnum;
43016+ atomic_unchecked_t seqnum;
43017
43018 /*
43019 * NOTE:
43020diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
43021index f1ca084..7b5c0c3 100644
43022--- a/drivers/staging/usbip/vhci_hcd.c
43023+++ b/drivers/staging/usbip/vhci_hcd.c
43024@@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
43025
43026 spin_lock(&vdev->priv_lock);
43027
43028- priv->seqnum = atomic_inc_return(&the_controller->seqnum);
43029+ priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43030 if (priv->seqnum == 0xffff)
43031 dev_info(&urb->dev->dev, "seqnum max\n");
43032
43033@@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
43034 return -ENOMEM;
43035 }
43036
43037- unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
43038+ unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
43039 if (unlink->seqnum == 0xffff)
43040 pr_info("seqnum max\n");
43041
43042@@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
43043 vdev->rhport = rhport;
43044 }
43045
43046- atomic_set(&vhci->seqnum, 0);
43047+ atomic_set_unchecked(&vhci->seqnum, 0);
43048 spin_lock_init(&vhci->lock);
43049
43050 hcd->power_budget = 0; /* no limit */
43051diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
43052index faf8e60..c46f8ab 100644
43053--- a/drivers/staging/usbip/vhci_rx.c
43054+++ b/drivers/staging/usbip/vhci_rx.c
43055@@ -76,7 +76,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
43056 if (!urb) {
43057 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
43058 pr_info("max seqnum %d\n",
43059- atomic_read(&the_controller->seqnum));
43060+ atomic_read_unchecked(&the_controller->seqnum));
43061 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
43062 return;
43063 }
43064diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
43065index 5f13890..36a044b 100644
43066--- a/drivers/staging/vt6655/hostap.c
43067+++ b/drivers/staging/vt6655/hostap.c
43068@@ -73,14 +73,13 @@ static int msglevel =MSG_LEVEL_INFO;
43069 *
43070 */
43071
43072+static net_device_ops_no_const apdev_netdev_ops;
43073+
43074 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43075 {
43076 PSDevice apdev_priv;
43077 struct net_device *dev = pDevice->dev;
43078 int ret;
43079- const struct net_device_ops apdev_netdev_ops = {
43080- .ndo_start_xmit = pDevice->tx_80211,
43081- };
43082
43083 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43084
43085@@ -92,6 +91,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
43086 *apdev_priv = *pDevice;
43087 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43088
43089+ /* only half broken now */
43090+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43091 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43092
43093 pDevice->apdev->type = ARPHRD_IEEE80211;
43094diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
43095index a94e66f..31984d0 100644
43096--- a/drivers/staging/vt6656/hostap.c
43097+++ b/drivers/staging/vt6656/hostap.c
43098@@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
43099 *
43100 */
43101
43102+static net_device_ops_no_const apdev_netdev_ops;
43103+
43104 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43105 {
43106 struct vnt_private *apdev_priv;
43107 struct net_device *dev = pDevice->dev;
43108 int ret;
43109- const struct net_device_ops apdev_netdev_ops = {
43110- .ndo_start_xmit = pDevice->tx_80211,
43111- };
43112
43113 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
43114
43115@@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
43116 *apdev_priv = *pDevice;
43117 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
43118
43119+ /* only half broken now */
43120+ apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
43121 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
43122
43123 pDevice->apdev->type = ARPHRD_IEEE80211;
43124diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
43125index a2b7e03..9ff4bbd 100644
43126--- a/drivers/staging/zcache/tmem.c
43127+++ b/drivers/staging/zcache/tmem.c
43128@@ -50,7 +50,7 @@
43129 * A tmem host implementation must use this function to register callbacks
43130 * for memory allocation.
43131 */
43132-static struct tmem_hostops tmem_hostops;
43133+static tmem_hostops_no_const tmem_hostops;
43134
43135 static void tmem_objnode_tree_init(void);
43136
43137@@ -64,7 +64,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
43138 * A tmem host implementation must use this function to register
43139 * callbacks for a page-accessible memory (PAM) implementation.
43140 */
43141-static struct tmem_pamops tmem_pamops;
43142+static tmem_pamops_no_const tmem_pamops;
43143
43144 void tmem_register_pamops(struct tmem_pamops *m)
43145 {
43146diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
43147index adbe5a8..d387359 100644
43148--- a/drivers/staging/zcache/tmem.h
43149+++ b/drivers/staging/zcache/tmem.h
43150@@ -226,6 +226,7 @@ struct tmem_pamops {
43151 int (*replace_in_obj)(void *, struct tmem_obj *);
43152 #endif
43153 };
43154+typedef struct tmem_pamops __no_const tmem_pamops_no_const;
43155 extern void tmem_register_pamops(struct tmem_pamops *m);
43156
43157 /* memory allocation methods provided by the host implementation */
43158@@ -235,6 +236,7 @@ struct tmem_hostops {
43159 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
43160 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
43161 };
43162+typedef struct tmem_hostops __no_const tmem_hostops_no_const;
43163 extern void tmem_register_hostops(struct tmem_hostops *m);
43164
43165 /* core tmem accessor functions */
43166diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
43167index 2e4d655..fd72e68 100644
43168--- a/drivers/target/target_core_device.c
43169+++ b/drivers/target/target_core_device.c
43170@@ -1414,7 +1414,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
43171 spin_lock_init(&dev->se_port_lock);
43172 spin_lock_init(&dev->se_tmr_lock);
43173 spin_lock_init(&dev->qf_cmd_lock);
43174- atomic_set(&dev->dev_ordered_id, 0);
43175+ atomic_set_unchecked(&dev->dev_ordered_id, 0);
43176 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
43177 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
43178 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
43179diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
43180index fc9a5a0..1d5975e 100644
43181--- a/drivers/target/target_core_transport.c
43182+++ b/drivers/target/target_core_transport.c
43183@@ -1081,7 +1081,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
43184 * Used to determine when ORDERED commands should go from
43185 * Dormant to Active status.
43186 */
43187- cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
43188+ cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
43189 smp_mb__after_atomic_inc();
43190 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
43191 cmd->se_ordered_id, cmd->sam_task_attr,
43192diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
43193index 345bd0e..61d5375 100644
43194--- a/drivers/tty/cyclades.c
43195+++ b/drivers/tty/cyclades.c
43196@@ -1576,10 +1576,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
43197 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
43198 info->port.count);
43199 #endif
43200- info->port.count++;
43201+ atomic_inc(&info->port.count);
43202 #ifdef CY_DEBUG_COUNT
43203 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
43204- current->pid, info->port.count);
43205+ current->pid, atomic_read(&info->port.count));
43206 #endif
43207
43208 /*
43209@@ -3978,7 +3978,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
43210 for (j = 0; j < cy_card[i].nports; j++) {
43211 info = &cy_card[i].ports[j];
43212
43213- if (info->port.count) {
43214+ if (atomic_read(&info->port.count)) {
43215 /* XXX is the ldisc num worth this? */
43216 struct tty_struct *tty;
43217 struct tty_ldisc *ld;
43218diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
43219index eb255e8..f637a57 100644
43220--- a/drivers/tty/hvc/hvc_console.c
43221+++ b/drivers/tty/hvc/hvc_console.c
43222@@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
43223
43224 spin_lock_irqsave(&hp->port.lock, flags);
43225 /* Check and then increment for fast path open. */
43226- if (hp->port.count++ > 0) {
43227+ if (atomic_inc_return(&hp->port.count) > 1) {
43228 spin_unlock_irqrestore(&hp->port.lock, flags);
43229 hvc_kick();
43230 return 0;
43231@@ -388,7 +388,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43232
43233 spin_lock_irqsave(&hp->port.lock, flags);
43234
43235- if (--hp->port.count == 0) {
43236+ if (atomic_dec_return(&hp->port.count) == 0) {
43237 spin_unlock_irqrestore(&hp->port.lock, flags);
43238 /* We are done with the tty pointer now. */
43239 tty_port_tty_set(&hp->port, NULL);
43240@@ -406,9 +406,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
43241 */
43242 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
43243 } else {
43244- if (hp->port.count < 0)
43245+ if (atomic_read(&hp->port.count) < 0)
43246 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
43247- hp->vtermno, hp->port.count);
43248+ hp->vtermno, atomic_read(&hp->port.count));
43249 spin_unlock_irqrestore(&hp->port.lock, flags);
43250 }
43251 }
43252@@ -438,12 +438,12 @@ static void hvc_hangup(struct tty_struct *tty)
43253 * open->hangup case this can be called after the final close so prevent
43254 * that from happening for now.
43255 */
43256- if (hp->port.count <= 0) {
43257+ if (atomic_read(&hp->port.count) <= 0) {
43258 spin_unlock_irqrestore(&hp->port.lock, flags);
43259 return;
43260 }
43261
43262- hp->port.count = 0;
43263+ atomic_set(&hp->port.count, 0);
43264 spin_unlock_irqrestore(&hp->port.lock, flags);
43265 tty_port_tty_set(&hp->port, NULL);
43266
43267@@ -491,7 +491,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
43268 return -EPIPE;
43269
43270 /* FIXME what's this (unprotected) check for? */
43271- if (hp->port.count <= 0)
43272+ if (atomic_read(&hp->port.count) <= 0)
43273 return -EIO;
43274
43275 spin_lock_irqsave(&hp->lock, flags);
43276diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
43277index 81e939e..95ead10 100644
43278--- a/drivers/tty/hvc/hvcs.c
43279+++ b/drivers/tty/hvc/hvcs.c
43280@@ -83,6 +83,7 @@
43281 #include <asm/hvcserver.h>
43282 #include <asm/uaccess.h>
43283 #include <asm/vio.h>
43284+#include <asm/local.h>
43285
43286 /*
43287 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
43288@@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
43289
43290 spin_lock_irqsave(&hvcsd->lock, flags);
43291
43292- if (hvcsd->port.count > 0) {
43293+ if (atomic_read(&hvcsd->port.count) > 0) {
43294 spin_unlock_irqrestore(&hvcsd->lock, flags);
43295 printk(KERN_INFO "HVCS: vterm state unchanged. "
43296 "The hvcs device node is still in use.\n");
43297@@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
43298 }
43299 }
43300
43301- hvcsd->port.count = 0;
43302+ atomic_set(&hvcsd->port.count, 0);
43303 hvcsd->port.tty = tty;
43304 tty->driver_data = hvcsd;
43305
43306@@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
43307 unsigned long flags;
43308
43309 spin_lock_irqsave(&hvcsd->lock, flags);
43310- hvcsd->port.count++;
43311+ atomic_inc(&hvcsd->port.count);
43312 hvcsd->todo_mask |= HVCS_SCHED_READ;
43313 spin_unlock_irqrestore(&hvcsd->lock, flags);
43314
43315@@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43316 hvcsd = tty->driver_data;
43317
43318 spin_lock_irqsave(&hvcsd->lock, flags);
43319- if (--hvcsd->port.count == 0) {
43320+ if (atomic_dec_and_test(&hvcsd->port.count)) {
43321
43322 vio_disable_interrupts(hvcsd->vdev);
43323
43324@@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
43325
43326 free_irq(irq, hvcsd);
43327 return;
43328- } else if (hvcsd->port.count < 0) {
43329+ } else if (atomic_read(&hvcsd->port.count) < 0) {
43330 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
43331 " is missmanaged.\n",
43332- hvcsd->vdev->unit_address, hvcsd->port.count);
43333+ hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
43334 }
43335
43336 spin_unlock_irqrestore(&hvcsd->lock, flags);
43337@@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43338
43339 spin_lock_irqsave(&hvcsd->lock, flags);
43340 /* Preserve this so that we know how many kref refs to put */
43341- temp_open_count = hvcsd->port.count;
43342+ temp_open_count = atomic_read(&hvcsd->port.count);
43343
43344 /*
43345 * Don't kref put inside the spinlock because the destruction
43346@@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
43347 tty->driver_data = NULL;
43348 hvcsd->port.tty = NULL;
43349
43350- hvcsd->port.count = 0;
43351+ atomic_set(&hvcsd->port.count, 0);
43352
43353 /* This will drop any buffered data on the floor which is OK in a hangup
43354 * scenario. */
43355@@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
43356 * the middle of a write operation? This is a crummy place to do this
43357 * but we want to keep it all in the spinlock.
43358 */
43359- if (hvcsd->port.count <= 0) {
43360+ if (atomic_read(&hvcsd->port.count) <= 0) {
43361 spin_unlock_irqrestore(&hvcsd->lock, flags);
43362 return -ENODEV;
43363 }
43364@@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
43365 {
43366 struct hvcs_struct *hvcsd = tty->driver_data;
43367
43368- if (!hvcsd || hvcsd->port.count <= 0)
43369+ if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
43370 return 0;
43371
43372 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
43373diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
43374index 8fd72ff..34a0bed 100644
43375--- a/drivers/tty/ipwireless/tty.c
43376+++ b/drivers/tty/ipwireless/tty.c
43377@@ -29,6 +29,7 @@
43378 #include <linux/tty_driver.h>
43379 #include <linux/tty_flip.h>
43380 #include <linux/uaccess.h>
43381+#include <asm/local.h>
43382
43383 #include "tty.h"
43384 #include "network.h"
43385@@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43386 mutex_unlock(&tty->ipw_tty_mutex);
43387 return -ENODEV;
43388 }
43389- if (tty->port.count == 0)
43390+ if (atomic_read(&tty->port.count) == 0)
43391 tty->tx_bytes_queued = 0;
43392
43393- tty->port.count++;
43394+ atomic_inc(&tty->port.count);
43395
43396 tty->port.tty = linux_tty;
43397 linux_tty->driver_data = tty;
43398@@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
43399
43400 static void do_ipw_close(struct ipw_tty *tty)
43401 {
43402- tty->port.count--;
43403-
43404- if (tty->port.count == 0) {
43405+ if (atomic_dec_return(&tty->port.count) == 0) {
43406 struct tty_struct *linux_tty = tty->port.tty;
43407
43408 if (linux_tty != NULL) {
43409@@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
43410 return;
43411
43412 mutex_lock(&tty->ipw_tty_mutex);
43413- if (tty->port.count == 0) {
43414+ if (atomic_read(&tty->port.count) == 0) {
43415 mutex_unlock(&tty->ipw_tty_mutex);
43416 return;
43417 }
43418@@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
43419
43420 mutex_lock(&tty->ipw_tty_mutex);
43421
43422- if (!tty->port.count) {
43423+ if (!atomic_read(&tty->port.count)) {
43424 mutex_unlock(&tty->ipw_tty_mutex);
43425 return;
43426 }
43427@@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
43428 return -ENODEV;
43429
43430 mutex_lock(&tty->ipw_tty_mutex);
43431- if (!tty->port.count) {
43432+ if (!atomic_read(&tty->port.count)) {
43433 mutex_unlock(&tty->ipw_tty_mutex);
43434 return -EINVAL;
43435 }
43436@@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
43437 if (!tty)
43438 return -ENODEV;
43439
43440- if (!tty->port.count)
43441+ if (!atomic_read(&tty->port.count))
43442 return -EINVAL;
43443
43444 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
43445@@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
43446 if (!tty)
43447 return 0;
43448
43449- if (!tty->port.count)
43450+ if (!atomic_read(&tty->port.count))
43451 return 0;
43452
43453 return tty->tx_bytes_queued;
43454@@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
43455 if (!tty)
43456 return -ENODEV;
43457
43458- if (!tty->port.count)
43459+ if (!atomic_read(&tty->port.count))
43460 return -EINVAL;
43461
43462 return get_control_lines(tty);
43463@@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
43464 if (!tty)
43465 return -ENODEV;
43466
43467- if (!tty->port.count)
43468+ if (!atomic_read(&tty->port.count))
43469 return -EINVAL;
43470
43471 return set_control_lines(tty, set, clear);
43472@@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
43473 if (!tty)
43474 return -ENODEV;
43475
43476- if (!tty->port.count)
43477+ if (!atomic_read(&tty->port.count))
43478 return -EINVAL;
43479
43480 /* FIXME: Exactly how is the tty object locked here .. */
43481@@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
43482 * are gone */
43483 mutex_lock(&ttyj->ipw_tty_mutex);
43484 }
43485- while (ttyj->port.count)
43486+ while (atomic_read(&ttyj->port.count))
43487 do_ipw_close(ttyj);
43488 ipwireless_disassociate_network_ttys(network,
43489 ttyj->channel_idx);
43490diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
43491index adeac25..787a0a1 100644
43492--- a/drivers/tty/moxa.c
43493+++ b/drivers/tty/moxa.c
43494@@ -1193,7 +1193,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
43495 }
43496
43497 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
43498- ch->port.count++;
43499+ atomic_inc(&ch->port.count);
43500 tty->driver_data = ch;
43501 tty_port_tty_set(&ch->port, tty);
43502 mutex_lock(&ch->port.mutex);
43503diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
43504index 4a43ef5d7..aa71f27 100644
43505--- a/drivers/tty/n_gsm.c
43506+++ b/drivers/tty/n_gsm.c
43507@@ -1636,7 +1636,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
43508 spin_lock_init(&dlci->lock);
43509 mutex_init(&dlci->mutex);
43510 dlci->fifo = &dlci->_fifo;
43511- if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
43512+ if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
43513 kfree(dlci);
43514 return NULL;
43515 }
43516@@ -2936,7 +2936,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
43517 struct gsm_dlci *dlci = tty->driver_data;
43518 struct tty_port *port = &dlci->port;
43519
43520- port->count++;
43521+ atomic_inc(&port->count);
43522 dlci_get(dlci);
43523 dlci_get(dlci->gsm->dlci[0]);
43524 mux_get(dlci->gsm);
43525diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
43526index 1f8cba6..47b06c2 100644
43527--- a/drivers/tty/n_tty.c
43528+++ b/drivers/tty/n_tty.c
43529@@ -2205,6 +2205,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
43530 {
43531 *ops = tty_ldisc_N_TTY;
43532 ops->owner = NULL;
43533- ops->refcount = ops->flags = 0;
43534+ atomic_set(&ops->refcount, 0);
43535+ ops->flags = 0;
43536 }
43537 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
43538diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
43539index 74a5e8b..40c36a7 100644
43540--- a/drivers/tty/pty.c
43541+++ b/drivers/tty/pty.c
43542@@ -797,8 +797,10 @@ static void __init unix98_pty_init(void)
43543 panic("Couldn't register Unix98 pts driver");
43544
43545 /* Now create the /dev/ptmx special device */
43546+ pax_open_kernel();
43547 tty_default_fops(&ptmx_fops);
43548- ptmx_fops.open = ptmx_open;
43549+ *(void **)&ptmx_fops.open = ptmx_open;
43550+ pax_close_kernel();
43551
43552 cdev_init(&ptmx_cdev, &ptmx_fops);
43553 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
43554diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
43555index 1d27003..959f452 100644
43556--- a/drivers/tty/rocket.c
43557+++ b/drivers/tty/rocket.c
43558@@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43559 tty->driver_data = info;
43560 tty_port_tty_set(port, tty);
43561
43562- if (port->count++ == 0) {
43563+ if (atomic_inc_return(&port->count) == 1) {
43564 atomic_inc(&rp_num_ports_open);
43565
43566 #ifdef ROCKET_DEBUG_OPEN
43567@@ -932,7 +932,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
43568 #endif
43569 }
43570 #ifdef ROCKET_DEBUG_OPEN
43571- printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
43572+ printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
43573 #endif
43574
43575 /*
43576@@ -1527,7 +1527,7 @@ static void rp_hangup(struct tty_struct *tty)
43577 spin_unlock_irqrestore(&info->port.lock, flags);
43578 return;
43579 }
43580- if (info->port.count)
43581+ if (atomic_read(&info->port.count))
43582 atomic_dec(&rp_num_ports_open);
43583 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
43584 spin_unlock_irqrestore(&info->port.lock, flags);
43585diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
43586index 1002054..dd644a8 100644
43587--- a/drivers/tty/serial/kgdboc.c
43588+++ b/drivers/tty/serial/kgdboc.c
43589@@ -24,8 +24,9 @@
43590 #define MAX_CONFIG_LEN 40
43591
43592 static struct kgdb_io kgdboc_io_ops;
43593+static struct kgdb_io kgdboc_io_ops_console;
43594
43595-/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
43596+/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
43597 static int configured = -1;
43598
43599 static char config[MAX_CONFIG_LEN];
43600@@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
43601 kgdboc_unregister_kbd();
43602 if (configured == 1)
43603 kgdb_unregister_io_module(&kgdboc_io_ops);
43604+ else if (configured == 2)
43605+ kgdb_unregister_io_module(&kgdboc_io_ops_console);
43606 }
43607
43608 static int configure_kgdboc(void)
43609@@ -160,13 +163,13 @@ static int configure_kgdboc(void)
43610 int err;
43611 char *cptr = config;
43612 struct console *cons;
43613+ int is_console = 0;
43614
43615 err = kgdboc_option_setup(config);
43616 if (err || !strlen(config) || isspace(config[0]))
43617 goto noconfig;
43618
43619 err = -ENODEV;
43620- kgdboc_io_ops.is_console = 0;
43621 kgdb_tty_driver = NULL;
43622
43623 kgdboc_use_kms = 0;
43624@@ -187,7 +190,7 @@ static int configure_kgdboc(void)
43625 int idx;
43626 if (cons->device && cons->device(cons, &idx) == p &&
43627 idx == tty_line) {
43628- kgdboc_io_ops.is_console = 1;
43629+ is_console = 1;
43630 break;
43631 }
43632 cons = cons->next;
43633@@ -197,7 +200,13 @@ static int configure_kgdboc(void)
43634 kgdb_tty_line = tty_line;
43635
43636 do_register:
43637- err = kgdb_register_io_module(&kgdboc_io_ops);
43638+ if (is_console) {
43639+ err = kgdb_register_io_module(&kgdboc_io_ops_console);
43640+ configured = 2;
43641+ } else {
43642+ err = kgdb_register_io_module(&kgdboc_io_ops);
43643+ configured = 1;
43644+ }
43645 if (err)
43646 goto noconfig;
43647
43648@@ -205,8 +214,6 @@ do_register:
43649 if (err)
43650 goto nmi_con_failed;
43651
43652- configured = 1;
43653-
43654 return 0;
43655
43656 nmi_con_failed:
43657@@ -223,7 +230,7 @@ noconfig:
43658 static int __init init_kgdboc(void)
43659 {
43660 /* Already configured? */
43661- if (configured == 1)
43662+ if (configured >= 1)
43663 return 0;
43664
43665 return configure_kgdboc();
43666@@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
43667 if (config[len - 1] == '\n')
43668 config[len - 1] = '\0';
43669
43670- if (configured == 1)
43671+ if (configured >= 1)
43672 cleanup_kgdboc();
43673
43674 /* Go and configure with the new params. */
43675@@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
43676 .post_exception = kgdboc_post_exp_handler,
43677 };
43678
43679+static struct kgdb_io kgdboc_io_ops_console = {
43680+ .name = "kgdboc",
43681+ .read_char = kgdboc_get_char,
43682+ .write_char = kgdboc_put_char,
43683+ .pre_exception = kgdboc_pre_exp_handler,
43684+ .post_exception = kgdboc_post_exp_handler,
43685+ .is_console = 1
43686+};
43687+
43688 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
43689 /* This is only available if kgdboc is a built in for early debugging */
43690 static int __init kgdboc_early_init(char *opt)
43691diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
43692index 2769a38..f3dbe48 100644
43693--- a/drivers/tty/serial/samsung.c
43694+++ b/drivers/tty/serial/samsung.c
43695@@ -451,11 +451,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
43696 }
43697 }
43698
43699+static int s3c64xx_serial_startup(struct uart_port *port);
43700 static int s3c24xx_serial_startup(struct uart_port *port)
43701 {
43702 struct s3c24xx_uart_port *ourport = to_ourport(port);
43703 int ret;
43704
43705+ /* Startup sequence is different for s3c64xx and higher SoC's */
43706+ if (s3c24xx_serial_has_interrupt_mask(port))
43707+ return s3c64xx_serial_startup(port);
43708+
43709 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
43710 port->mapbase, port->membase);
43711
43712@@ -1120,10 +1125,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
43713 /* setup info for port */
43714 port->dev = &platdev->dev;
43715
43716- /* Startup sequence is different for s3c64xx and higher SoC's */
43717- if (s3c24xx_serial_has_interrupt_mask(port))
43718- s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
43719-
43720 port->uartclk = 1;
43721
43722 if (cfg->uart_flags & UPF_CONS_FLOW) {
43723diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
43724index 8fbb6d2..822a9e6 100644
43725--- a/drivers/tty/serial/serial_core.c
43726+++ b/drivers/tty/serial/serial_core.c
43727@@ -1454,7 +1454,7 @@ static void uart_hangup(struct tty_struct *tty)
43728 uart_flush_buffer(tty);
43729 uart_shutdown(tty, state);
43730 spin_lock_irqsave(&port->lock, flags);
43731- port->count = 0;
43732+ atomic_set(&port->count, 0);
43733 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
43734 spin_unlock_irqrestore(&port->lock, flags);
43735 tty_port_tty_set(port, NULL);
43736@@ -1550,7 +1550,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43737 goto end;
43738 }
43739
43740- port->count++;
43741+ atomic_inc(&port->count);
43742 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
43743 retval = -ENXIO;
43744 goto err_dec_count;
43745@@ -1578,7 +1578,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43746 /*
43747 * Make sure the device is in D0 state.
43748 */
43749- if (port->count == 1)
43750+ if (atomic_read(&port->count) == 1)
43751 uart_change_pm(state, UART_PM_STATE_ON);
43752
43753 /*
43754@@ -1596,7 +1596,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
43755 end:
43756 return retval;
43757 err_dec_count:
43758- port->count--;
43759+ atomic_inc(&port->count);
43760 mutex_unlock(&port->mutex);
43761 goto end;
43762 }
43763diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
43764index 8983276..72a4090 100644
43765--- a/drivers/tty/synclink.c
43766+++ b/drivers/tty/synclink.c
43767@@ -3093,7 +3093,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43768
43769 if (debug_level >= DEBUG_LEVEL_INFO)
43770 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
43771- __FILE__,__LINE__, info->device_name, info->port.count);
43772+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
43773
43774 if (tty_port_close_start(&info->port, tty, filp) == 0)
43775 goto cleanup;
43776@@ -3111,7 +3111,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
43777 cleanup:
43778 if (debug_level >= DEBUG_LEVEL_INFO)
43779 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
43780- tty->driver->name, info->port.count);
43781+ tty->driver->name, atomic_read(&info->port.count));
43782
43783 } /* end of mgsl_close() */
43784
43785@@ -3210,8 +3210,8 @@ static void mgsl_hangup(struct tty_struct *tty)
43786
43787 mgsl_flush_buffer(tty);
43788 shutdown(info);
43789-
43790- info->port.count = 0;
43791+
43792+ atomic_set(&info->port.count, 0);
43793 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43794 info->port.tty = NULL;
43795
43796@@ -3300,12 +3300,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43797
43798 if (debug_level >= DEBUG_LEVEL_INFO)
43799 printk("%s(%d):block_til_ready before block on %s count=%d\n",
43800- __FILE__,__LINE__, tty->driver->name, port->count );
43801+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43802
43803 spin_lock_irqsave(&info->irq_spinlock, flags);
43804 if (!tty_hung_up_p(filp)) {
43805 extra_count = true;
43806- port->count--;
43807+ atomic_dec(&port->count);
43808 }
43809 spin_unlock_irqrestore(&info->irq_spinlock, flags);
43810 port->blocked_open++;
43811@@ -3334,7 +3334,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43812
43813 if (debug_level >= DEBUG_LEVEL_INFO)
43814 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
43815- __FILE__,__LINE__, tty->driver->name, port->count );
43816+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43817
43818 tty_unlock(tty);
43819 schedule();
43820@@ -3346,12 +3346,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
43821
43822 /* FIXME: Racy on hangup during close wait */
43823 if (extra_count)
43824- port->count++;
43825+ atomic_inc(&port->count);
43826 port->blocked_open--;
43827
43828 if (debug_level >= DEBUG_LEVEL_INFO)
43829 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
43830- __FILE__,__LINE__, tty->driver->name, port->count );
43831+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
43832
43833 if (!retval)
43834 port->flags |= ASYNC_NORMAL_ACTIVE;
43835@@ -3403,7 +3403,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43836
43837 if (debug_level >= DEBUG_LEVEL_INFO)
43838 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
43839- __FILE__,__LINE__,tty->driver->name, info->port.count);
43840+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
43841
43842 /* If port is closing, signal caller to try again */
43843 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43844@@ -3422,10 +3422,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
43845 spin_unlock_irqrestore(&info->netlock, flags);
43846 goto cleanup;
43847 }
43848- info->port.count++;
43849+ atomic_inc(&info->port.count);
43850 spin_unlock_irqrestore(&info->netlock, flags);
43851
43852- if (info->port.count == 1) {
43853+ if (atomic_read(&info->port.count) == 1) {
43854 /* 1st open on this device, init hardware */
43855 retval = startup(info);
43856 if (retval < 0)
43857@@ -3449,8 +3449,8 @@ cleanup:
43858 if (retval) {
43859 if (tty->count == 1)
43860 info->port.tty = NULL; /* tty layer will release tty struct */
43861- if(info->port.count)
43862- info->port.count--;
43863+ if (atomic_read(&info->port.count))
43864+ atomic_dec(&info->port.count);
43865 }
43866
43867 return retval;
43868@@ -7668,7 +7668,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43869 unsigned short new_crctype;
43870
43871 /* return error if TTY interface open */
43872- if (info->port.count)
43873+ if (atomic_read(&info->port.count))
43874 return -EBUSY;
43875
43876 switch (encoding)
43877@@ -7763,7 +7763,7 @@ static int hdlcdev_open(struct net_device *dev)
43878
43879 /* arbitrate between network and tty opens */
43880 spin_lock_irqsave(&info->netlock, flags);
43881- if (info->port.count != 0 || info->netcount != 0) {
43882+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43883 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
43884 spin_unlock_irqrestore(&info->netlock, flags);
43885 return -EBUSY;
43886@@ -7849,7 +7849,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43887 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
43888
43889 /* return error if TTY interface open */
43890- if (info->port.count)
43891+ if (atomic_read(&info->port.count))
43892 return -EBUSY;
43893
43894 if (cmd != SIOCWANDEV)
43895diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
43896index aa9eece..d8baaec 100644
43897--- a/drivers/tty/synclink_gt.c
43898+++ b/drivers/tty/synclink_gt.c
43899@@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
43900 tty->driver_data = info;
43901 info->port.tty = tty;
43902
43903- DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
43904+ DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
43905
43906 /* If port is closing, signal caller to try again */
43907 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
43908@@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
43909 mutex_unlock(&info->port.mutex);
43910 goto cleanup;
43911 }
43912- info->port.count++;
43913+ atomic_inc(&info->port.count);
43914 spin_unlock_irqrestore(&info->netlock, flags);
43915
43916- if (info->port.count == 1) {
43917+ if (atomic_read(&info->port.count) == 1) {
43918 /* 1st open on this device, init hardware */
43919 retval = startup(info);
43920 if (retval < 0) {
43921@@ -715,8 +715,8 @@ cleanup:
43922 if (retval) {
43923 if (tty->count == 1)
43924 info->port.tty = NULL; /* tty layer will release tty struct */
43925- if(info->port.count)
43926- info->port.count--;
43927+ if(atomic_read(&info->port.count))
43928+ atomic_dec(&info->port.count);
43929 }
43930
43931 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
43932@@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43933
43934 if (sanity_check(info, tty->name, "close"))
43935 return;
43936- DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
43937+ DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
43938
43939 if (tty_port_close_start(&info->port, tty, filp) == 0)
43940 goto cleanup;
43941@@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
43942 tty_port_close_end(&info->port, tty);
43943 info->port.tty = NULL;
43944 cleanup:
43945- DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
43946+ DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
43947 }
43948
43949 static void hangup(struct tty_struct *tty)
43950@@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
43951 shutdown(info);
43952
43953 spin_lock_irqsave(&info->port.lock, flags);
43954- info->port.count = 0;
43955+ atomic_set(&info->port.count, 0);
43956 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
43957 info->port.tty = NULL;
43958 spin_unlock_irqrestore(&info->port.lock, flags);
43959@@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
43960 unsigned short new_crctype;
43961
43962 /* return error if TTY interface open */
43963- if (info->port.count)
43964+ if (atomic_read(&info->port.count))
43965 return -EBUSY;
43966
43967 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
43968@@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
43969
43970 /* arbitrate between network and tty opens */
43971 spin_lock_irqsave(&info->netlock, flags);
43972- if (info->port.count != 0 || info->netcount != 0) {
43973+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
43974 DBGINFO(("%s hdlc_open busy\n", dev->name));
43975 spin_unlock_irqrestore(&info->netlock, flags);
43976 return -EBUSY;
43977@@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
43978 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
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 if (cmd != SIOCWANDEV)
43986@@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
43987 if (port == NULL)
43988 continue;
43989 spin_lock(&port->lock);
43990- if ((port->port.count || port->netcount) &&
43991+ if ((atomic_read(&port->port.count) || port->netcount) &&
43992 port->pending_bh && !port->bh_running &&
43993 !port->bh_requested) {
43994 DBGISR(("%s bh queued\n", port->device_name));
43995@@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
43996 spin_lock_irqsave(&info->lock, flags);
43997 if (!tty_hung_up_p(filp)) {
43998 extra_count = true;
43999- port->count--;
44000+ atomic_dec(&port->count);
44001 }
44002 spin_unlock_irqrestore(&info->lock, flags);
44003 port->blocked_open++;
44004@@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44005 remove_wait_queue(&port->open_wait, &wait);
44006
44007 if (extra_count)
44008- port->count++;
44009+ atomic_inc(&port->count);
44010 port->blocked_open--;
44011
44012 if (!retval)
44013diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
44014index 6d5780c..aa4d8cd 100644
44015--- a/drivers/tty/synclinkmp.c
44016+++ b/drivers/tty/synclinkmp.c
44017@@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
44018
44019 if (debug_level >= DEBUG_LEVEL_INFO)
44020 printk("%s(%d):%s open(), old ref count = %d\n",
44021- __FILE__,__LINE__,tty->driver->name, info->port.count);
44022+ __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
44023
44024 /* If port is closing, signal caller to try again */
44025 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
44026@@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
44027 spin_unlock_irqrestore(&info->netlock, flags);
44028 goto cleanup;
44029 }
44030- info->port.count++;
44031+ atomic_inc(&info->port.count);
44032 spin_unlock_irqrestore(&info->netlock, flags);
44033
44034- if (info->port.count == 1) {
44035+ if (atomic_read(&info->port.count) == 1) {
44036 /* 1st open on this device, init hardware */
44037 retval = startup(info);
44038 if (retval < 0)
44039@@ -796,8 +796,8 @@ cleanup:
44040 if (retval) {
44041 if (tty->count == 1)
44042 info->port.tty = NULL; /* tty layer will release tty struct */
44043- if(info->port.count)
44044- info->port.count--;
44045+ if(atomic_read(&info->port.count))
44046+ atomic_dec(&info->port.count);
44047 }
44048
44049 return retval;
44050@@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44051
44052 if (debug_level >= DEBUG_LEVEL_INFO)
44053 printk("%s(%d):%s close() entry, count=%d\n",
44054- __FILE__,__LINE__, info->device_name, info->port.count);
44055+ __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
44056
44057 if (tty_port_close_start(&info->port, tty, filp) == 0)
44058 goto cleanup;
44059@@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
44060 cleanup:
44061 if (debug_level >= DEBUG_LEVEL_INFO)
44062 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
44063- tty->driver->name, info->port.count);
44064+ tty->driver->name, atomic_read(&info->port.count));
44065 }
44066
44067 /* Called by tty_hangup() when a hangup is signaled.
44068@@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
44069 shutdown(info);
44070
44071 spin_lock_irqsave(&info->port.lock, flags);
44072- info->port.count = 0;
44073+ atomic_set(&info->port.count, 0);
44074 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
44075 info->port.tty = NULL;
44076 spin_unlock_irqrestore(&info->port.lock, flags);
44077@@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
44078 unsigned short new_crctype;
44079
44080 /* return error if TTY interface open */
44081- if (info->port.count)
44082+ if (atomic_read(&info->port.count))
44083 return -EBUSY;
44084
44085 switch (encoding)
44086@@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
44087
44088 /* arbitrate between network and tty opens */
44089 spin_lock_irqsave(&info->netlock, flags);
44090- if (info->port.count != 0 || info->netcount != 0) {
44091+ if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
44092 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
44093 spin_unlock_irqrestore(&info->netlock, flags);
44094 return -EBUSY;
44095@@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
44096 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
44097
44098 /* return error if TTY interface open */
44099- if (info->port.count)
44100+ if (atomic_read(&info->port.count))
44101 return -EBUSY;
44102
44103 if (cmd != SIOCWANDEV)
44104@@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
44105 * do not request bottom half processing if the
44106 * device is not open in a normal mode.
44107 */
44108- if ( port && (port->port.count || port->netcount) &&
44109+ if ( port && (atomic_read(&port->port.count) || port->netcount) &&
44110 port->pending_bh && !port->bh_running &&
44111 !port->bh_requested ) {
44112 if ( debug_level >= DEBUG_LEVEL_ISR )
44113@@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44114
44115 if (debug_level >= DEBUG_LEVEL_INFO)
44116 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
44117- __FILE__,__LINE__, tty->driver->name, port->count );
44118+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44119
44120 spin_lock_irqsave(&info->lock, flags);
44121 if (!tty_hung_up_p(filp)) {
44122 extra_count = true;
44123- port->count--;
44124+ atomic_dec(&port->count);
44125 }
44126 spin_unlock_irqrestore(&info->lock, flags);
44127 port->blocked_open++;
44128@@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44129
44130 if (debug_level >= DEBUG_LEVEL_INFO)
44131 printk("%s(%d):%s block_til_ready() count=%d\n",
44132- __FILE__,__LINE__, tty->driver->name, port->count );
44133+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44134
44135 tty_unlock(tty);
44136 schedule();
44137@@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
44138 remove_wait_queue(&port->open_wait, &wait);
44139
44140 if (extra_count)
44141- port->count++;
44142+ atomic_inc(&port->count);
44143 port->blocked_open--;
44144
44145 if (debug_level >= DEBUG_LEVEL_INFO)
44146 printk("%s(%d):%s block_til_ready() after, count=%d\n",
44147- __FILE__,__LINE__, tty->driver->name, port->count );
44148+ __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
44149
44150 if (!retval)
44151 port->flags |= ASYNC_NORMAL_ACTIVE;
44152diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
44153index 3687f0c..6b9b808 100644
44154--- a/drivers/tty/sysrq.c
44155+++ b/drivers/tty/sysrq.c
44156@@ -995,7 +995,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
44157 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
44158 size_t count, loff_t *ppos)
44159 {
44160- if (count) {
44161+ if (count && capable(CAP_SYS_ADMIN)) {
44162 char c;
44163
44164 if (get_user(c, buf))
44165diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
44166index a9cd0b9..47b9336 100644
44167--- a/drivers/tty/tty_io.c
44168+++ b/drivers/tty/tty_io.c
44169@@ -3398,7 +3398,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
44170
44171 void tty_default_fops(struct file_operations *fops)
44172 {
44173- *fops = tty_fops;
44174+ memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
44175 }
44176
44177 /*
44178diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
44179index d794087..e4f49e5 100644
44180--- a/drivers/tty/tty_ldisc.c
44181+++ b/drivers/tty/tty_ldisc.c
44182@@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
44183 if (atomic_dec_and_test(&ld->users)) {
44184 struct tty_ldisc_ops *ldo = ld->ops;
44185
44186- ldo->refcount--;
44187+ atomic_dec(&ldo->refcount);
44188 module_put(ldo->owner);
44189 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44190
44191@@ -93,7 +93,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
44192 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44193 tty_ldiscs[disc] = new_ldisc;
44194 new_ldisc->num = disc;
44195- new_ldisc->refcount = 0;
44196+ atomic_set(&new_ldisc->refcount, 0);
44197 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44198
44199 return ret;
44200@@ -121,7 +121,7 @@ int tty_unregister_ldisc(int disc)
44201 return -EINVAL;
44202
44203 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44204- if (tty_ldiscs[disc]->refcount)
44205+ if (atomic_read(&tty_ldiscs[disc]->refcount))
44206 ret = -EBUSY;
44207 else
44208 tty_ldiscs[disc] = NULL;
44209@@ -142,7 +142,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
44210 if (ldops) {
44211 ret = ERR_PTR(-EAGAIN);
44212 if (try_module_get(ldops->owner)) {
44213- ldops->refcount++;
44214+ atomic_inc(&ldops->refcount);
44215 ret = ldops;
44216 }
44217 }
44218@@ -155,7 +155,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
44219 unsigned long flags;
44220
44221 raw_spin_lock_irqsave(&tty_ldisc_lock, flags);
44222- ldops->refcount--;
44223+ atomic_dec(&ldops->refcount);
44224 module_put(ldops->owner);
44225 raw_spin_unlock_irqrestore(&tty_ldisc_lock, flags);
44226 }
44227diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
44228index b7ff59d..7c6105e 100644
44229--- a/drivers/tty/tty_port.c
44230+++ b/drivers/tty/tty_port.c
44231@@ -218,7 +218,7 @@ void tty_port_hangup(struct tty_port *port)
44232 unsigned long flags;
44233
44234 spin_lock_irqsave(&port->lock, flags);
44235- port->count = 0;
44236+ atomic_set(&port->count, 0);
44237 port->flags &= ~ASYNC_NORMAL_ACTIVE;
44238 if (port->tty) {
44239 set_bit(TTY_IO_ERROR, &port->tty->flags);
44240@@ -344,7 +344,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44241 /* The port lock protects the port counts */
44242 spin_lock_irqsave(&port->lock, flags);
44243 if (!tty_hung_up_p(filp))
44244- port->count--;
44245+ atomic_dec(&port->count);
44246 port->blocked_open++;
44247 spin_unlock_irqrestore(&port->lock, flags);
44248
44249@@ -386,7 +386,7 @@ int tty_port_block_til_ready(struct tty_port *port,
44250 we must not mess that up further */
44251 spin_lock_irqsave(&port->lock, flags);
44252 if (!tty_hung_up_p(filp))
44253- port->count++;
44254+ atomic_inc(&port->count);
44255 port->blocked_open--;
44256 if (retval == 0)
44257 port->flags |= ASYNC_NORMAL_ACTIVE;
44258@@ -406,19 +406,19 @@ int tty_port_close_start(struct tty_port *port,
44259 return 0;
44260 }
44261
44262- if (tty->count == 1 && port->count != 1) {
44263+ if (tty->count == 1 && atomic_read(&port->count) != 1) {
44264 printk(KERN_WARNING
44265 "tty_port_close_start: tty->count = 1 port count = %d.\n",
44266- port->count);
44267- port->count = 1;
44268+ atomic_read(&port->count));
44269+ atomic_set(&port->count, 1);
44270 }
44271- if (--port->count < 0) {
44272+ if (atomic_dec_return(&port->count) < 0) {
44273 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
44274- port->count);
44275- port->count = 0;
44276+ atomic_read(&port->count));
44277+ atomic_set(&port->count, 0);
44278 }
44279
44280- if (port->count) {
44281+ if (atomic_read(&port->count)) {
44282 spin_unlock_irqrestore(&port->lock, flags);
44283 if (port->ops->drop)
44284 port->ops->drop(port);
44285@@ -516,7 +516,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
44286 {
44287 spin_lock_irq(&port->lock);
44288 if (!tty_hung_up_p(filp))
44289- ++port->count;
44290+ atomic_inc(&port->count);
44291 spin_unlock_irq(&port->lock);
44292 tty_port_tty_set(port, tty);
44293
44294diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
44295index a9af1b9a..1e08e7f 100644
44296--- a/drivers/tty/vt/keyboard.c
44297+++ b/drivers/tty/vt/keyboard.c
44298@@ -647,6 +647,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
44299 kbd->kbdmode == VC_OFF) &&
44300 value != KVAL(K_SAK))
44301 return; /* SAK is allowed even in raw mode */
44302+
44303+#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
44304+ {
44305+ void *func = fn_handler[value];
44306+ if (func == fn_show_state || func == fn_show_ptregs ||
44307+ func == fn_show_mem)
44308+ return;
44309+ }
44310+#endif
44311+
44312 fn_handler[value](vc);
44313 }
44314
44315@@ -1795,9 +1805,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44316 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
44317 return -EFAULT;
44318
44319- if (!capable(CAP_SYS_TTY_CONFIG))
44320- perm = 0;
44321-
44322 switch (cmd) {
44323 case KDGKBENT:
44324 /* Ensure another thread doesn't free it under us */
44325@@ -1812,6 +1819,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
44326 spin_unlock_irqrestore(&kbd_event_lock, flags);
44327 return put_user(val, &user_kbe->kb_value);
44328 case KDSKBENT:
44329+ if (!capable(CAP_SYS_TTY_CONFIG))
44330+ perm = 0;
44331+
44332 if (!perm)
44333 return -EPERM;
44334 if (!i && v == K_NOSUCHMAP) {
44335@@ -1902,9 +1912,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44336 int i, j, k;
44337 int ret;
44338
44339- if (!capable(CAP_SYS_TTY_CONFIG))
44340- perm = 0;
44341-
44342 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
44343 if (!kbs) {
44344 ret = -ENOMEM;
44345@@ -1938,6 +1945,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
44346 kfree(kbs);
44347 return ((p && *p) ? -EOVERFLOW : 0);
44348 case KDSKBSENT:
44349+ if (!capable(CAP_SYS_TTY_CONFIG))
44350+ perm = 0;
44351+
44352 if (!perm) {
44353 ret = -EPERM;
44354 goto reterr;
44355diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
44356index b645c47..a55c182 100644
44357--- a/drivers/uio/uio.c
44358+++ b/drivers/uio/uio.c
44359@@ -25,6 +25,7 @@
44360 #include <linux/kobject.h>
44361 #include <linux/cdev.h>
44362 #include <linux/uio_driver.h>
44363+#include <asm/local.h>
44364
44365 #define UIO_MAX_DEVICES (1U << MINORBITS)
44366
44367@@ -32,10 +33,10 @@ struct uio_device {
44368 struct module *owner;
44369 struct device *dev;
44370 int minor;
44371- atomic_t event;
44372+ atomic_unchecked_t event;
44373 struct fasync_struct *async_queue;
44374 wait_queue_head_t wait;
44375- int vma_count;
44376+ local_t vma_count;
44377 struct uio_info *info;
44378 struct kobject *map_dir;
44379 struct kobject *portio_dir;
44380@@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
44381 struct device_attribute *attr, char *buf)
44382 {
44383 struct uio_device *idev = dev_get_drvdata(dev);
44384- return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
44385+ return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
44386 }
44387
44388 static struct device_attribute uio_class_attributes[] = {
44389@@ -398,7 +399,7 @@ void uio_event_notify(struct uio_info *info)
44390 {
44391 struct uio_device *idev = info->uio_dev;
44392
44393- atomic_inc(&idev->event);
44394+ atomic_inc_unchecked(&idev->event);
44395 wake_up_interruptible(&idev->wait);
44396 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
44397 }
44398@@ -451,7 +452,7 @@ static int uio_open(struct inode *inode, struct file *filep)
44399 }
44400
44401 listener->dev = idev;
44402- listener->event_count = atomic_read(&idev->event);
44403+ listener->event_count = atomic_read_unchecked(&idev->event);
44404 filep->private_data = listener;
44405
44406 if (idev->info->open) {
44407@@ -502,7 +503,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
44408 return -EIO;
44409
44410 poll_wait(filep, &idev->wait, wait);
44411- if (listener->event_count != atomic_read(&idev->event))
44412+ if (listener->event_count != atomic_read_unchecked(&idev->event))
44413 return POLLIN | POLLRDNORM;
44414 return 0;
44415 }
44416@@ -527,7 +528,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
44417 do {
44418 set_current_state(TASK_INTERRUPTIBLE);
44419
44420- event_count = atomic_read(&idev->event);
44421+ event_count = atomic_read_unchecked(&idev->event);
44422 if (event_count != listener->event_count) {
44423 if (copy_to_user(buf, &event_count, count))
44424 retval = -EFAULT;
44425@@ -596,13 +597,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
44426 static void uio_vma_open(struct vm_area_struct *vma)
44427 {
44428 struct uio_device *idev = vma->vm_private_data;
44429- idev->vma_count++;
44430+ local_inc(&idev->vma_count);
44431 }
44432
44433 static void uio_vma_close(struct vm_area_struct *vma)
44434 {
44435 struct uio_device *idev = vma->vm_private_data;
44436- idev->vma_count--;
44437+ local_dec(&idev->vma_count);
44438 }
44439
44440 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
44441@@ -809,7 +810,7 @@ int __uio_register_device(struct module *owner,
44442 idev->owner = owner;
44443 idev->info = info;
44444 init_waitqueue_head(&idev->wait);
44445- atomic_set(&idev->event, 0);
44446+ atomic_set_unchecked(&idev->event, 0);
44447
44448 ret = uio_get_minor(idev);
44449 if (ret)
44450diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
44451index 8a7eb77..c00402f 100644
44452--- a/drivers/usb/atm/cxacru.c
44453+++ b/drivers/usb/atm/cxacru.c
44454@@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
44455 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
44456 if (ret < 2)
44457 return -EINVAL;
44458- if (index < 0 || index > 0x7f)
44459+ if (index > 0x7f)
44460 return -EINVAL;
44461 pos += tmp;
44462
44463diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
44464index 35f10bf..6a38a0b 100644
44465--- a/drivers/usb/atm/usbatm.c
44466+++ b/drivers/usb/atm/usbatm.c
44467@@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44468 if (printk_ratelimit())
44469 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
44470 __func__, vpi, vci);
44471- atomic_inc(&vcc->stats->rx_err);
44472+ atomic_inc_unchecked(&vcc->stats->rx_err);
44473 return;
44474 }
44475
44476@@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44477 if (length > ATM_MAX_AAL5_PDU) {
44478 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
44479 __func__, length, vcc);
44480- atomic_inc(&vcc->stats->rx_err);
44481+ atomic_inc_unchecked(&vcc->stats->rx_err);
44482 goto out;
44483 }
44484
44485@@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44486 if (sarb->len < pdu_length) {
44487 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
44488 __func__, pdu_length, sarb->len, vcc);
44489- atomic_inc(&vcc->stats->rx_err);
44490+ atomic_inc_unchecked(&vcc->stats->rx_err);
44491 goto out;
44492 }
44493
44494 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
44495 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
44496 __func__, vcc);
44497- atomic_inc(&vcc->stats->rx_err);
44498+ atomic_inc_unchecked(&vcc->stats->rx_err);
44499 goto out;
44500 }
44501
44502@@ -389,7 +389,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44503 if (printk_ratelimit())
44504 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
44505 __func__, length);
44506- atomic_inc(&vcc->stats->rx_drop);
44507+ atomic_inc_unchecked(&vcc->stats->rx_drop);
44508 goto out;
44509 }
44510
44511@@ -417,7 +417,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
44512
44513 vcc->push(vcc, skb);
44514
44515- atomic_inc(&vcc->stats->rx);
44516+ atomic_inc_unchecked(&vcc->stats->rx);
44517 out:
44518 skb_trim(sarb, 0);
44519 }
44520@@ -623,7 +623,7 @@ static void usbatm_tx_process(unsigned long data)
44521 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
44522
44523 usbatm_pop(vcc, skb);
44524- atomic_inc(&vcc->stats->tx);
44525+ atomic_inc_unchecked(&vcc->stats->tx);
44526
44527 skb = skb_dequeue(&instance->sndqueue);
44528 }
44529@@ -779,11 +779,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
44530 if (!left--)
44531 return sprintf(page,
44532 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
44533- atomic_read(&atm_dev->stats.aal5.tx),
44534- atomic_read(&atm_dev->stats.aal5.tx_err),
44535- atomic_read(&atm_dev->stats.aal5.rx),
44536- atomic_read(&atm_dev->stats.aal5.rx_err),
44537- atomic_read(&atm_dev->stats.aal5.rx_drop));
44538+ atomic_read_unchecked(&atm_dev->stats.aal5.tx),
44539+ atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
44540+ atomic_read_unchecked(&atm_dev->stats.aal5.rx),
44541+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
44542+ atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
44543
44544 if (!left--) {
44545 if (instance->disconnected)
44546diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
44547index 2a3bbdf..91d72cf 100644
44548--- a/drivers/usb/core/devices.c
44549+++ b/drivers/usb/core/devices.c
44550@@ -126,7 +126,7 @@ static const char format_endpt[] =
44551 * time it gets called.
44552 */
44553 static struct device_connect_event {
44554- atomic_t count;
44555+ atomic_unchecked_t count;
44556 wait_queue_head_t wait;
44557 } device_event = {
44558 .count = ATOMIC_INIT(1),
44559@@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
44560
44561 void usbfs_conn_disc_event(void)
44562 {
44563- atomic_add(2, &device_event.count);
44564+ atomic_add_unchecked(2, &device_event.count);
44565 wake_up(&device_event.wait);
44566 }
44567
44568@@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
44569
44570 poll_wait(file, &device_event.wait, wait);
44571
44572- event_count = atomic_read(&device_event.count);
44573+ event_count = atomic_read_unchecked(&device_event.count);
44574 if (file->f_version != event_count) {
44575 file->f_version = event_count;
44576 return POLLIN | POLLRDNORM;
44577diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
44578index f9ec44c..eb5779f 100644
44579--- a/drivers/usb/core/hcd.c
44580+++ b/drivers/usb/core/hcd.c
44581@@ -1526,7 +1526,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44582 */
44583 usb_get_urb(urb);
44584 atomic_inc(&urb->use_count);
44585- atomic_inc(&urb->dev->urbnum);
44586+ atomic_inc_unchecked(&urb->dev->urbnum);
44587 usbmon_urb_submit(&hcd->self, urb);
44588
44589 /* NOTE requirements on root-hub callers (usbfs and the hub
44590@@ -1553,7 +1553,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
44591 urb->hcpriv = NULL;
44592 INIT_LIST_HEAD(&urb->urb_list);
44593 atomic_dec(&urb->use_count);
44594- atomic_dec(&urb->dev->urbnum);
44595+ atomic_dec_unchecked(&urb->dev->urbnum);
44596 if (atomic_read(&urb->reject))
44597 wake_up(&usb_kill_urb_queue);
44598 usb_put_urb(urb);
44599diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
44600index 444d30e..f15c850 100644
44601--- a/drivers/usb/core/message.c
44602+++ b/drivers/usb/core/message.c
44603@@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
44604 * method can wait for it to complete. Since you don't have a handle on the
44605 * URB used, you can't cancel the request.
44606 */
44607-int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44608+int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
44609 __u8 requesttype, __u16 value, __u16 index, void *data,
44610 __u16 size, int timeout)
44611 {
44612diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
44613index 3f81a3d..a3aa993 100644
44614--- a/drivers/usb/core/sysfs.c
44615+++ b/drivers/usb/core/sysfs.c
44616@@ -239,7 +239,7 @@ show_urbnum(struct device *dev, struct device_attribute *attr, char *buf)
44617 struct usb_device *udev;
44618
44619 udev = to_usb_device(dev);
44620- return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
44621+ return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
44622 }
44623 static DEVICE_ATTR(urbnum, S_IRUGO, show_urbnum, NULL);
44624
44625diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
44626index f81b925..78d22ec 100644
44627--- a/drivers/usb/core/usb.c
44628+++ b/drivers/usb/core/usb.c
44629@@ -388,7 +388,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
44630 set_dev_node(&dev->dev, dev_to_node(bus->controller));
44631 dev->state = USB_STATE_ATTACHED;
44632 dev->lpm_disable_count = 1;
44633- atomic_set(&dev->urbnum, 0);
44634+ atomic_set_unchecked(&dev->urbnum, 0);
44635
44636 INIT_LIST_HEAD(&dev->ep0.urb_list);
44637 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
44638diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
44639index 5e29dde..eca992f 100644
44640--- a/drivers/usb/early/ehci-dbgp.c
44641+++ b/drivers/usb/early/ehci-dbgp.c
44642@@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
44643
44644 #ifdef CONFIG_KGDB
44645 static struct kgdb_io kgdbdbgp_io_ops;
44646-#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
44647+static struct kgdb_io kgdbdbgp_io_ops_console;
44648+#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
44649 #else
44650 #define dbgp_kgdb_mode (0)
44651 #endif
44652@@ -1047,6 +1048,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
44653 .write_char = kgdbdbgp_write_char,
44654 };
44655
44656+static struct kgdb_io kgdbdbgp_io_ops_console = {
44657+ .name = "kgdbdbgp",
44658+ .read_char = kgdbdbgp_read_char,
44659+ .write_char = kgdbdbgp_write_char,
44660+ .is_console = 1
44661+};
44662+
44663 static int kgdbdbgp_wait_time;
44664
44665 static int __init kgdbdbgp_parse_config(char *str)
44666@@ -1062,8 +1070,10 @@ static int __init kgdbdbgp_parse_config(char *str)
44667 ptr++;
44668 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
44669 }
44670- kgdb_register_io_module(&kgdbdbgp_io_ops);
44671- kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
44672+ if (early_dbgp_console.index != -1)
44673+ kgdb_register_io_module(&kgdbdbgp_io_ops_console);
44674+ else
44675+ kgdb_register_io_module(&kgdbdbgp_io_ops);
44676
44677 return 0;
44678 }
44679diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
44680index b369292..9f3ba40 100644
44681--- a/drivers/usb/gadget/u_serial.c
44682+++ b/drivers/usb/gadget/u_serial.c
44683@@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44684 spin_lock_irq(&port->port_lock);
44685
44686 /* already open? Great. */
44687- if (port->port.count) {
44688+ if (atomic_read(&port->port.count)) {
44689 status = 0;
44690- port->port.count++;
44691+ atomic_inc(&port->port.count);
44692
44693 /* currently opening/closing? wait ... */
44694 } else if (port->openclose) {
44695@@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
44696 tty->driver_data = port;
44697 port->port.tty = tty;
44698
44699- port->port.count = 1;
44700+ atomic_set(&port->port.count, 1);
44701 port->openclose = false;
44702
44703 /* if connected, start the I/O stream */
44704@@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44705
44706 spin_lock_irq(&port->port_lock);
44707
44708- if (port->port.count != 1) {
44709- if (port->port.count == 0)
44710+ if (atomic_read(&port->port.count) != 1) {
44711+ if (atomic_read(&port->port.count) == 0)
44712 WARN_ON(1);
44713 else
44714- --port->port.count;
44715+ atomic_dec(&port->port.count);
44716 goto exit;
44717 }
44718
44719@@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
44720 * and sleep if necessary
44721 */
44722 port->openclose = true;
44723- port->port.count = 0;
44724+ atomic_set(&port->port.count, 0);
44725
44726 gser = port->port_usb;
44727 if (gser && gser->disconnect)
44728@@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
44729 int cond;
44730
44731 spin_lock_irq(&port->port_lock);
44732- cond = (port->port.count == 0) && !port->openclose;
44733+ cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
44734 spin_unlock_irq(&port->port_lock);
44735 return cond;
44736 }
44737@@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
44738 /* if it's already open, start I/O ... and notify the serial
44739 * protocol about open/close status (connect/disconnect).
44740 */
44741- if (port->port.count) {
44742+ if (atomic_read(&port->port.count)) {
44743 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
44744 gs_start_io(port);
44745 if (gser->connect)
44746@@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
44747
44748 port->port_usb = NULL;
44749 gser->ioport = NULL;
44750- if (port->port.count > 0 || port->openclose) {
44751+ if (atomic_read(&port->port.count) > 0 || port->openclose) {
44752 wake_up_interruptible(&port->drain_wait);
44753 if (port->port.tty)
44754 tty_hangup(port->port.tty);
44755@@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
44756
44757 /* finally, free any unused/unusable I/O buffers */
44758 spin_lock_irqsave(&port->port_lock, flags);
44759- if (port->port.count == 0 && !port->openclose)
44760+ if (atomic_read(&port->port.count) == 0 && !port->openclose)
44761 gs_buf_free(&port->port_write_buf);
44762 gs_free_requests(gser->out, &port->read_pool, NULL);
44763 gs_free_requests(gser->out, &port->read_queue, NULL);
44764diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
44765index 5f3bcd3..bfca43f 100644
44766--- a/drivers/usb/serial/console.c
44767+++ b/drivers/usb/serial/console.c
44768@@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
44769
44770 info->port = port;
44771
44772- ++port->port.count;
44773+ atomic_inc(&port->port.count);
44774 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
44775 if (serial->type->set_termios) {
44776 /*
44777@@ -174,7 +174,7 @@ static int usb_console_setup(struct console *co, char *options)
44778 }
44779 /* Now that any required fake tty operations are completed restore
44780 * the tty port count */
44781- --port->port.count;
44782+ atomic_dec(&port->port.count);
44783 /* The console is special in terms of closing the device so
44784 * indicate this port is now acting as a system console. */
44785 port->port.console = 1;
44786@@ -187,7 +187,7 @@ static int usb_console_setup(struct console *co, char *options)
44787 free_tty:
44788 kfree(tty);
44789 reset_open_count:
44790- port->port.count = 0;
44791+ atomic_set(&port->port.count, 0);
44792 usb_autopm_put_interface(serial->interface);
44793 error_get_interface:
44794 usb_serial_put(serial);
44795diff --git a/drivers/usb/storage/realtek_cr.c b/drivers/usb/storage/realtek_cr.c
44796index 6c3586a..a94e621 100644
44797--- a/drivers/usb/storage/realtek_cr.c
44798+++ b/drivers/usb/storage/realtek_cr.c
44799@@ -429,7 +429,7 @@ static int rts51x_read_status(struct us_data *us,
44800
44801 buf = kmalloc(len, GFP_NOIO);
44802 if (buf == NULL)
44803- return USB_STOR_TRANSPORT_ERROR;
44804+ return -ENOMEM;
44805
44806 US_DEBUGP("%s, lun = %d\n", __func__, lun);
44807
44808diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
44809index 75f70f0..d467e1a 100644
44810--- a/drivers/usb/storage/usb.h
44811+++ b/drivers/usb/storage/usb.h
44812@@ -63,7 +63,7 @@ struct us_unusual_dev {
44813 __u8 useProtocol;
44814 __u8 useTransport;
44815 int (*initFunction)(struct us_data *);
44816-};
44817+} __do_const;
44818
44819
44820 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
44821diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
44822index d6bea3e..60b250e 100644
44823--- a/drivers/usb/wusbcore/wa-hc.h
44824+++ b/drivers/usb/wusbcore/wa-hc.h
44825@@ -192,7 +192,7 @@ struct wahc {
44826 struct list_head xfer_delayed_list;
44827 spinlock_t xfer_list_lock;
44828 struct work_struct xfer_work;
44829- atomic_t xfer_id_count;
44830+ atomic_unchecked_t xfer_id_count;
44831 };
44832
44833
44834@@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
44835 INIT_LIST_HEAD(&wa->xfer_delayed_list);
44836 spin_lock_init(&wa->xfer_list_lock);
44837 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
44838- atomic_set(&wa->xfer_id_count, 1);
44839+ atomic_set_unchecked(&wa->xfer_id_count, 1);
44840 }
44841
44842 /**
44843diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
44844index 6ef94bc..1b41265 100644
44845--- a/drivers/usb/wusbcore/wa-xfer.c
44846+++ b/drivers/usb/wusbcore/wa-xfer.c
44847@@ -296,7 +296,7 @@ out:
44848 */
44849 static void wa_xfer_id_init(struct wa_xfer *xfer)
44850 {
44851- xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
44852+ xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
44853 }
44854
44855 /*
44856diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
44857index 8c55011..eed4ae1a 100644
44858--- a/drivers/video/aty/aty128fb.c
44859+++ b/drivers/video/aty/aty128fb.c
44860@@ -149,7 +149,7 @@ enum {
44861 };
44862
44863 /* Must match above enum */
44864-static char * const r128_family[] = {
44865+static const char * const r128_family[] = {
44866 "AGP",
44867 "PCI",
44868 "PRO AGP",
44869diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
44870index 4f27fdc..d3537e6 100644
44871--- a/drivers/video/aty/atyfb_base.c
44872+++ b/drivers/video/aty/atyfb_base.c
44873@@ -1325,10 +1325,14 @@ static int atyfb_set_par(struct fb_info *info)
44874 par->accel_flags = var->accel_flags; /* hack */
44875
44876 if (var->accel_flags) {
44877- info->fbops->fb_sync = atyfb_sync;
44878+ pax_open_kernel();
44879+ *(void **)&info->fbops->fb_sync = atyfb_sync;
44880+ pax_close_kernel();
44881 info->flags &= ~FBINFO_HWACCEL_DISABLED;
44882 } else {
44883- info->fbops->fb_sync = NULL;
44884+ pax_open_kernel();
44885+ *(void **)&info->fbops->fb_sync = NULL;
44886+ pax_close_kernel();
44887 info->flags |= FBINFO_HWACCEL_DISABLED;
44888 }
44889
44890diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
44891index 95ec042..e6affdd 100644
44892--- a/drivers/video/aty/mach64_cursor.c
44893+++ b/drivers/video/aty/mach64_cursor.c
44894@@ -7,6 +7,7 @@
44895 #include <linux/string.h>
44896
44897 #include <asm/io.h>
44898+#include <asm/pgtable.h>
44899
44900 #ifdef __sparc__
44901 #include <asm/fbio.h>
44902@@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
44903 info->sprite.buf_align = 16; /* and 64 lines tall. */
44904 info->sprite.flags = FB_PIXMAP_IO;
44905
44906- info->fbops->fb_cursor = atyfb_cursor;
44907+ pax_open_kernel();
44908+ *(void **)&info->fbops->fb_cursor = atyfb_cursor;
44909+ pax_close_kernel();
44910
44911 return 0;
44912 }
44913diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
44914index 6c5ed6b..b727c88 100644
44915--- a/drivers/video/backlight/kb3886_bl.c
44916+++ b/drivers/video/backlight/kb3886_bl.c
44917@@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
44918 static unsigned long kb3886bl_flags;
44919 #define KB3886BL_SUSPENDED 0x01
44920
44921-static struct dmi_system_id __initdata kb3886bl_device_table[] = {
44922+static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
44923 {
44924 .ident = "Sahara Touch-iT",
44925 .matches = {
44926diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
44927index 900aa4e..6d49418 100644
44928--- a/drivers/video/fb_defio.c
44929+++ b/drivers/video/fb_defio.c
44930@@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
44931
44932 BUG_ON(!fbdefio);
44933 mutex_init(&fbdefio->lock);
44934- info->fbops->fb_mmap = fb_deferred_io_mmap;
44935+ pax_open_kernel();
44936+ *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
44937+ pax_close_kernel();
44938 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
44939 INIT_LIST_HEAD(&fbdefio->pagelist);
44940 if (fbdefio->delay == 0) /* set a default of 1 s */
44941@@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
44942 page->mapping = NULL;
44943 }
44944
44945- info->fbops->fb_mmap = NULL;
44946+ *(void **)&info->fbops->fb_mmap = NULL;
44947 mutex_destroy(&fbdefio->lock);
44948 }
44949 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
44950diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
44951index 5c3960d..15cf8fc 100644
44952--- a/drivers/video/fbcmap.c
44953+++ b/drivers/video/fbcmap.c
44954@@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
44955 rc = -ENODEV;
44956 goto out;
44957 }
44958- if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
44959- !info->fbops->fb_setcmap)) {
44960+ if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
44961 rc = -EINVAL;
44962 goto out1;
44963 }
44964diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
44965index 86291dc..7cc5962 100644
44966--- a/drivers/video/fbmem.c
44967+++ b/drivers/video/fbmem.c
44968@@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44969 image->dx += image->width + 8;
44970 }
44971 } else if (rotate == FB_ROTATE_UD) {
44972- for (x = 0; x < num && image->dx >= 0; x++) {
44973+ for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
44974 info->fbops->fb_imageblit(info, image);
44975 image->dx -= image->width + 8;
44976 }
44977@@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
44978 image->dy += image->height + 8;
44979 }
44980 } else if (rotate == FB_ROTATE_CCW) {
44981- for (x = 0; x < num && image->dy >= 0; x++) {
44982+ for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
44983 info->fbops->fb_imageblit(info, image);
44984 image->dy -= image->height + 8;
44985 }
44986@@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
44987 return -EFAULT;
44988 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
44989 return -EINVAL;
44990- if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
44991+ if (con2fb.framebuffer >= FB_MAX)
44992 return -EINVAL;
44993 if (!registered_fb[con2fb.framebuffer])
44994 request_module("fb%d", con2fb.framebuffer);
44995diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
44996index 7672d2e..b56437f 100644
44997--- a/drivers/video/i810/i810_accel.c
44998+++ b/drivers/video/i810/i810_accel.c
44999@@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
45000 }
45001 }
45002 printk("ringbuffer lockup!!!\n");
45003+ printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
45004 i810_report_error(mmio);
45005 par->dev_flags |= LOCKUP;
45006 info->pixmap.scan_align = 1;
45007diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
45008index 3c14e43..eafa544 100644
45009--- a/drivers/video/logo/logo_linux_clut224.ppm
45010+++ b/drivers/video/logo/logo_linux_clut224.ppm
45011@@ -1,1604 +1,1123 @@
45012 P3
45013-# Standard 224-color Linux logo
45014 80 80
45015 255
45016- 0 0 0 0 0 0 0 0 0 0 0 0
45017- 0 0 0 0 0 0 0 0 0 0 0 0
45018- 0 0 0 0 0 0 0 0 0 0 0 0
45019- 0 0 0 0 0 0 0 0 0 0 0 0
45020- 0 0 0 0 0 0 0 0 0 0 0 0
45021- 0 0 0 0 0 0 0 0 0 0 0 0
45022- 0 0 0 0 0 0 0 0 0 0 0 0
45023- 0 0 0 0 0 0 0 0 0 0 0 0
45024- 0 0 0 0 0 0 0 0 0 0 0 0
45025- 6 6 6 6 6 6 10 10 10 10 10 10
45026- 10 10 10 6 6 6 6 6 6 6 6 6
45027- 0 0 0 0 0 0 0 0 0 0 0 0
45028- 0 0 0 0 0 0 0 0 0 0 0 0
45029- 0 0 0 0 0 0 0 0 0 0 0 0
45030- 0 0 0 0 0 0 0 0 0 0 0 0
45031- 0 0 0 0 0 0 0 0 0 0 0 0
45032- 0 0 0 0 0 0 0 0 0 0 0 0
45033- 0 0 0 0 0 0 0 0 0 0 0 0
45034- 0 0 0 0 0 0 0 0 0 0 0 0
45035- 0 0 0 0 0 0 0 0 0 0 0 0
45036- 0 0 0 0 0 0 0 0 0 0 0 0
45037- 0 0 0 0 0 0 0 0 0 0 0 0
45038- 0 0 0 0 0 0 0 0 0 0 0 0
45039- 0 0 0 0 0 0 0 0 0 0 0 0
45040- 0 0 0 0 0 0 0 0 0 0 0 0
45041- 0 0 0 0 0 0 0 0 0 0 0 0
45042- 0 0 0 0 0 0 0 0 0 0 0 0
45043- 0 0 0 0 0 0 0 0 0 0 0 0
45044- 0 0 0 6 6 6 10 10 10 14 14 14
45045- 22 22 22 26 26 26 30 30 30 34 34 34
45046- 30 30 30 30 30 30 26 26 26 18 18 18
45047- 14 14 14 10 10 10 6 6 6 0 0 0
45048- 0 0 0 0 0 0 0 0 0 0 0 0
45049- 0 0 0 0 0 0 0 0 0 0 0 0
45050- 0 0 0 0 0 0 0 0 0 0 0 0
45051- 0 0 0 0 0 0 0 0 0 0 0 0
45052- 0 0 0 0 0 0 0 0 0 0 0 0
45053- 0 0 0 0 0 0 0 0 0 0 0 0
45054- 0 0 0 0 0 0 0 0 0 0 0 0
45055- 0 0 0 0 0 0 0 0 0 0 0 0
45056- 0 0 0 0 0 0 0 0 0 0 0 0
45057- 0 0 0 0 0 1 0 0 1 0 0 0
45058- 0 0 0 0 0 0 0 0 0 0 0 0
45059- 0 0 0 0 0 0 0 0 0 0 0 0
45060- 0 0 0 0 0 0 0 0 0 0 0 0
45061- 0 0 0 0 0 0 0 0 0 0 0 0
45062- 0 0 0 0 0 0 0 0 0 0 0 0
45063- 0 0 0 0 0 0 0 0 0 0 0 0
45064- 6 6 6 14 14 14 26 26 26 42 42 42
45065- 54 54 54 66 66 66 78 78 78 78 78 78
45066- 78 78 78 74 74 74 66 66 66 54 54 54
45067- 42 42 42 26 26 26 18 18 18 10 10 10
45068- 6 6 6 0 0 0 0 0 0 0 0 0
45069- 0 0 0 0 0 0 0 0 0 0 0 0
45070- 0 0 0 0 0 0 0 0 0 0 0 0
45071- 0 0 0 0 0 0 0 0 0 0 0 0
45072- 0 0 0 0 0 0 0 0 0 0 0 0
45073- 0 0 0 0 0 0 0 0 0 0 0 0
45074- 0 0 0 0 0 0 0 0 0 0 0 0
45075- 0 0 0 0 0 0 0 0 0 0 0 0
45076- 0 0 0 0 0 0 0 0 0 0 0 0
45077- 0 0 1 0 0 0 0 0 0 0 0 0
45078- 0 0 0 0 0 0 0 0 0 0 0 0
45079- 0 0 0 0 0 0 0 0 0 0 0 0
45080- 0 0 0 0 0 0 0 0 0 0 0 0
45081- 0 0 0 0 0 0 0 0 0 0 0 0
45082- 0 0 0 0 0 0 0 0 0 0 0 0
45083- 0 0 0 0 0 0 0 0 0 10 10 10
45084- 22 22 22 42 42 42 66 66 66 86 86 86
45085- 66 66 66 38 38 38 38 38 38 22 22 22
45086- 26 26 26 34 34 34 54 54 54 66 66 66
45087- 86 86 86 70 70 70 46 46 46 26 26 26
45088- 14 14 14 6 6 6 0 0 0 0 0 0
45089- 0 0 0 0 0 0 0 0 0 0 0 0
45090- 0 0 0 0 0 0 0 0 0 0 0 0
45091- 0 0 0 0 0 0 0 0 0 0 0 0
45092- 0 0 0 0 0 0 0 0 0 0 0 0
45093- 0 0 0 0 0 0 0 0 0 0 0 0
45094- 0 0 0 0 0 0 0 0 0 0 0 0
45095- 0 0 0 0 0 0 0 0 0 0 0 0
45096- 0 0 0 0 0 0 0 0 0 0 0 0
45097- 0 0 1 0 0 1 0 0 1 0 0 0
45098- 0 0 0 0 0 0 0 0 0 0 0 0
45099- 0 0 0 0 0 0 0 0 0 0 0 0
45100- 0 0 0 0 0 0 0 0 0 0 0 0
45101- 0 0 0 0 0 0 0 0 0 0 0 0
45102- 0 0 0 0 0 0 0 0 0 0 0 0
45103- 0 0 0 0 0 0 10 10 10 26 26 26
45104- 50 50 50 82 82 82 58 58 58 6 6 6
45105- 2 2 6 2 2 6 2 2 6 2 2 6
45106- 2 2 6 2 2 6 2 2 6 2 2 6
45107- 6 6 6 54 54 54 86 86 86 66 66 66
45108- 38 38 38 18 18 18 6 6 6 0 0 0
45109- 0 0 0 0 0 0 0 0 0 0 0 0
45110- 0 0 0 0 0 0 0 0 0 0 0 0
45111- 0 0 0 0 0 0 0 0 0 0 0 0
45112- 0 0 0 0 0 0 0 0 0 0 0 0
45113- 0 0 0 0 0 0 0 0 0 0 0 0
45114- 0 0 0 0 0 0 0 0 0 0 0 0
45115- 0 0 0 0 0 0 0 0 0 0 0 0
45116- 0 0 0 0 0 0 0 0 0 0 0 0
45117- 0 0 0 0 0 0 0 0 0 0 0 0
45118- 0 0 0 0 0 0 0 0 0 0 0 0
45119- 0 0 0 0 0 0 0 0 0 0 0 0
45120- 0 0 0 0 0 0 0 0 0 0 0 0
45121- 0 0 0 0 0 0 0 0 0 0 0 0
45122- 0 0 0 0 0 0 0 0 0 0 0 0
45123- 0 0 0 6 6 6 22 22 22 50 50 50
45124- 78 78 78 34 34 34 2 2 6 2 2 6
45125- 2 2 6 2 2 6 2 2 6 2 2 6
45126- 2 2 6 2 2 6 2 2 6 2 2 6
45127- 2 2 6 2 2 6 6 6 6 70 70 70
45128- 78 78 78 46 46 46 22 22 22 6 6 6
45129- 0 0 0 0 0 0 0 0 0 0 0 0
45130- 0 0 0 0 0 0 0 0 0 0 0 0
45131- 0 0 0 0 0 0 0 0 0 0 0 0
45132- 0 0 0 0 0 0 0 0 0 0 0 0
45133- 0 0 0 0 0 0 0 0 0 0 0 0
45134- 0 0 0 0 0 0 0 0 0 0 0 0
45135- 0 0 0 0 0 0 0 0 0 0 0 0
45136- 0 0 0 0 0 0 0 0 0 0 0 0
45137- 0 0 1 0 0 1 0 0 1 0 0 0
45138- 0 0 0 0 0 0 0 0 0 0 0 0
45139- 0 0 0 0 0 0 0 0 0 0 0 0
45140- 0 0 0 0 0 0 0 0 0 0 0 0
45141- 0 0 0 0 0 0 0 0 0 0 0 0
45142- 0 0 0 0 0 0 0 0 0 0 0 0
45143- 6 6 6 18 18 18 42 42 42 82 82 82
45144- 26 26 26 2 2 6 2 2 6 2 2 6
45145- 2 2 6 2 2 6 2 2 6 2 2 6
45146- 2 2 6 2 2 6 2 2 6 14 14 14
45147- 46 46 46 34 34 34 6 6 6 2 2 6
45148- 42 42 42 78 78 78 42 42 42 18 18 18
45149- 6 6 6 0 0 0 0 0 0 0 0 0
45150- 0 0 0 0 0 0 0 0 0 0 0 0
45151- 0 0 0 0 0 0 0 0 0 0 0 0
45152- 0 0 0 0 0 0 0 0 0 0 0 0
45153- 0 0 0 0 0 0 0 0 0 0 0 0
45154- 0 0 0 0 0 0 0 0 0 0 0 0
45155- 0 0 0 0 0 0 0 0 0 0 0 0
45156- 0 0 0 0 0 0 0 0 0 0 0 0
45157- 0 0 1 0 0 0 0 0 1 0 0 0
45158- 0 0 0 0 0 0 0 0 0 0 0 0
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- 10 10 10 30 30 30 66 66 66 58 58 58
45164- 2 2 6 2 2 6 2 2 6 2 2 6
45165- 2 2 6 2 2 6 2 2 6 2 2 6
45166- 2 2 6 2 2 6 2 2 6 26 26 26
45167- 86 86 86 101 101 101 46 46 46 10 10 10
45168- 2 2 6 58 58 58 70 70 70 34 34 34
45169- 10 10 10 0 0 0 0 0 0 0 0 0
45170- 0 0 0 0 0 0 0 0 0 0 0 0
45171- 0 0 0 0 0 0 0 0 0 0 0 0
45172- 0 0 0 0 0 0 0 0 0 0 0 0
45173- 0 0 0 0 0 0 0 0 0 0 0 0
45174- 0 0 0 0 0 0 0 0 0 0 0 0
45175- 0 0 0 0 0 0 0 0 0 0 0 0
45176- 0 0 0 0 0 0 0 0 0 0 0 0
45177- 0 0 1 0 0 1 0 0 1 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- 14 14 14 42 42 42 86 86 86 10 10 10
45184- 2 2 6 2 2 6 2 2 6 2 2 6
45185- 2 2 6 2 2 6 2 2 6 2 2 6
45186- 2 2 6 2 2 6 2 2 6 30 30 30
45187- 94 94 94 94 94 94 58 58 58 26 26 26
45188- 2 2 6 6 6 6 78 78 78 54 54 54
45189- 22 22 22 6 6 6 0 0 0 0 0 0
45190- 0 0 0 0 0 0 0 0 0 0 0 0
45191- 0 0 0 0 0 0 0 0 0 0 0 0
45192- 0 0 0 0 0 0 0 0 0 0 0 0
45193- 0 0 0 0 0 0 0 0 0 0 0 0
45194- 0 0 0 0 0 0 0 0 0 0 0 0
45195- 0 0 0 0 0 0 0 0 0 0 0 0
45196- 0 0 0 0 0 0 0 0 0 0 0 0
45197- 0 0 0 0 0 0 0 0 0 0 0 0
45198- 0 0 0 0 0 0 0 0 0 0 0 0
45199- 0 0 0 0 0 0 0 0 0 0 0 0
45200- 0 0 0 0 0 0 0 0 0 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 6 6 6
45203- 22 22 22 62 62 62 62 62 62 2 2 6
45204- 2 2 6 2 2 6 2 2 6 2 2 6
45205- 2 2 6 2 2 6 2 2 6 2 2 6
45206- 2 2 6 2 2 6 2 2 6 26 26 26
45207- 54 54 54 38 38 38 18 18 18 10 10 10
45208- 2 2 6 2 2 6 34 34 34 82 82 82
45209- 38 38 38 14 14 14 0 0 0 0 0 0
45210- 0 0 0 0 0 0 0 0 0 0 0 0
45211- 0 0 0 0 0 0 0 0 0 0 0 0
45212- 0 0 0 0 0 0 0 0 0 0 0 0
45213- 0 0 0 0 0 0 0 0 0 0 0 0
45214- 0 0 0 0 0 0 0 0 0 0 0 0
45215- 0 0 0 0 0 0 0 0 0 0 0 0
45216- 0 0 0 0 0 0 0 0 0 0 0 0
45217- 0 0 0 0 0 1 0 0 1 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 0 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 6 6 6
45223- 30 30 30 78 78 78 30 30 30 2 2 6
45224- 2 2 6 2 2 6 2 2 6 2 2 6
45225- 2 2 6 2 2 6 2 2 6 2 2 6
45226- 2 2 6 2 2 6 2 2 6 10 10 10
45227- 10 10 10 2 2 6 2 2 6 2 2 6
45228- 2 2 6 2 2 6 2 2 6 78 78 78
45229- 50 50 50 18 18 18 6 6 6 0 0 0
45230- 0 0 0 0 0 0 0 0 0 0 0 0
45231- 0 0 0 0 0 0 0 0 0 0 0 0
45232- 0 0 0 0 0 0 0 0 0 0 0 0
45233- 0 0 0 0 0 0 0 0 0 0 0 0
45234- 0 0 0 0 0 0 0 0 0 0 0 0
45235- 0 0 0 0 0 0 0 0 0 0 0 0
45236- 0 0 0 0 0 0 0 0 0 0 0 0
45237- 0 0 1 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 0 0 0 0 0 0 0 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 10 10 10
45243- 38 38 38 86 86 86 14 14 14 2 2 6
45244- 2 2 6 2 2 6 2 2 6 2 2 6
45245- 2 2 6 2 2 6 2 2 6 2 2 6
45246- 2 2 6 2 2 6 2 2 6 2 2 6
45247- 2 2 6 2 2 6 2 2 6 2 2 6
45248- 2 2 6 2 2 6 2 2 6 54 54 54
45249- 66 66 66 26 26 26 6 6 6 0 0 0
45250- 0 0 0 0 0 0 0 0 0 0 0 0
45251- 0 0 0 0 0 0 0 0 0 0 0 0
45252- 0 0 0 0 0 0 0 0 0 0 0 0
45253- 0 0 0 0 0 0 0 0 0 0 0 0
45254- 0 0 0 0 0 0 0 0 0 0 0 0
45255- 0 0 0 0 0 0 0 0 0 0 0 0
45256- 0 0 0 0 0 0 0 0 0 0 0 0
45257- 0 0 0 0 0 1 0 0 1 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 14 14 14
45263- 42 42 42 82 82 82 2 2 6 2 2 6
45264- 2 2 6 6 6 6 10 10 10 2 2 6
45265- 2 2 6 2 2 6 2 2 6 2 2 6
45266- 2 2 6 2 2 6 2 2 6 6 6 6
45267- 14 14 14 10 10 10 2 2 6 2 2 6
45268- 2 2 6 2 2 6 2 2 6 18 18 18
45269- 82 82 82 34 34 34 10 10 10 0 0 0
45270- 0 0 0 0 0 0 0 0 0 0 0 0
45271- 0 0 0 0 0 0 0 0 0 0 0 0
45272- 0 0 0 0 0 0 0 0 0 0 0 0
45273- 0 0 0 0 0 0 0 0 0 0 0 0
45274- 0 0 0 0 0 0 0 0 0 0 0 0
45275- 0 0 0 0 0 0 0 0 0 0 0 0
45276- 0 0 0 0 0 0 0 0 0 0 0 0
45277- 0 0 1 0 0 0 0 0 0 0 0 0
45278- 0 0 0 0 0 0 0 0 0 0 0 0
45279- 0 0 0 0 0 0 0 0 0 0 0 0
45280- 0 0 0 0 0 0 0 0 0 0 0 0
45281- 0 0 0 0 0 0 0 0 0 0 0 0
45282- 0 0 0 0 0 0 0 0 0 14 14 14
45283- 46 46 46 86 86 86 2 2 6 2 2 6
45284- 6 6 6 6 6 6 22 22 22 34 34 34
45285- 6 6 6 2 2 6 2 2 6 2 2 6
45286- 2 2 6 2 2 6 18 18 18 34 34 34
45287- 10 10 10 50 50 50 22 22 22 2 2 6
45288- 2 2 6 2 2 6 2 2 6 10 10 10
45289- 86 86 86 42 42 42 14 14 14 0 0 0
45290- 0 0 0 0 0 0 0 0 0 0 0 0
45291- 0 0 0 0 0 0 0 0 0 0 0 0
45292- 0 0 0 0 0 0 0 0 0 0 0 0
45293- 0 0 0 0 0 0 0 0 0 0 0 0
45294- 0 0 0 0 0 0 0 0 0 0 0 0
45295- 0 0 0 0 0 0 0 0 0 0 0 0
45296- 0 0 0 0 0 0 0 0 0 0 0 0
45297- 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
45301- 0 0 0 0 0 0 0 0 0 0 0 0
45302- 0 0 0 0 0 0 0 0 0 14 14 14
45303- 46 46 46 86 86 86 2 2 6 2 2 6
45304- 38 38 38 116 116 116 94 94 94 22 22 22
45305- 22 22 22 2 2 6 2 2 6 2 2 6
45306- 14 14 14 86 86 86 138 138 138 162 162 162
45307-154 154 154 38 38 38 26 26 26 6 6 6
45308- 2 2 6 2 2 6 2 2 6 2 2 6
45309- 86 86 86 46 46 46 14 14 14 0 0 0
45310- 0 0 0 0 0 0 0 0 0 0 0 0
45311- 0 0 0 0 0 0 0 0 0 0 0 0
45312- 0 0 0 0 0 0 0 0 0 0 0 0
45313- 0 0 0 0 0 0 0 0 0 0 0 0
45314- 0 0 0 0 0 0 0 0 0 0 0 0
45315- 0 0 0 0 0 0 0 0 0 0 0 0
45316- 0 0 0 0 0 0 0 0 0 0 0 0
45317- 0 0 0 0 0 0 0 0 0 0 0 0
45318- 0 0 0 0 0 0 0 0 0 0 0 0
45319- 0 0 0 0 0 0 0 0 0 0 0 0
45320- 0 0 0 0 0 0 0 0 0 0 0 0
45321- 0 0 0 0 0 0 0 0 0 0 0 0
45322- 0 0 0 0 0 0 0 0 0 14 14 14
45323- 46 46 46 86 86 86 2 2 6 14 14 14
45324-134 134 134 198 198 198 195 195 195 116 116 116
45325- 10 10 10 2 2 6 2 2 6 6 6 6
45326-101 98 89 187 187 187 210 210 210 218 218 218
45327-214 214 214 134 134 134 14 14 14 6 6 6
45328- 2 2 6 2 2 6 2 2 6 2 2 6
45329- 86 86 86 50 50 50 18 18 18 6 6 6
45330- 0 0 0 0 0 0 0 0 0 0 0 0
45331- 0 0 0 0 0 0 0 0 0 0 0 0
45332- 0 0 0 0 0 0 0 0 0 0 0 0
45333- 0 0 0 0 0 0 0 0 0 0 0 0
45334- 0 0 0 0 0 0 0 0 0 0 0 0
45335- 0 0 0 0 0 0 0 0 0 0 0 0
45336- 0 0 0 0 0 0 0 0 1 0 0 0
45337- 0 0 1 0 0 1 0 0 1 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 14 14 14
45343- 46 46 46 86 86 86 2 2 6 54 54 54
45344-218 218 218 195 195 195 226 226 226 246 246 246
45345- 58 58 58 2 2 6 2 2 6 30 30 30
45346-210 210 210 253 253 253 174 174 174 123 123 123
45347-221 221 221 234 234 234 74 74 74 2 2 6
45348- 2 2 6 2 2 6 2 2 6 2 2 6
45349- 70 70 70 58 58 58 22 22 22 6 6 6
45350- 0 0 0 0 0 0 0 0 0 0 0 0
45351- 0 0 0 0 0 0 0 0 0 0 0 0
45352- 0 0 0 0 0 0 0 0 0 0 0 0
45353- 0 0 0 0 0 0 0 0 0 0 0 0
45354- 0 0 0 0 0 0 0 0 0 0 0 0
45355- 0 0 0 0 0 0 0 0 0 0 0 0
45356- 0 0 0 0 0 0 0 0 0 0 0 0
45357- 0 0 0 0 0 0 0 0 0 0 0 0
45358- 0 0 0 0 0 0 0 0 0 0 0 0
45359- 0 0 0 0 0 0 0 0 0 0 0 0
45360- 0 0 0 0 0 0 0 0 0 0 0 0
45361- 0 0 0 0 0 0 0 0 0 0 0 0
45362- 0 0 0 0 0 0 0 0 0 14 14 14
45363- 46 46 46 82 82 82 2 2 6 106 106 106
45364-170 170 170 26 26 26 86 86 86 226 226 226
45365-123 123 123 10 10 10 14 14 14 46 46 46
45366-231 231 231 190 190 190 6 6 6 70 70 70
45367- 90 90 90 238 238 238 158 158 158 2 2 6
45368- 2 2 6 2 2 6 2 2 6 2 2 6
45369- 70 70 70 58 58 58 22 22 22 6 6 6
45370- 0 0 0 0 0 0 0 0 0 0 0 0
45371- 0 0 0 0 0 0 0 0 0 0 0 0
45372- 0 0 0 0 0 0 0 0 0 0 0 0
45373- 0 0 0 0 0 0 0 0 0 0 0 0
45374- 0 0 0 0 0 0 0 0 0 0 0 0
45375- 0 0 0 0 0 0 0 0 0 0 0 0
45376- 0 0 0 0 0 0 0 0 1 0 0 0
45377- 0 0 1 0 0 1 0 0 1 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 0 0 0 0 0 0 0 0 0 0
45381- 0 0 0 0 0 0 0 0 0 0 0 0
45382- 0 0 0 0 0 0 0 0 0 14 14 14
45383- 42 42 42 86 86 86 6 6 6 116 116 116
45384-106 106 106 6 6 6 70 70 70 149 149 149
45385-128 128 128 18 18 18 38 38 38 54 54 54
45386-221 221 221 106 106 106 2 2 6 14 14 14
45387- 46 46 46 190 190 190 198 198 198 2 2 6
45388- 2 2 6 2 2 6 2 2 6 2 2 6
45389- 74 74 74 62 62 62 22 22 22 6 6 6
45390- 0 0 0 0 0 0 0 0 0 0 0 0
45391- 0 0 0 0 0 0 0 0 0 0 0 0
45392- 0 0 0 0 0 0 0 0 0 0 0 0
45393- 0 0 0 0 0 0 0 0 0 0 0 0
45394- 0 0 0 0 0 0 0 0 0 0 0 0
45395- 0 0 0 0 0 0 0 0 0 0 0 0
45396- 0 0 0 0 0 0 0 0 1 0 0 0
45397- 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0
45401- 0 0 0 0 0 0 0 0 0 0 0 0
45402- 0 0 0 0 0 0 0 0 0 14 14 14
45403- 42 42 42 94 94 94 14 14 14 101 101 101
45404-128 128 128 2 2 6 18 18 18 116 116 116
45405-118 98 46 121 92 8 121 92 8 98 78 10
45406-162 162 162 106 106 106 2 2 6 2 2 6
45407- 2 2 6 195 195 195 195 195 195 6 6 6
45408- 2 2 6 2 2 6 2 2 6 2 2 6
45409- 74 74 74 62 62 62 22 22 22 6 6 6
45410- 0 0 0 0 0 0 0 0 0 0 0 0
45411- 0 0 0 0 0 0 0 0 0 0 0 0
45412- 0 0 0 0 0 0 0 0 0 0 0 0
45413- 0 0 0 0 0 0 0 0 0 0 0 0
45414- 0 0 0 0 0 0 0 0 0 0 0 0
45415- 0 0 0 0 0 0 0 0 0 0 0 0
45416- 0 0 0 0 0 0 0 0 1 0 0 1
45417- 0 0 1 0 0 0 0 0 1 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 0 0 0 0 0 0 0 0 0 0
45421- 0 0 0 0 0 0 0 0 0 0 0 0
45422- 0 0 0 0 0 0 0 0 0 10 10 10
45423- 38 38 38 90 90 90 14 14 14 58 58 58
45424-210 210 210 26 26 26 54 38 6 154 114 10
45425-226 170 11 236 186 11 225 175 15 184 144 12
45426-215 174 15 175 146 61 37 26 9 2 2 6
45427- 70 70 70 246 246 246 138 138 138 2 2 6
45428- 2 2 6 2 2 6 2 2 6 2 2 6
45429- 70 70 70 66 66 66 26 26 26 6 6 6
45430- 0 0 0 0 0 0 0 0 0 0 0 0
45431- 0 0 0 0 0 0 0 0 0 0 0 0
45432- 0 0 0 0 0 0 0 0 0 0 0 0
45433- 0 0 0 0 0 0 0 0 0 0 0 0
45434- 0 0 0 0 0 0 0 0 0 0 0 0
45435- 0 0 0 0 0 0 0 0 0 0 0 0
45436- 0 0 0 0 0 0 0 0 0 0 0 0
45437- 0 0 0 0 0 0 0 0 0 0 0 0
45438- 0 0 0 0 0 0 0 0 0 0 0 0
45439- 0 0 0 0 0 0 0 0 0 0 0 0
45440- 0 0 0 0 0 0 0 0 0 0 0 0
45441- 0 0 0 0 0 0 0 0 0 0 0 0
45442- 0 0 0 0 0 0 0 0 0 10 10 10
45443- 38 38 38 86 86 86 14 14 14 10 10 10
45444-195 195 195 188 164 115 192 133 9 225 175 15
45445-239 182 13 234 190 10 232 195 16 232 200 30
45446-245 207 45 241 208 19 232 195 16 184 144 12
45447-218 194 134 211 206 186 42 42 42 2 2 6
45448- 2 2 6 2 2 6 2 2 6 2 2 6
45449- 50 50 50 74 74 74 30 30 30 6 6 6
45450- 0 0 0 0 0 0 0 0 0 0 0 0
45451- 0 0 0 0 0 0 0 0 0 0 0 0
45452- 0 0 0 0 0 0 0 0 0 0 0 0
45453- 0 0 0 0 0 0 0 0 0 0 0 0
45454- 0 0 0 0 0 0 0 0 0 0 0 0
45455- 0 0 0 0 0 0 0 0 0 0 0 0
45456- 0 0 0 0 0 0 0 0 0 0 0 0
45457- 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 10 10 10
45463- 34 34 34 86 86 86 14 14 14 2 2 6
45464-121 87 25 192 133 9 219 162 10 239 182 13
45465-236 186 11 232 195 16 241 208 19 244 214 54
45466-246 218 60 246 218 38 246 215 20 241 208 19
45467-241 208 19 226 184 13 121 87 25 2 2 6
45468- 2 2 6 2 2 6 2 2 6 2 2 6
45469- 50 50 50 82 82 82 34 34 34 10 10 10
45470- 0 0 0 0 0 0 0 0 0 0 0 0
45471- 0 0 0 0 0 0 0 0 0 0 0 0
45472- 0 0 0 0 0 0 0 0 0 0 0 0
45473- 0 0 0 0 0 0 0 0 0 0 0 0
45474- 0 0 0 0 0 0 0 0 0 0 0 0
45475- 0 0 0 0 0 0 0 0 0 0 0 0
45476- 0 0 0 0 0 0 0 0 0 0 0 0
45477- 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 0 0 0 0
45480- 0 0 0 0 0 0 0 0 0 0 0 0
45481- 0 0 0 0 0 0 0 0 0 0 0 0
45482- 0 0 0 0 0 0 0 0 0 10 10 10
45483- 34 34 34 82 82 82 30 30 30 61 42 6
45484-180 123 7 206 145 10 230 174 11 239 182 13
45485-234 190 10 238 202 15 241 208 19 246 218 74
45486-246 218 38 246 215 20 246 215 20 246 215 20
45487-226 184 13 215 174 15 184 144 12 6 6 6
45488- 2 2 6 2 2 6 2 2 6 2 2 6
45489- 26 26 26 94 94 94 42 42 42 14 14 14
45490- 0 0 0 0 0 0 0 0 0 0 0 0
45491- 0 0 0 0 0 0 0 0 0 0 0 0
45492- 0 0 0 0 0 0 0 0 0 0 0 0
45493- 0 0 0 0 0 0 0 0 0 0 0 0
45494- 0 0 0 0 0 0 0 0 0 0 0 0
45495- 0 0 0 0 0 0 0 0 0 0 0 0
45496- 0 0 0 0 0 0 0 0 0 0 0 0
45497- 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 10 10 10
45503- 30 30 30 78 78 78 50 50 50 104 69 6
45504-192 133 9 216 158 10 236 178 12 236 186 11
45505-232 195 16 241 208 19 244 214 54 245 215 43
45506-246 215 20 246 215 20 241 208 19 198 155 10
45507-200 144 11 216 158 10 156 118 10 2 2 6
45508- 2 2 6 2 2 6 2 2 6 2 2 6
45509- 6 6 6 90 90 90 54 54 54 18 18 18
45510- 6 6 6 0 0 0 0 0 0 0 0 0
45511- 0 0 0 0 0 0 0 0 0 0 0 0
45512- 0 0 0 0 0 0 0 0 0 0 0 0
45513- 0 0 0 0 0 0 0 0 0 0 0 0
45514- 0 0 0 0 0 0 0 0 0 0 0 0
45515- 0 0 0 0 0 0 0 0 0 0 0 0
45516- 0 0 0 0 0 0 0 0 0 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 0 0 0 0
45520- 0 0 0 0 0 0 0 0 0 0 0 0
45521- 0 0 0 0 0 0 0 0 0 0 0 0
45522- 0 0 0 0 0 0 0 0 0 10 10 10
45523- 30 30 30 78 78 78 46 46 46 22 22 22
45524-137 92 6 210 162 10 239 182 13 238 190 10
45525-238 202 15 241 208 19 246 215 20 246 215 20
45526-241 208 19 203 166 17 185 133 11 210 150 10
45527-216 158 10 210 150 10 102 78 10 2 2 6
45528- 6 6 6 54 54 54 14 14 14 2 2 6
45529- 2 2 6 62 62 62 74 74 74 30 30 30
45530- 10 10 10 0 0 0 0 0 0 0 0 0
45531- 0 0 0 0 0 0 0 0 0 0 0 0
45532- 0 0 0 0 0 0 0 0 0 0 0 0
45533- 0 0 0 0 0 0 0 0 0 0 0 0
45534- 0 0 0 0 0 0 0 0 0 0 0 0
45535- 0 0 0 0 0 0 0 0 0 0 0 0
45536- 0 0 0 0 0 0 0 0 0 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 0 0 0 0
45540- 0 0 0 0 0 0 0 0 0 0 0 0
45541- 0 0 0 0 0 0 0 0 0 0 0 0
45542- 0 0 0 0 0 0 0 0 0 10 10 10
45543- 34 34 34 78 78 78 50 50 50 6 6 6
45544- 94 70 30 139 102 15 190 146 13 226 184 13
45545-232 200 30 232 195 16 215 174 15 190 146 13
45546-168 122 10 192 133 9 210 150 10 213 154 11
45547-202 150 34 182 157 106 101 98 89 2 2 6
45548- 2 2 6 78 78 78 116 116 116 58 58 58
45549- 2 2 6 22 22 22 90 90 90 46 46 46
45550- 18 18 18 6 6 6 0 0 0 0 0 0
45551- 0 0 0 0 0 0 0 0 0 0 0 0
45552- 0 0 0 0 0 0 0 0 0 0 0 0
45553- 0 0 0 0 0 0 0 0 0 0 0 0
45554- 0 0 0 0 0 0 0 0 0 0 0 0
45555- 0 0 0 0 0 0 0 0 0 0 0 0
45556- 0 0 0 0 0 0 0 0 0 0 0 0
45557- 0 0 0 0 0 0 0 0 0 0 0 0
45558- 0 0 0 0 0 0 0 0 0 0 0 0
45559- 0 0 0 0 0 0 0 0 0 0 0 0
45560- 0 0 0 0 0 0 0 0 0 0 0 0
45561- 0 0 0 0 0 0 0 0 0 0 0 0
45562- 0 0 0 0 0 0 0 0 0 10 10 10
45563- 38 38 38 86 86 86 50 50 50 6 6 6
45564-128 128 128 174 154 114 156 107 11 168 122 10
45565-198 155 10 184 144 12 197 138 11 200 144 11
45566-206 145 10 206 145 10 197 138 11 188 164 115
45567-195 195 195 198 198 198 174 174 174 14 14 14
45568- 2 2 6 22 22 22 116 116 116 116 116 116
45569- 22 22 22 2 2 6 74 74 74 70 70 70
45570- 30 30 30 10 10 10 0 0 0 0 0 0
45571- 0 0 0 0 0 0 0 0 0 0 0 0
45572- 0 0 0 0 0 0 0 0 0 0 0 0
45573- 0 0 0 0 0 0 0 0 0 0 0 0
45574- 0 0 0 0 0 0 0 0 0 0 0 0
45575- 0 0 0 0 0 0 0 0 0 0 0 0
45576- 0 0 0 0 0 0 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 6 6 6 18 18 18
45583- 50 50 50 101 101 101 26 26 26 10 10 10
45584-138 138 138 190 190 190 174 154 114 156 107 11
45585-197 138 11 200 144 11 197 138 11 192 133 9
45586-180 123 7 190 142 34 190 178 144 187 187 187
45587-202 202 202 221 221 221 214 214 214 66 66 66
45588- 2 2 6 2 2 6 50 50 50 62 62 62
45589- 6 6 6 2 2 6 10 10 10 90 90 90
45590- 50 50 50 18 18 18 6 6 6 0 0 0
45591- 0 0 0 0 0 0 0 0 0 0 0 0
45592- 0 0 0 0 0 0 0 0 0 0 0 0
45593- 0 0 0 0 0 0 0 0 0 0 0 0
45594- 0 0 0 0 0 0 0 0 0 0 0 0
45595- 0 0 0 0 0 0 0 0 0 0 0 0
45596- 0 0 0 0 0 0 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 10 10 10 34 34 34
45603- 74 74 74 74 74 74 2 2 6 6 6 6
45604-144 144 144 198 198 198 190 190 190 178 166 146
45605-154 121 60 156 107 11 156 107 11 168 124 44
45606-174 154 114 187 187 187 190 190 190 210 210 210
45607-246 246 246 253 253 253 253 253 253 182 182 182
45608- 6 6 6 2 2 6 2 2 6 2 2 6
45609- 2 2 6 2 2 6 2 2 6 62 62 62
45610- 74 74 74 34 34 34 14 14 14 0 0 0
45611- 0 0 0 0 0 0 0 0 0 0 0 0
45612- 0 0 0 0 0 0 0 0 0 0 0 0
45613- 0 0 0 0 0 0 0 0 0 0 0 0
45614- 0 0 0 0 0 0 0 0 0 0 0 0
45615- 0 0 0 0 0 0 0 0 0 0 0 0
45616- 0 0 0 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 10 10 10 22 22 22 54 54 54
45623- 94 94 94 18 18 18 2 2 6 46 46 46
45624-234 234 234 221 221 221 190 190 190 190 190 190
45625-190 190 190 187 187 187 187 187 187 190 190 190
45626-190 190 190 195 195 195 214 214 214 242 242 242
45627-253 253 253 253 253 253 253 253 253 253 253 253
45628- 82 82 82 2 2 6 2 2 6 2 2 6
45629- 2 2 6 2 2 6 2 2 6 14 14 14
45630- 86 86 86 54 54 54 22 22 22 6 6 6
45631- 0 0 0 0 0 0 0 0 0 0 0 0
45632- 0 0 0 0 0 0 0 0 0 0 0 0
45633- 0 0 0 0 0 0 0 0 0 0 0 0
45634- 0 0 0 0 0 0 0 0 0 0 0 0
45635- 0 0 0 0 0 0 0 0 0 0 0 0
45636- 0 0 0 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- 6 6 6 18 18 18 46 46 46 90 90 90
45643- 46 46 46 18 18 18 6 6 6 182 182 182
45644-253 253 253 246 246 246 206 206 206 190 190 190
45645-190 190 190 190 190 190 190 190 190 190 190 190
45646-206 206 206 231 231 231 250 250 250 253 253 253
45647-253 253 253 253 253 253 253 253 253 253 253 253
45648-202 202 202 14 14 14 2 2 6 2 2 6
45649- 2 2 6 2 2 6 2 2 6 2 2 6
45650- 42 42 42 86 86 86 42 42 42 18 18 18
45651- 6 6 6 0 0 0 0 0 0 0 0 0
45652- 0 0 0 0 0 0 0 0 0 0 0 0
45653- 0 0 0 0 0 0 0 0 0 0 0 0
45654- 0 0 0 0 0 0 0 0 0 0 0 0
45655- 0 0 0 0 0 0 0 0 0 0 0 0
45656- 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 6 6 6
45662- 14 14 14 38 38 38 74 74 74 66 66 66
45663- 2 2 6 6 6 6 90 90 90 250 250 250
45664-253 253 253 253 253 253 238 238 238 198 198 198
45665-190 190 190 190 190 190 195 195 195 221 221 221
45666-246 246 246 253 253 253 253 253 253 253 253 253
45667-253 253 253 253 253 253 253 253 253 253 253 253
45668-253 253 253 82 82 82 2 2 6 2 2 6
45669- 2 2 6 2 2 6 2 2 6 2 2 6
45670- 2 2 6 78 78 78 70 70 70 34 34 34
45671- 14 14 14 6 6 6 0 0 0 0 0 0
45672- 0 0 0 0 0 0 0 0 0 0 0 0
45673- 0 0 0 0 0 0 0 0 0 0 0 0
45674- 0 0 0 0 0 0 0 0 0 0 0 0
45675- 0 0 0 0 0 0 0 0 0 0 0 0
45676- 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 14 14 14
45682- 34 34 34 66 66 66 78 78 78 6 6 6
45683- 2 2 6 18 18 18 218 218 218 253 253 253
45684-253 253 253 253 253 253 253 253 253 246 246 246
45685-226 226 226 231 231 231 246 246 246 253 253 253
45686-253 253 253 253 253 253 253 253 253 253 253 253
45687-253 253 253 253 253 253 253 253 253 253 253 253
45688-253 253 253 178 178 178 2 2 6 2 2 6
45689- 2 2 6 2 2 6 2 2 6 2 2 6
45690- 2 2 6 18 18 18 90 90 90 62 62 62
45691- 30 30 30 10 10 10 0 0 0 0 0 0
45692- 0 0 0 0 0 0 0 0 0 0 0 0
45693- 0 0 0 0 0 0 0 0 0 0 0 0
45694- 0 0 0 0 0 0 0 0 0 0 0 0
45695- 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
45702- 58 58 58 90 90 90 18 18 18 2 2 6
45703- 2 2 6 110 110 110 253 253 253 253 253 253
45704-253 253 253 253 253 253 253 253 253 253 253 253
45705-250 250 250 253 253 253 253 253 253 253 253 253
45706-253 253 253 253 253 253 253 253 253 253 253 253
45707-253 253 253 253 253 253 253 253 253 253 253 253
45708-253 253 253 231 231 231 18 18 18 2 2 6
45709- 2 2 6 2 2 6 2 2 6 2 2 6
45710- 2 2 6 2 2 6 18 18 18 94 94 94
45711- 54 54 54 26 26 26 10 10 10 0 0 0
45712- 0 0 0 0 0 0 0 0 0 0 0 0
45713- 0 0 0 0 0 0 0 0 0 0 0 0
45714- 0 0 0 0 0 0 0 0 0 0 0 0
45715- 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
45722- 90 90 90 26 26 26 2 2 6 2 2 6
45723- 14 14 14 195 195 195 250 250 250 253 253 253
45724-253 253 253 253 253 253 253 253 253 253 253 253
45725-253 253 253 253 253 253 253 253 253 253 253 253
45726-253 253 253 253 253 253 253 253 253 253 253 253
45727-253 253 253 253 253 253 253 253 253 253 253 253
45728-250 250 250 242 242 242 54 54 54 2 2 6
45729- 2 2 6 2 2 6 2 2 6 2 2 6
45730- 2 2 6 2 2 6 2 2 6 38 38 38
45731- 86 86 86 50 50 50 22 22 22 6 6 6
45732- 0 0 0 0 0 0 0 0 0 0 0 0
45733- 0 0 0 0 0 0 0 0 0 0 0 0
45734- 0 0 0 0 0 0 0 0 0 0 0 0
45735- 0 0 0 0 0 0 0 0 0 0 0 0
45736- 0 0 0 0 0 0 0 0 0 0 0 0
45737- 0 0 0 0 0 0 0 0 0 0 0 0
45738- 0 0 0 0 0 0 0 0 0 0 0 0
45739- 0 0 0 0 0 0 0 0 0 0 0 0
45740- 0 0 0 0 0 0 0 0 0 0 0 0
45741- 6 6 6 14 14 14 38 38 38 82 82 82
45742- 34 34 34 2 2 6 2 2 6 2 2 6
45743- 42 42 42 195 195 195 246 246 246 253 253 253
45744-253 253 253 253 253 253 253 253 253 250 250 250
45745-242 242 242 242 242 242 250 250 250 253 253 253
45746-253 253 253 253 253 253 253 253 253 253 253 253
45747-253 253 253 250 250 250 246 246 246 238 238 238
45748-226 226 226 231 231 231 101 101 101 6 6 6
45749- 2 2 6 2 2 6 2 2 6 2 2 6
45750- 2 2 6 2 2 6 2 2 6 2 2 6
45751- 38 38 38 82 82 82 42 42 42 14 14 14
45752- 6 6 6 0 0 0 0 0 0 0 0 0
45753- 0 0 0 0 0 0 0 0 0 0 0 0
45754- 0 0 0 0 0 0 0 0 0 0 0 0
45755- 0 0 0 0 0 0 0 0 0 0 0 0
45756- 0 0 0 0 0 0 0 0 0 0 0 0
45757- 0 0 0 0 0 0 0 0 0 0 0 0
45758- 0 0 0 0 0 0 0 0 0 0 0 0
45759- 0 0 0 0 0 0 0 0 0 0 0 0
45760- 0 0 0 0 0 0 0 0 0 0 0 0
45761- 10 10 10 26 26 26 62 62 62 66 66 66
45762- 2 2 6 2 2 6 2 2 6 6 6 6
45763- 70 70 70 170 170 170 206 206 206 234 234 234
45764-246 246 246 250 250 250 250 250 250 238 238 238
45765-226 226 226 231 231 231 238 238 238 250 250 250
45766-250 250 250 250 250 250 246 246 246 231 231 231
45767-214 214 214 206 206 206 202 202 202 202 202 202
45768-198 198 198 202 202 202 182 182 182 18 18 18
45769- 2 2 6 2 2 6 2 2 6 2 2 6
45770- 2 2 6 2 2 6 2 2 6 2 2 6
45771- 2 2 6 62 62 62 66 66 66 30 30 30
45772- 10 10 10 0 0 0 0 0 0 0 0 0
45773- 0 0 0 0 0 0 0 0 0 0 0 0
45774- 0 0 0 0 0 0 0 0 0 0 0 0
45775- 0 0 0 0 0 0 0 0 0 0 0 0
45776- 0 0 0 0 0 0 0 0 0 0 0 0
45777- 0 0 0 0 0 0 0 0 0 0 0 0
45778- 0 0 0 0 0 0 0 0 0 0 0 0
45779- 0 0 0 0 0 0 0 0 0 0 0 0
45780- 0 0 0 0 0 0 0 0 0 0 0 0
45781- 14 14 14 42 42 42 82 82 82 18 18 18
45782- 2 2 6 2 2 6 2 2 6 10 10 10
45783- 94 94 94 182 182 182 218 218 218 242 242 242
45784-250 250 250 253 253 253 253 253 253 250 250 250
45785-234 234 234 253 253 253 253 253 253 253 253 253
45786-253 253 253 253 253 253 253 253 253 246 246 246
45787-238 238 238 226 226 226 210 210 210 202 202 202
45788-195 195 195 195 195 195 210 210 210 158 158 158
45789- 6 6 6 14 14 14 50 50 50 14 14 14
45790- 2 2 6 2 2 6 2 2 6 2 2 6
45791- 2 2 6 6 6 6 86 86 86 46 46 46
45792- 18 18 18 6 6 6 0 0 0 0 0 0
45793- 0 0 0 0 0 0 0 0 0 0 0 0
45794- 0 0 0 0 0 0 0 0 0 0 0 0
45795- 0 0 0 0 0 0 0 0 0 0 0 0
45796- 0 0 0 0 0 0 0 0 0 0 0 0
45797- 0 0 0 0 0 0 0 0 0 0 0 0
45798- 0 0 0 0 0 0 0 0 0 0 0 0
45799- 0 0 0 0 0 0 0 0 0 0 0 0
45800- 0 0 0 0 0 0 0 0 0 6 6 6
45801- 22 22 22 54 54 54 70 70 70 2 2 6
45802- 2 2 6 10 10 10 2 2 6 22 22 22
45803-166 166 166 231 231 231 250 250 250 253 253 253
45804-253 253 253 253 253 253 253 253 253 250 250 250
45805-242 242 242 253 253 253 253 253 253 253 253 253
45806-253 253 253 253 253 253 253 253 253 253 253 253
45807-253 253 253 253 253 253 253 253 253 246 246 246
45808-231 231 231 206 206 206 198 198 198 226 226 226
45809- 94 94 94 2 2 6 6 6 6 38 38 38
45810- 30 30 30 2 2 6 2 2 6 2 2 6
45811- 2 2 6 2 2 6 62 62 62 66 66 66
45812- 26 26 26 10 10 10 0 0 0 0 0 0
45813- 0 0 0 0 0 0 0 0 0 0 0 0
45814- 0 0 0 0 0 0 0 0 0 0 0 0
45815- 0 0 0 0 0 0 0 0 0 0 0 0
45816- 0 0 0 0 0 0 0 0 0 0 0 0
45817- 0 0 0 0 0 0 0 0 0 0 0 0
45818- 0 0 0 0 0 0 0 0 0 0 0 0
45819- 0 0 0 0 0 0 0 0 0 0 0 0
45820- 0 0 0 0 0 0 0 0 0 10 10 10
45821- 30 30 30 74 74 74 50 50 50 2 2 6
45822- 26 26 26 26 26 26 2 2 6 106 106 106
45823-238 238 238 253 253 253 253 253 253 253 253 253
45824-253 253 253 253 253 253 253 253 253 253 253 253
45825-253 253 253 253 253 253 253 253 253 253 253 253
45826-253 253 253 253 253 253 253 253 253 253 253 253
45827-253 253 253 253 253 253 253 253 253 253 253 253
45828-253 253 253 246 246 246 218 218 218 202 202 202
45829-210 210 210 14 14 14 2 2 6 2 2 6
45830- 30 30 30 22 22 22 2 2 6 2 2 6
45831- 2 2 6 2 2 6 18 18 18 86 86 86
45832- 42 42 42 14 14 14 0 0 0 0 0 0
45833- 0 0 0 0 0 0 0 0 0 0 0 0
45834- 0 0 0 0 0 0 0 0 0 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 14 14 14
45841- 42 42 42 90 90 90 22 22 22 2 2 6
45842- 42 42 42 2 2 6 18 18 18 218 218 218
45843-253 253 253 253 253 253 253 253 253 253 253 253
45844-253 253 253 253 253 253 253 253 253 253 253 253
45845-253 253 253 253 253 253 253 253 253 253 253 253
45846-253 253 253 253 253 253 253 253 253 253 253 253
45847-253 253 253 253 253 253 253 253 253 253 253 253
45848-253 253 253 253 253 253 250 250 250 221 221 221
45849-218 218 218 101 101 101 2 2 6 14 14 14
45850- 18 18 18 38 38 38 10 10 10 2 2 6
45851- 2 2 6 2 2 6 2 2 6 78 78 78
45852- 58 58 58 22 22 22 6 6 6 0 0 0
45853- 0 0 0 0 0 0 0 0 0 0 0 0
45854- 0 0 0 0 0 0 0 0 0 0 0 0
45855- 0 0 0 0 0 0 0 0 0 0 0 0
45856- 0 0 0 0 0 0 0 0 0 0 0 0
45857- 0 0 0 0 0 0 0 0 0 0 0 0
45858- 0 0 0 0 0 0 0 0 0 0 0 0
45859- 0 0 0 0 0 0 0 0 0 0 0 0
45860- 0 0 0 0 0 0 6 6 6 18 18 18
45861- 54 54 54 82 82 82 2 2 6 26 26 26
45862- 22 22 22 2 2 6 123 123 123 253 253 253
45863-253 253 253 253 253 253 253 253 253 253 253 253
45864-253 253 253 253 253 253 253 253 253 253 253 253
45865-253 253 253 253 253 253 253 253 253 253 253 253
45866-253 253 253 253 253 253 253 253 253 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 250 250 250
45869-238 238 238 198 198 198 6 6 6 38 38 38
45870- 58 58 58 26 26 26 38 38 38 2 2 6
45871- 2 2 6 2 2 6 2 2 6 46 46 46
45872- 78 78 78 30 30 30 10 10 10 0 0 0
45873- 0 0 0 0 0 0 0 0 0 0 0 0
45874- 0 0 0 0 0 0 0 0 0 0 0 0
45875- 0 0 0 0 0 0 0 0 0 0 0 0
45876- 0 0 0 0 0 0 0 0 0 0 0 0
45877- 0 0 0 0 0 0 0 0 0 0 0 0
45878- 0 0 0 0 0 0 0 0 0 0 0 0
45879- 0 0 0 0 0 0 0 0 0 0 0 0
45880- 0 0 0 0 0 0 10 10 10 30 30 30
45881- 74 74 74 58 58 58 2 2 6 42 42 42
45882- 2 2 6 22 22 22 231 231 231 253 253 253
45883-253 253 253 253 253 253 253 253 253 253 253 253
45884-253 253 253 253 253 253 253 253 253 250 250 250
45885-253 253 253 253 253 253 253 253 253 253 253 253
45886-253 253 253 253 253 253 253 253 253 253 253 253
45887-253 253 253 253 253 253 253 253 253 253 253 253
45888-253 253 253 253 253 253 253 253 253 253 253 253
45889-253 253 253 246 246 246 46 46 46 38 38 38
45890- 42 42 42 14 14 14 38 38 38 14 14 14
45891- 2 2 6 2 2 6 2 2 6 6 6 6
45892- 86 86 86 46 46 46 14 14 14 0 0 0
45893- 0 0 0 0 0 0 0 0 0 0 0 0
45894- 0 0 0 0 0 0 0 0 0 0 0 0
45895- 0 0 0 0 0 0 0 0 0 0 0 0
45896- 0 0 0 0 0 0 0 0 0 0 0 0
45897- 0 0 0 0 0 0 0 0 0 0 0 0
45898- 0 0 0 0 0 0 0 0 0 0 0 0
45899- 0 0 0 0 0 0 0 0 0 0 0 0
45900- 0 0 0 6 6 6 14 14 14 42 42 42
45901- 90 90 90 18 18 18 18 18 18 26 26 26
45902- 2 2 6 116 116 116 253 253 253 253 253 253
45903-253 253 253 253 253 253 253 253 253 253 253 253
45904-253 253 253 253 253 253 250 250 250 238 238 238
45905-253 253 253 253 253 253 253 253 253 253 253 253
45906-253 253 253 253 253 253 253 253 253 253 253 253
45907-253 253 253 253 253 253 253 253 253 253 253 253
45908-253 253 253 253 253 253 253 253 253 253 253 253
45909-253 253 253 253 253 253 94 94 94 6 6 6
45910- 2 2 6 2 2 6 10 10 10 34 34 34
45911- 2 2 6 2 2 6 2 2 6 2 2 6
45912- 74 74 74 58 58 58 22 22 22 6 6 6
45913- 0 0 0 0 0 0 0 0 0 0 0 0
45914- 0 0 0 0 0 0 0 0 0 0 0 0
45915- 0 0 0 0 0 0 0 0 0 0 0 0
45916- 0 0 0 0 0 0 0 0 0 0 0 0
45917- 0 0 0 0 0 0 0 0 0 0 0 0
45918- 0 0 0 0 0 0 0 0 0 0 0 0
45919- 0 0 0 0 0 0 0 0 0 0 0 0
45920- 0 0 0 10 10 10 26 26 26 66 66 66
45921- 82 82 82 2 2 6 38 38 38 6 6 6
45922- 14 14 14 210 210 210 253 253 253 253 253 253
45923-253 253 253 253 253 253 253 253 253 253 253 253
45924-253 253 253 253 253 253 246 246 246 242 242 242
45925-253 253 253 253 253 253 253 253 253 253 253 253
45926-253 253 253 253 253 253 253 253 253 253 253 253
45927-253 253 253 253 253 253 253 253 253 253 253 253
45928-253 253 253 253 253 253 253 253 253 253 253 253
45929-253 253 253 253 253 253 144 144 144 2 2 6
45930- 2 2 6 2 2 6 2 2 6 46 46 46
45931- 2 2 6 2 2 6 2 2 6 2 2 6
45932- 42 42 42 74 74 74 30 30 30 10 10 10
45933- 0 0 0 0 0 0 0 0 0 0 0 0
45934- 0 0 0 0 0 0 0 0 0 0 0 0
45935- 0 0 0 0 0 0 0 0 0 0 0 0
45936- 0 0 0 0 0 0 0 0 0 0 0 0
45937- 0 0 0 0 0 0 0 0 0 0 0 0
45938- 0 0 0 0 0 0 0 0 0 0 0 0
45939- 0 0 0 0 0 0 0 0 0 0 0 0
45940- 6 6 6 14 14 14 42 42 42 90 90 90
45941- 26 26 26 6 6 6 42 42 42 2 2 6
45942- 74 74 74 250 250 250 253 253 253 253 253 253
45943-253 253 253 253 253 253 253 253 253 253 253 253
45944-253 253 253 253 253 253 242 242 242 242 242 242
45945-253 253 253 253 253 253 253 253 253 253 253 253
45946-253 253 253 253 253 253 253 253 253 253 253 253
45947-253 253 253 253 253 253 253 253 253 253 253 253
45948-253 253 253 253 253 253 253 253 253 253 253 253
45949-253 253 253 253 253 253 182 182 182 2 2 6
45950- 2 2 6 2 2 6 2 2 6 46 46 46
45951- 2 2 6 2 2 6 2 2 6 2 2 6
45952- 10 10 10 86 86 86 38 38 38 10 10 10
45953- 0 0 0 0 0 0 0 0 0 0 0 0
45954- 0 0 0 0 0 0 0 0 0 0 0 0
45955- 0 0 0 0 0 0 0 0 0 0 0 0
45956- 0 0 0 0 0 0 0 0 0 0 0 0
45957- 0 0 0 0 0 0 0 0 0 0 0 0
45958- 0 0 0 0 0 0 0 0 0 0 0 0
45959- 0 0 0 0 0 0 0 0 0 0 0 0
45960- 10 10 10 26 26 26 66 66 66 82 82 82
45961- 2 2 6 22 22 22 18 18 18 2 2 6
45962-149 149 149 253 253 253 253 253 253 253 253 253
45963-253 253 253 253 253 253 253 253 253 253 253 253
45964-253 253 253 253 253 253 234 234 234 242 242 242
45965-253 253 253 253 253 253 253 253 253 253 253 253
45966-253 253 253 253 253 253 253 253 253 253 253 253
45967-253 253 253 253 253 253 253 253 253 253 253 253
45968-253 253 253 253 253 253 253 253 253 253 253 253
45969-253 253 253 253 253 253 206 206 206 2 2 6
45970- 2 2 6 2 2 6 2 2 6 38 38 38
45971- 2 2 6 2 2 6 2 2 6 2 2 6
45972- 6 6 6 86 86 86 46 46 46 14 14 14
45973- 0 0 0 0 0 0 0 0 0 0 0 0
45974- 0 0 0 0 0 0 0 0 0 0 0 0
45975- 0 0 0 0 0 0 0 0 0 0 0 0
45976- 0 0 0 0 0 0 0 0 0 0 0 0
45977- 0 0 0 0 0 0 0 0 0 0 0 0
45978- 0 0 0 0 0 0 0 0 0 0 0 0
45979- 0 0 0 0 0 0 0 0 0 6 6 6
45980- 18 18 18 46 46 46 86 86 86 18 18 18
45981- 2 2 6 34 34 34 10 10 10 6 6 6
45982-210 210 210 253 253 253 253 253 253 253 253 253
45983-253 253 253 253 253 253 253 253 253 253 253 253
45984-253 253 253 253 253 253 234 234 234 242 242 242
45985-253 253 253 253 253 253 253 253 253 253 253 253
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 221 221 221 6 6 6
45990- 2 2 6 2 2 6 6 6 6 30 30 30
45991- 2 2 6 2 2 6 2 2 6 2 2 6
45992- 2 2 6 82 82 82 54 54 54 18 18 18
45993- 6 6 6 0 0 0 0 0 0 0 0 0
45994- 0 0 0 0 0 0 0 0 0 0 0 0
45995- 0 0 0 0 0 0 0 0 0 0 0 0
45996- 0 0 0 0 0 0 0 0 0 0 0 0
45997- 0 0 0 0 0 0 0 0 0 0 0 0
45998- 0 0 0 0 0 0 0 0 0 0 0 0
45999- 0 0 0 0 0 0 0 0 0 10 10 10
46000- 26 26 26 66 66 66 62 62 62 2 2 6
46001- 2 2 6 38 38 38 10 10 10 26 26 26
46002-238 238 238 253 253 253 253 253 253 253 253 253
46003-253 253 253 253 253 253 253 253 253 253 253 253
46004-253 253 253 253 253 253 231 231 231 238 238 238
46005-253 253 253 253 253 253 253 253 253 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 231 231 231 6 6 6
46010- 2 2 6 2 2 6 10 10 10 30 30 30
46011- 2 2 6 2 2 6 2 2 6 2 2 6
46012- 2 2 6 66 66 66 58 58 58 22 22 22
46013- 6 6 6 0 0 0 0 0 0 0 0 0
46014- 0 0 0 0 0 0 0 0 0 0 0 0
46015- 0 0 0 0 0 0 0 0 0 0 0 0
46016- 0 0 0 0 0 0 0 0 0 0 0 0
46017- 0 0 0 0 0 0 0 0 0 0 0 0
46018- 0 0 0 0 0 0 0 0 0 0 0 0
46019- 0 0 0 0 0 0 0 0 0 10 10 10
46020- 38 38 38 78 78 78 6 6 6 2 2 6
46021- 2 2 6 46 46 46 14 14 14 42 42 42
46022-246 246 246 253 253 253 253 253 253 253 253 253
46023-253 253 253 253 253 253 253 253 253 253 253 253
46024-253 253 253 253 253 253 231 231 231 242 242 242
46025-253 253 253 253 253 253 253 253 253 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 253 253 253
46028-253 253 253 253 253 253 253 253 253 253 253 253
46029-253 253 253 253 253 253 234 234 234 10 10 10
46030- 2 2 6 2 2 6 22 22 22 14 14 14
46031- 2 2 6 2 2 6 2 2 6 2 2 6
46032- 2 2 6 66 66 66 62 62 62 22 22 22
46033- 6 6 6 0 0 0 0 0 0 0 0 0
46034- 0 0 0 0 0 0 0 0 0 0 0 0
46035- 0 0 0 0 0 0 0 0 0 0 0 0
46036- 0 0 0 0 0 0 0 0 0 0 0 0
46037- 0 0 0 0 0 0 0 0 0 0 0 0
46038- 0 0 0 0 0 0 0 0 0 0 0 0
46039- 0 0 0 0 0 0 6 6 6 18 18 18
46040- 50 50 50 74 74 74 2 2 6 2 2 6
46041- 14 14 14 70 70 70 34 34 34 62 62 62
46042-250 250 250 253 253 253 253 253 253 253 253 253
46043-253 253 253 253 253 253 253 253 253 253 253 253
46044-253 253 253 253 253 253 231 231 231 246 246 246
46045-253 253 253 253 253 253 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 253 253 253 253 253 253
46048-253 253 253 253 253 253 253 253 253 253 253 253
46049-253 253 253 253 253 253 234 234 234 14 14 14
46050- 2 2 6 2 2 6 30 30 30 2 2 6
46051- 2 2 6 2 2 6 2 2 6 2 2 6
46052- 2 2 6 66 66 66 62 62 62 22 22 22
46053- 6 6 6 0 0 0 0 0 0 0 0 0
46054- 0 0 0 0 0 0 0 0 0 0 0 0
46055- 0 0 0 0 0 0 0 0 0 0 0 0
46056- 0 0 0 0 0 0 0 0 0 0 0 0
46057- 0 0 0 0 0 0 0 0 0 0 0 0
46058- 0 0 0 0 0 0 0 0 0 0 0 0
46059- 0 0 0 0 0 0 6 6 6 18 18 18
46060- 54 54 54 62 62 62 2 2 6 2 2 6
46061- 2 2 6 30 30 30 46 46 46 70 70 70
46062-250 250 250 253 253 253 253 253 253 253 253 253
46063-253 253 253 253 253 253 253 253 253 253 253 253
46064-253 253 253 253 253 253 231 231 231 246 246 246
46065-253 253 253 253 253 253 253 253 253 253 253 253
46066-253 253 253 253 253 253 253 253 253 253 253 253
46067-253 253 253 253 253 253 253 253 253 253 253 253
46068-253 253 253 253 253 253 253 253 253 253 253 253
46069-253 253 253 253 253 253 226 226 226 10 10 10
46070- 2 2 6 6 6 6 30 30 30 2 2 6
46071- 2 2 6 2 2 6 2 2 6 2 2 6
46072- 2 2 6 66 66 66 58 58 58 22 22 22
46073- 6 6 6 0 0 0 0 0 0 0 0 0
46074- 0 0 0 0 0 0 0 0 0 0 0 0
46075- 0 0 0 0 0 0 0 0 0 0 0 0
46076- 0 0 0 0 0 0 0 0 0 0 0 0
46077- 0 0 0 0 0 0 0 0 0 0 0 0
46078- 0 0 0 0 0 0 0 0 0 0 0 0
46079- 0 0 0 0 0 0 6 6 6 22 22 22
46080- 58 58 58 62 62 62 2 2 6 2 2 6
46081- 2 2 6 2 2 6 30 30 30 78 78 78
46082-250 250 250 253 253 253 253 253 253 253 253 253
46083-253 253 253 253 253 253 253 253 253 253 253 253
46084-253 253 253 253 253 253 231 231 231 246 246 246
46085-253 253 253 253 253 253 253 253 253 253 253 253
46086-253 253 253 253 253 253 253 253 253 253 253 253
46087-253 253 253 253 253 253 253 253 253 253 253 253
46088-253 253 253 253 253 253 253 253 253 253 253 253
46089-253 253 253 253 253 253 206 206 206 2 2 6
46090- 22 22 22 34 34 34 18 14 6 22 22 22
46091- 26 26 26 18 18 18 6 6 6 2 2 6
46092- 2 2 6 82 82 82 54 54 54 18 18 18
46093- 6 6 6 0 0 0 0 0 0 0 0 0
46094- 0 0 0 0 0 0 0 0 0 0 0 0
46095- 0 0 0 0 0 0 0 0 0 0 0 0
46096- 0 0 0 0 0 0 0 0 0 0 0 0
46097- 0 0 0 0 0 0 0 0 0 0 0 0
46098- 0 0 0 0 0 0 0 0 0 0 0 0
46099- 0 0 0 0 0 0 6 6 6 26 26 26
46100- 62 62 62 106 106 106 74 54 14 185 133 11
46101-210 162 10 121 92 8 6 6 6 62 62 62
46102-238 238 238 253 253 253 253 253 253 253 253 253
46103-253 253 253 253 253 253 253 253 253 253 253 253
46104-253 253 253 253 253 253 231 231 231 246 246 246
46105-253 253 253 253 253 253 253 253 253 253 253 253
46106-253 253 253 253 253 253 253 253 253 253 253 253
46107-253 253 253 253 253 253 253 253 253 253 253 253
46108-253 253 253 253 253 253 253 253 253 253 253 253
46109-253 253 253 253 253 253 158 158 158 18 18 18
46110- 14 14 14 2 2 6 2 2 6 2 2 6
46111- 6 6 6 18 18 18 66 66 66 38 38 38
46112- 6 6 6 94 94 94 50 50 50 18 18 18
46113- 6 6 6 0 0 0 0 0 0 0 0 0
46114- 0 0 0 0 0 0 0 0 0 0 0 0
46115- 0 0 0 0 0 0 0 0 0 0 0 0
46116- 0 0 0 0 0 0 0 0 0 0 0 0
46117- 0 0 0 0 0 0 0 0 0 0 0 0
46118- 0 0 0 0 0 0 0 0 0 6 6 6
46119- 10 10 10 10 10 10 18 18 18 38 38 38
46120- 78 78 78 142 134 106 216 158 10 242 186 14
46121-246 190 14 246 190 14 156 118 10 10 10 10
46122- 90 90 90 238 238 238 253 253 253 253 253 253
46123-253 253 253 253 253 253 253 253 253 253 253 253
46124-253 253 253 253 253 253 231 231 231 250 250 250
46125-253 253 253 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 253 253 253 253 253 253
46128-253 253 253 253 253 253 253 253 253 246 230 190
46129-238 204 91 238 204 91 181 142 44 37 26 9
46130- 2 2 6 2 2 6 2 2 6 2 2 6
46131- 2 2 6 2 2 6 38 38 38 46 46 46
46132- 26 26 26 106 106 106 54 54 54 18 18 18
46133- 6 6 6 0 0 0 0 0 0 0 0 0
46134- 0 0 0 0 0 0 0 0 0 0 0 0
46135- 0 0 0 0 0 0 0 0 0 0 0 0
46136- 0 0 0 0 0 0 0 0 0 0 0 0
46137- 0 0 0 0 0 0 0 0 0 0 0 0
46138- 0 0 0 6 6 6 14 14 14 22 22 22
46139- 30 30 30 38 38 38 50 50 50 70 70 70
46140-106 106 106 190 142 34 226 170 11 242 186 14
46141-246 190 14 246 190 14 246 190 14 154 114 10
46142- 6 6 6 74 74 74 226 226 226 253 253 253
46143-253 253 253 253 253 253 253 253 253 253 253 253
46144-253 253 253 253 253 253 231 231 231 250 250 250
46145-253 253 253 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 253 253 253 253 253 253
46148-253 253 253 253 253 253 253 253 253 228 184 62
46149-241 196 14 241 208 19 232 195 16 38 30 10
46150- 2 2 6 2 2 6 2 2 6 2 2 6
46151- 2 2 6 6 6 6 30 30 30 26 26 26
46152-203 166 17 154 142 90 66 66 66 26 26 26
46153- 6 6 6 0 0 0 0 0 0 0 0 0
46154- 0 0 0 0 0 0 0 0 0 0 0 0
46155- 0 0 0 0 0 0 0 0 0 0 0 0
46156- 0 0 0 0 0 0 0 0 0 0 0 0
46157- 0 0 0 0 0 0 0 0 0 0 0 0
46158- 6 6 6 18 18 18 38 38 38 58 58 58
46159- 78 78 78 86 86 86 101 101 101 123 123 123
46160-175 146 61 210 150 10 234 174 13 246 186 14
46161-246 190 14 246 190 14 246 190 14 238 190 10
46162-102 78 10 2 2 6 46 46 46 198 198 198
46163-253 253 253 253 253 253 253 253 253 253 253 253
46164-253 253 253 253 253 253 234 234 234 242 242 242
46165-253 253 253 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 253 253 253 253 253 253
46168-253 253 253 253 253 253 253 253 253 224 178 62
46169-242 186 14 241 196 14 210 166 10 22 18 6
46170- 2 2 6 2 2 6 2 2 6 2 2 6
46171- 2 2 6 2 2 6 6 6 6 121 92 8
46172-238 202 15 232 195 16 82 82 82 34 34 34
46173- 10 10 10 0 0 0 0 0 0 0 0 0
46174- 0 0 0 0 0 0 0 0 0 0 0 0
46175- 0 0 0 0 0 0 0 0 0 0 0 0
46176- 0 0 0 0 0 0 0 0 0 0 0 0
46177- 0 0 0 0 0 0 0 0 0 0 0 0
46178- 14 14 14 38 38 38 70 70 70 154 122 46
46179-190 142 34 200 144 11 197 138 11 197 138 11
46180-213 154 11 226 170 11 242 186 14 246 190 14
46181-246 190 14 246 190 14 246 190 14 246 190 14
46182-225 175 15 46 32 6 2 2 6 22 22 22
46183-158 158 158 250 250 250 253 253 253 253 253 253
46184-253 253 253 253 253 253 253 253 253 253 253 253
46185-253 253 253 253 253 253 253 253 253 253 253 253
46186-253 253 253 253 253 253 253 253 253 253 253 253
46187-253 253 253 253 253 253 253 253 253 253 253 253
46188-253 253 253 250 250 250 242 242 242 224 178 62
46189-239 182 13 236 186 11 213 154 11 46 32 6
46190- 2 2 6 2 2 6 2 2 6 2 2 6
46191- 2 2 6 2 2 6 61 42 6 225 175 15
46192-238 190 10 236 186 11 112 100 78 42 42 42
46193- 14 14 14 0 0 0 0 0 0 0 0 0
46194- 0 0 0 0 0 0 0 0 0 0 0 0
46195- 0 0 0 0 0 0 0 0 0 0 0 0
46196- 0 0 0 0 0 0 0 0 0 0 0 0
46197- 0 0 0 0 0 0 0 0 0 6 6 6
46198- 22 22 22 54 54 54 154 122 46 213 154 11
46199-226 170 11 230 174 11 226 170 11 226 170 11
46200-236 178 12 242 186 14 246 190 14 246 190 14
46201-246 190 14 246 190 14 246 190 14 246 190 14
46202-241 196 14 184 144 12 10 10 10 2 2 6
46203- 6 6 6 116 116 116 242 242 242 253 253 253
46204-253 253 253 253 253 253 253 253 253 253 253 253
46205-253 253 253 253 253 253 253 253 253 253 253 253
46206-253 253 253 253 253 253 253 253 253 253 253 253
46207-253 253 253 253 253 253 253 253 253 253 253 253
46208-253 253 253 231 231 231 198 198 198 214 170 54
46209-236 178 12 236 178 12 210 150 10 137 92 6
46210- 18 14 6 2 2 6 2 2 6 2 2 6
46211- 6 6 6 70 47 6 200 144 11 236 178 12
46212-239 182 13 239 182 13 124 112 88 58 58 58
46213- 22 22 22 6 6 6 0 0 0 0 0 0
46214- 0 0 0 0 0 0 0 0 0 0 0 0
46215- 0 0 0 0 0 0 0 0 0 0 0 0
46216- 0 0 0 0 0 0 0 0 0 0 0 0
46217- 0 0 0 0 0 0 0 0 0 10 10 10
46218- 30 30 30 70 70 70 180 133 36 226 170 11
46219-239 182 13 242 186 14 242 186 14 246 186 14
46220-246 190 14 246 190 14 246 190 14 246 190 14
46221-246 190 14 246 190 14 246 190 14 246 190 14
46222-246 190 14 232 195 16 98 70 6 2 2 6
46223- 2 2 6 2 2 6 66 66 66 221 221 221
46224-253 253 253 253 253 253 253 253 253 253 253 253
46225-253 253 253 253 253 253 253 253 253 253 253 253
46226-253 253 253 253 253 253 253 253 253 253 253 253
46227-253 253 253 253 253 253 253 253 253 253 253 253
46228-253 253 253 206 206 206 198 198 198 214 166 58
46229-230 174 11 230 174 11 216 158 10 192 133 9
46230-163 110 8 116 81 8 102 78 10 116 81 8
46231-167 114 7 197 138 11 226 170 11 239 182 13
46232-242 186 14 242 186 14 162 146 94 78 78 78
46233- 34 34 34 14 14 14 6 6 6 0 0 0
46234- 0 0 0 0 0 0 0 0 0 0 0 0
46235- 0 0 0 0 0 0 0 0 0 0 0 0
46236- 0 0 0 0 0 0 0 0 0 0 0 0
46237- 0 0 0 0 0 0 0 0 0 6 6 6
46238- 30 30 30 78 78 78 190 142 34 226 170 11
46239-239 182 13 246 190 14 246 190 14 246 190 14
46240-246 190 14 246 190 14 246 190 14 246 190 14
46241-246 190 14 246 190 14 246 190 14 246 190 14
46242-246 190 14 241 196 14 203 166 17 22 18 6
46243- 2 2 6 2 2 6 2 2 6 38 38 38
46244-218 218 218 253 253 253 253 253 253 253 253 253
46245-253 253 253 253 253 253 253 253 253 253 253 253
46246-253 253 253 253 253 253 253 253 253 253 253 253
46247-253 253 253 253 253 253 253 253 253 253 253 253
46248-250 250 250 206 206 206 198 198 198 202 162 69
46249-226 170 11 236 178 12 224 166 10 210 150 10
46250-200 144 11 197 138 11 192 133 9 197 138 11
46251-210 150 10 226 170 11 242 186 14 246 190 14
46252-246 190 14 246 186 14 225 175 15 124 112 88
46253- 62 62 62 30 30 30 14 14 14 6 6 6
46254- 0 0 0 0 0 0 0 0 0 0 0 0
46255- 0 0 0 0 0 0 0 0 0 0 0 0
46256- 0 0 0 0 0 0 0 0 0 0 0 0
46257- 0 0 0 0 0 0 0 0 0 10 10 10
46258- 30 30 30 78 78 78 174 135 50 224 166 10
46259-239 182 13 246 190 14 246 190 14 246 190 14
46260-246 190 14 246 190 14 246 190 14 246 190 14
46261-246 190 14 246 190 14 246 190 14 246 190 14
46262-246 190 14 246 190 14 241 196 14 139 102 15
46263- 2 2 6 2 2 6 2 2 6 2 2 6
46264- 78 78 78 250 250 250 253 253 253 253 253 253
46265-253 253 253 253 253 253 253 253 253 253 253 253
46266-253 253 253 253 253 253 253 253 253 253 253 253
46267-253 253 253 253 253 253 253 253 253 253 253 253
46268-250 250 250 214 214 214 198 198 198 190 150 46
46269-219 162 10 236 178 12 234 174 13 224 166 10
46270-216 158 10 213 154 11 213 154 11 216 158 10
46271-226 170 11 239 182 13 246 190 14 246 190 14
46272-246 190 14 246 190 14 242 186 14 206 162 42
46273-101 101 101 58 58 58 30 30 30 14 14 14
46274- 6 6 6 0 0 0 0 0 0 0 0 0
46275- 0 0 0 0 0 0 0 0 0 0 0 0
46276- 0 0 0 0 0 0 0 0 0 0 0 0
46277- 0 0 0 0 0 0 0 0 0 10 10 10
46278- 30 30 30 74 74 74 174 135 50 216 158 10
46279-236 178 12 246 190 14 246 190 14 246 190 14
46280-246 190 14 246 190 14 246 190 14 246 190 14
46281-246 190 14 246 190 14 246 190 14 246 190 14
46282-246 190 14 246 190 14 241 196 14 226 184 13
46283- 61 42 6 2 2 6 2 2 6 2 2 6
46284- 22 22 22 238 238 238 253 253 253 253 253 253
46285-253 253 253 253 253 253 253 253 253 253 253 253
46286-253 253 253 253 253 253 253 253 253 253 253 253
46287-253 253 253 253 253 253 253 253 253 253 253 253
46288-253 253 253 226 226 226 187 187 187 180 133 36
46289-216 158 10 236 178 12 239 182 13 236 178 12
46290-230 174 11 226 170 11 226 170 11 230 174 11
46291-236 178 12 242 186 14 246 190 14 246 190 14
46292-246 190 14 246 190 14 246 186 14 239 182 13
46293-206 162 42 106 106 106 66 66 66 34 34 34
46294- 14 14 14 6 6 6 0 0 0 0 0 0
46295- 0 0 0 0 0 0 0 0 0 0 0 0
46296- 0 0 0 0 0 0 0 0 0 0 0 0
46297- 0 0 0 0 0 0 0 0 0 6 6 6
46298- 26 26 26 70 70 70 163 133 67 213 154 11
46299-236 178 12 246 190 14 246 190 14 246 190 14
46300-246 190 14 246 190 14 246 190 14 246 190 14
46301-246 190 14 246 190 14 246 190 14 246 190 14
46302-246 190 14 246 190 14 246 190 14 241 196 14
46303-190 146 13 18 14 6 2 2 6 2 2 6
46304- 46 46 46 246 246 246 253 253 253 253 253 253
46305-253 253 253 253 253 253 253 253 253 253 253 253
46306-253 253 253 253 253 253 253 253 253 253 253 253
46307-253 253 253 253 253 253 253 253 253 253 253 253
46308-253 253 253 221 221 221 86 86 86 156 107 11
46309-216 158 10 236 178 12 242 186 14 246 186 14
46310-242 186 14 239 182 13 239 182 13 242 186 14
46311-242 186 14 246 186 14 246 190 14 246 190 14
46312-246 190 14 246 190 14 246 190 14 246 190 14
46313-242 186 14 225 175 15 142 122 72 66 66 66
46314- 30 30 30 10 10 10 0 0 0 0 0 0
46315- 0 0 0 0 0 0 0 0 0 0 0 0
46316- 0 0 0 0 0 0 0 0 0 0 0 0
46317- 0 0 0 0 0 0 0 0 0 6 6 6
46318- 26 26 26 70 70 70 163 133 67 210 150 10
46319-236 178 12 246 190 14 246 190 14 246 190 14
46320-246 190 14 246 190 14 246 190 14 246 190 14
46321-246 190 14 246 190 14 246 190 14 246 190 14
46322-246 190 14 246 190 14 246 190 14 246 190 14
46323-232 195 16 121 92 8 34 34 34 106 106 106
46324-221 221 221 253 253 253 253 253 253 253 253 253
46325-253 253 253 253 253 253 253 253 253 253 253 253
46326-253 253 253 253 253 253 253 253 253 253 253 253
46327-253 253 253 253 253 253 253 253 253 253 253 253
46328-242 242 242 82 82 82 18 14 6 163 110 8
46329-216 158 10 236 178 12 242 186 14 246 190 14
46330-246 190 14 246 190 14 246 190 14 246 190 14
46331-246 190 14 246 190 14 246 190 14 246 190 14
46332-246 190 14 246 190 14 246 190 14 246 190 14
46333-246 190 14 246 190 14 242 186 14 163 133 67
46334- 46 46 46 18 18 18 6 6 6 0 0 0
46335- 0 0 0 0 0 0 0 0 0 0 0 0
46336- 0 0 0 0 0 0 0 0 0 0 0 0
46337- 0 0 0 0 0 0 0 0 0 10 10 10
46338- 30 30 30 78 78 78 163 133 67 210 150 10
46339-236 178 12 246 186 14 246 190 14 246 190 14
46340-246 190 14 246 190 14 246 190 14 246 190 14
46341-246 190 14 246 190 14 246 190 14 246 190 14
46342-246 190 14 246 190 14 246 190 14 246 190 14
46343-241 196 14 215 174 15 190 178 144 253 253 253
46344-253 253 253 253 253 253 253 253 253 253 253 253
46345-253 253 253 253 253 253 253 253 253 253 253 253
46346-253 253 253 253 253 253 253 253 253 253 253 253
46347-253 253 253 253 253 253 253 253 253 218 218 218
46348- 58 58 58 2 2 6 22 18 6 167 114 7
46349-216 158 10 236 178 12 246 186 14 246 190 14
46350-246 190 14 246 190 14 246 190 14 246 190 14
46351-246 190 14 246 190 14 246 190 14 246 190 14
46352-246 190 14 246 190 14 246 190 14 246 190 14
46353-246 190 14 246 186 14 242 186 14 190 150 46
46354- 54 54 54 22 22 22 6 6 6 0 0 0
46355- 0 0 0 0 0 0 0 0 0 0 0 0
46356- 0 0 0 0 0 0 0 0 0 0 0 0
46357- 0 0 0 0 0 0 0 0 0 14 14 14
46358- 38 38 38 86 86 86 180 133 36 213 154 11
46359-236 178 12 246 186 14 246 190 14 246 190 14
46360-246 190 14 246 190 14 246 190 14 246 190 14
46361-246 190 14 246 190 14 246 190 14 246 190 14
46362-246 190 14 246 190 14 246 190 14 246 190 14
46363-246 190 14 232 195 16 190 146 13 214 214 214
46364-253 253 253 253 253 253 253 253 253 253 253 253
46365-253 253 253 253 253 253 253 253 253 253 253 253
46366-253 253 253 253 253 253 253 253 253 253 253 253
46367-253 253 253 250 250 250 170 170 170 26 26 26
46368- 2 2 6 2 2 6 37 26 9 163 110 8
46369-219 162 10 239 182 13 246 186 14 246 190 14
46370-246 190 14 246 190 14 246 190 14 246 190 14
46371-246 190 14 246 190 14 246 190 14 246 190 14
46372-246 190 14 246 190 14 246 190 14 246 190 14
46373-246 186 14 236 178 12 224 166 10 142 122 72
46374- 46 46 46 18 18 18 6 6 6 0 0 0
46375- 0 0 0 0 0 0 0 0 0 0 0 0
46376- 0 0 0 0 0 0 0 0 0 0 0 0
46377- 0 0 0 0 0 0 6 6 6 18 18 18
46378- 50 50 50 109 106 95 192 133 9 224 166 10
46379-242 186 14 246 190 14 246 190 14 246 190 14
46380-246 190 14 246 190 14 246 190 14 246 190 14
46381-246 190 14 246 190 14 246 190 14 246 190 14
46382-246 190 14 246 190 14 246 190 14 246 190 14
46383-242 186 14 226 184 13 210 162 10 142 110 46
46384-226 226 226 253 253 253 253 253 253 253 253 253
46385-253 253 253 253 253 253 253 253 253 253 253 253
46386-253 253 253 253 253 253 253 253 253 253 253 253
46387-198 198 198 66 66 66 2 2 6 2 2 6
46388- 2 2 6 2 2 6 50 34 6 156 107 11
46389-219 162 10 239 182 13 246 186 14 246 190 14
46390-246 190 14 246 190 14 246 190 14 246 190 14
46391-246 190 14 246 190 14 246 190 14 246 190 14
46392-246 190 14 246 190 14 246 190 14 242 186 14
46393-234 174 13 213 154 11 154 122 46 66 66 66
46394- 30 30 30 10 10 10 0 0 0 0 0 0
46395- 0 0 0 0 0 0 0 0 0 0 0 0
46396- 0 0 0 0 0 0 0 0 0 0 0 0
46397- 0 0 0 0 0 0 6 6 6 22 22 22
46398- 58 58 58 154 121 60 206 145 10 234 174 13
46399-242 186 14 246 186 14 246 190 14 246 190 14
46400-246 190 14 246 190 14 246 190 14 246 190 14
46401-246 190 14 246 190 14 246 190 14 246 190 14
46402-246 190 14 246 190 14 246 190 14 246 190 14
46403-246 186 14 236 178 12 210 162 10 163 110 8
46404- 61 42 6 138 138 138 218 218 218 250 250 250
46405-253 253 253 253 253 253 253 253 253 250 250 250
46406-242 242 242 210 210 210 144 144 144 66 66 66
46407- 6 6 6 2 2 6 2 2 6 2 2 6
46408- 2 2 6 2 2 6 61 42 6 163 110 8
46409-216 158 10 236 178 12 246 190 14 246 190 14
46410-246 190 14 246 190 14 246 190 14 246 190 14
46411-246 190 14 246 190 14 246 190 14 246 190 14
46412-246 190 14 239 182 13 230 174 11 216 158 10
46413-190 142 34 124 112 88 70 70 70 38 38 38
46414- 18 18 18 6 6 6 0 0 0 0 0 0
46415- 0 0 0 0 0 0 0 0 0 0 0 0
46416- 0 0 0 0 0 0 0 0 0 0 0 0
46417- 0 0 0 0 0 0 6 6 6 22 22 22
46418- 62 62 62 168 124 44 206 145 10 224 166 10
46419-236 178 12 239 182 13 242 186 14 242 186 14
46420-246 186 14 246 190 14 246 190 14 246 190 14
46421-246 190 14 246 190 14 246 190 14 246 190 14
46422-246 190 14 246 190 14 246 190 14 246 190 14
46423-246 190 14 236 178 12 216 158 10 175 118 6
46424- 80 54 7 2 2 6 6 6 6 30 30 30
46425- 54 54 54 62 62 62 50 50 50 38 38 38
46426- 14 14 14 2 2 6 2 2 6 2 2 6
46427- 2 2 6 2 2 6 2 2 6 2 2 6
46428- 2 2 6 6 6 6 80 54 7 167 114 7
46429-213 154 11 236 178 12 246 190 14 246 190 14
46430-246 190 14 246 190 14 246 190 14 246 190 14
46431-246 190 14 242 186 14 239 182 13 239 182 13
46432-230 174 11 210 150 10 174 135 50 124 112 88
46433- 82 82 82 54 54 54 34 34 34 18 18 18
46434- 6 6 6 0 0 0 0 0 0 0 0 0
46435- 0 0 0 0 0 0 0 0 0 0 0 0
46436- 0 0 0 0 0 0 0 0 0 0 0 0
46437- 0 0 0 0 0 0 6 6 6 18 18 18
46438- 50 50 50 158 118 36 192 133 9 200 144 11
46439-216 158 10 219 162 10 224 166 10 226 170 11
46440-230 174 11 236 178 12 239 182 13 239 182 13
46441-242 186 14 246 186 14 246 190 14 246 190 14
46442-246 190 14 246 190 14 246 190 14 246 190 14
46443-246 186 14 230 174 11 210 150 10 163 110 8
46444-104 69 6 10 10 10 2 2 6 2 2 6
46445- 2 2 6 2 2 6 2 2 6 2 2 6
46446- 2 2 6 2 2 6 2 2 6 2 2 6
46447- 2 2 6 2 2 6 2 2 6 2 2 6
46448- 2 2 6 6 6 6 91 60 6 167 114 7
46449-206 145 10 230 174 11 242 186 14 246 190 14
46450-246 190 14 246 190 14 246 186 14 242 186 14
46451-239 182 13 230 174 11 224 166 10 213 154 11
46452-180 133 36 124 112 88 86 86 86 58 58 58
46453- 38 38 38 22 22 22 10 10 10 6 6 6
46454- 0 0 0 0 0 0 0 0 0 0 0 0
46455- 0 0 0 0 0 0 0 0 0 0 0 0
46456- 0 0 0 0 0 0 0 0 0 0 0 0
46457- 0 0 0 0 0 0 0 0 0 14 14 14
46458- 34 34 34 70 70 70 138 110 50 158 118 36
46459-167 114 7 180 123 7 192 133 9 197 138 11
46460-200 144 11 206 145 10 213 154 11 219 162 10
46461-224 166 10 230 174 11 239 182 13 242 186 14
46462-246 186 14 246 186 14 246 186 14 246 186 14
46463-239 182 13 216 158 10 185 133 11 152 99 6
46464-104 69 6 18 14 6 2 2 6 2 2 6
46465- 2 2 6 2 2 6 2 2 6 2 2 6
46466- 2 2 6 2 2 6 2 2 6 2 2 6
46467- 2 2 6 2 2 6 2 2 6 2 2 6
46468- 2 2 6 6 6 6 80 54 7 152 99 6
46469-192 133 9 219 162 10 236 178 12 239 182 13
46470-246 186 14 242 186 14 239 182 13 236 178 12
46471-224 166 10 206 145 10 192 133 9 154 121 60
46472- 94 94 94 62 62 62 42 42 42 22 22 22
46473- 14 14 14 6 6 6 0 0 0 0 0 0
46474- 0 0 0 0 0 0 0 0 0 0 0 0
46475- 0 0 0 0 0 0 0 0 0 0 0 0
46476- 0 0 0 0 0 0 0 0 0 0 0 0
46477- 0 0 0 0 0 0 0 0 0 6 6 6
46478- 18 18 18 34 34 34 58 58 58 78 78 78
46479-101 98 89 124 112 88 142 110 46 156 107 11
46480-163 110 8 167 114 7 175 118 6 180 123 7
46481-185 133 11 197 138 11 210 150 10 219 162 10
46482-226 170 11 236 178 12 236 178 12 234 174 13
46483-219 162 10 197 138 11 163 110 8 130 83 6
46484- 91 60 6 10 10 10 2 2 6 2 2 6
46485- 18 18 18 38 38 38 38 38 38 38 38 38
46486- 38 38 38 38 38 38 38 38 38 38 38 38
46487- 38 38 38 38 38 38 26 26 26 2 2 6
46488- 2 2 6 6 6 6 70 47 6 137 92 6
46489-175 118 6 200 144 11 219 162 10 230 174 11
46490-234 174 13 230 174 11 219 162 10 210 150 10
46491-192 133 9 163 110 8 124 112 88 82 82 82
46492- 50 50 50 30 30 30 14 14 14 6 6 6
46493- 0 0 0 0 0 0 0 0 0 0 0 0
46494- 0 0 0 0 0 0 0 0 0 0 0 0
46495- 0 0 0 0 0 0 0 0 0 0 0 0
46496- 0 0 0 0 0 0 0 0 0 0 0 0
46497- 0 0 0 0 0 0 0 0 0 0 0 0
46498- 6 6 6 14 14 14 22 22 22 34 34 34
46499- 42 42 42 58 58 58 74 74 74 86 86 86
46500-101 98 89 122 102 70 130 98 46 121 87 25
46501-137 92 6 152 99 6 163 110 8 180 123 7
46502-185 133 11 197 138 11 206 145 10 200 144 11
46503-180 123 7 156 107 11 130 83 6 104 69 6
46504- 50 34 6 54 54 54 110 110 110 101 98 89
46505- 86 86 86 82 82 82 78 78 78 78 78 78
46506- 78 78 78 78 78 78 78 78 78 78 78 78
46507- 78 78 78 82 82 82 86 86 86 94 94 94
46508-106 106 106 101 101 101 86 66 34 124 80 6
46509-156 107 11 180 123 7 192 133 9 200 144 11
46510-206 145 10 200 144 11 192 133 9 175 118 6
46511-139 102 15 109 106 95 70 70 70 42 42 42
46512- 22 22 22 10 10 10 0 0 0 0 0 0
46513- 0 0 0 0 0 0 0 0 0 0 0 0
46514- 0 0 0 0 0 0 0 0 0 0 0 0
46515- 0 0 0 0 0 0 0 0 0 0 0 0
46516- 0 0 0 0 0 0 0 0 0 0 0 0
46517- 0 0 0 0 0 0 0 0 0 0 0 0
46518- 0 0 0 0 0 0 6 6 6 10 10 10
46519- 14 14 14 22 22 22 30 30 30 38 38 38
46520- 50 50 50 62 62 62 74 74 74 90 90 90
46521-101 98 89 112 100 78 121 87 25 124 80 6
46522-137 92 6 152 99 6 152 99 6 152 99 6
46523-138 86 6 124 80 6 98 70 6 86 66 30
46524-101 98 89 82 82 82 58 58 58 46 46 46
46525- 38 38 38 34 34 34 34 34 34 34 34 34
46526- 34 34 34 34 34 34 34 34 34 34 34 34
46527- 34 34 34 34 34 34 38 38 38 42 42 42
46528- 54 54 54 82 82 82 94 86 76 91 60 6
46529-134 86 6 156 107 11 167 114 7 175 118 6
46530-175 118 6 167 114 7 152 99 6 121 87 25
46531-101 98 89 62 62 62 34 34 34 18 18 18
46532- 6 6 6 0 0 0 0 0 0 0 0 0
46533- 0 0 0 0 0 0 0 0 0 0 0 0
46534- 0 0 0 0 0 0 0 0 0 0 0 0
46535- 0 0 0 0 0 0 0 0 0 0 0 0
46536- 0 0 0 0 0 0 0 0 0 0 0 0
46537- 0 0 0 0 0 0 0 0 0 0 0 0
46538- 0 0 0 0 0 0 0 0 0 0 0 0
46539- 0 0 0 6 6 6 6 6 6 10 10 10
46540- 18 18 18 22 22 22 30 30 30 42 42 42
46541- 50 50 50 66 66 66 86 86 86 101 98 89
46542-106 86 58 98 70 6 104 69 6 104 69 6
46543-104 69 6 91 60 6 82 62 34 90 90 90
46544- 62 62 62 38 38 38 22 22 22 14 14 14
46545- 10 10 10 10 10 10 10 10 10 10 10 10
46546- 10 10 10 10 10 10 6 6 6 10 10 10
46547- 10 10 10 10 10 10 10 10 10 14 14 14
46548- 22 22 22 42 42 42 70 70 70 89 81 66
46549- 80 54 7 104 69 6 124 80 6 137 92 6
46550-134 86 6 116 81 8 100 82 52 86 86 86
46551- 58 58 58 30 30 30 14 14 14 6 6 6
46552- 0 0 0 0 0 0 0 0 0 0 0 0
46553- 0 0 0 0 0 0 0 0 0 0 0 0
46554- 0 0 0 0 0 0 0 0 0 0 0 0
46555- 0 0 0 0 0 0 0 0 0 0 0 0
46556- 0 0 0 0 0 0 0 0 0 0 0 0
46557- 0 0 0 0 0 0 0 0 0 0 0 0
46558- 0 0 0 0 0 0 0 0 0 0 0 0
46559- 0 0 0 0 0 0 0 0 0 0 0 0
46560- 0 0 0 6 6 6 10 10 10 14 14 14
46561- 18 18 18 26 26 26 38 38 38 54 54 54
46562- 70 70 70 86 86 86 94 86 76 89 81 66
46563- 89 81 66 86 86 86 74 74 74 50 50 50
46564- 30 30 30 14 14 14 6 6 6 0 0 0
46565- 0 0 0 0 0 0 0 0 0 0 0 0
46566- 0 0 0 0 0 0 0 0 0 0 0 0
46567- 0 0 0 0 0 0 0 0 0 0 0 0
46568- 6 6 6 18 18 18 34 34 34 58 58 58
46569- 82 82 82 89 81 66 89 81 66 89 81 66
46570- 94 86 66 94 86 76 74 74 74 50 50 50
46571- 26 26 26 14 14 14 6 6 6 0 0 0
46572- 0 0 0 0 0 0 0 0 0 0 0 0
46573- 0 0 0 0 0 0 0 0 0 0 0 0
46574- 0 0 0 0 0 0 0 0 0 0 0 0
46575- 0 0 0 0 0 0 0 0 0 0 0 0
46576- 0 0 0 0 0 0 0 0 0 0 0 0
46577- 0 0 0 0 0 0 0 0 0 0 0 0
46578- 0 0 0 0 0 0 0 0 0 0 0 0
46579- 0 0 0 0 0 0 0 0 0 0 0 0
46580- 0 0 0 0 0 0 0 0 0 0 0 0
46581- 6 6 6 6 6 6 14 14 14 18 18 18
46582- 30 30 30 38 38 38 46 46 46 54 54 54
46583- 50 50 50 42 42 42 30 30 30 18 18 18
46584- 10 10 10 0 0 0 0 0 0 0 0 0
46585- 0 0 0 0 0 0 0 0 0 0 0 0
46586- 0 0 0 0 0 0 0 0 0 0 0 0
46587- 0 0 0 0 0 0 0 0 0 0 0 0
46588- 0 0 0 6 6 6 14 14 14 26 26 26
46589- 38 38 38 50 50 50 58 58 58 58 58 58
46590- 54 54 54 42 42 42 30 30 30 18 18 18
46591- 10 10 10 0 0 0 0 0 0 0 0 0
46592- 0 0 0 0 0 0 0 0 0 0 0 0
46593- 0 0 0 0 0 0 0 0 0 0 0 0
46594- 0 0 0 0 0 0 0 0 0 0 0 0
46595- 0 0 0 0 0 0 0 0 0 0 0 0
46596- 0 0 0 0 0 0 0 0 0 0 0 0
46597- 0 0 0 0 0 0 0 0 0 0 0 0
46598- 0 0 0 0 0 0 0 0 0 0 0 0
46599- 0 0 0 0 0 0 0 0 0 0 0 0
46600- 0 0 0 0 0 0 0 0 0 0 0 0
46601- 0 0 0 0 0 0 0 0 0 6 6 6
46602- 6 6 6 10 10 10 14 14 14 18 18 18
46603- 18 18 18 14 14 14 10 10 10 6 6 6
46604- 0 0 0 0 0 0 0 0 0 0 0 0
46605- 0 0 0 0 0 0 0 0 0 0 0 0
46606- 0 0 0 0 0 0 0 0 0 0 0 0
46607- 0 0 0 0 0 0 0 0 0 0 0 0
46608- 0 0 0 0 0 0 0 0 0 6 6 6
46609- 14 14 14 18 18 18 22 22 22 22 22 22
46610- 18 18 18 14 14 14 10 10 10 6 6 6
46611- 0 0 0 0 0 0 0 0 0 0 0 0
46612- 0 0 0 0 0 0 0 0 0 0 0 0
46613- 0 0 0 0 0 0 0 0 0 0 0 0
46614- 0 0 0 0 0 0 0 0 0 0 0 0
46615- 0 0 0 0 0 0 0 0 0 0 0 0
46616+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46623+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46624+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46625+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46626+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46627+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46628+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46629+4 4 4 4 4 4
46630+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46636+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46637+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46638+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46639+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46640+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46641+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46642+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46643+4 4 4 4 4 4
46644+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46649+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46650+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46651+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46652+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46653+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46654+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46655+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46656+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46657+4 4 4 4 4 4
46658+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46663+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46664+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46665+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46666+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46667+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46668+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46670+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46671+4 4 4 4 4 4
46672+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46677+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46678+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46679+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46684+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46685+4 4 4 4 4 4
46686+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46690+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46691+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46692+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46693+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46698+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46699+4 4 4 4 4 4
46700+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46704+4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
46705+0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
46706+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46707+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46709+4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
46710+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46711+4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
46712+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46713+4 4 4 4 4 4
46714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46718+4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
46719+37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
46720+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46721+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46723+4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
46724+2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
46725+4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
46726+1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46727+4 4 4 4 4 4
46728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46732+2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
46733+153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
46734+0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46735+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46736+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46737+4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
46738+60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
46739+4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
46740+2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
46741+4 4 4 4 4 4
46742+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46743+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46744+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46745+4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
46746+4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
46747+165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
46748+1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
46749+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46750+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46751+3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
46752+163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
46753+0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
46754+37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
46755+4 4 4 4 4 4
46756+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46757+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46758+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46759+4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
46760+37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
46761+156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
46762+125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
46763+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
46764+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
46765+0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
46766+174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
46767+0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
46768+64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
46769+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 4 4 4 4 4 4 4 4 4 5 5 5
46773+5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
46774+156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
46775+156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
46776+174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
46777+1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
46778+4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
46779+13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
46780+174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
46781+22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
46782+90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
46783+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 4 4 4 4 4 4 5 5 5 3 3 3
46787+0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
46788+174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
46789+156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
46790+163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
46791+4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
46792+5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
46793+131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
46794+190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
46795+90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
46796+31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
46797+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 4 4 4 2 2 2 0 0 0 4 0 0
46801+4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
46802+155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
46803+167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
46804+153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
46805+41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
46806+1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
46807+177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
46808+125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
46809+136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
46810+7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
46811+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 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
46815+125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
46816+156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
46817+137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
46818+156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
46819+167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
46820+0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
46821+166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
46822+6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
46823+90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
46824+1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
46825+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+1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
46829+167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
46830+157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
46831+26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
46832+158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
46833+165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
46834+60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
46835+137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
46836+52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
46837+13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
46838+4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
46839+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 3 3 3 0 0 0
46842+0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
46843+158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
46844+167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
46845+4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
46846+174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
46847+155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
46848+137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
46849+16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
46850+136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
46851+2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
46852+4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
46853+4 4 4 4 4 4
46854+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
46855+4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
46856+37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
46857+157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
46858+153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
46859+4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
46860+125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
46861+156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
46862+174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
46863+4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
46864+136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
46865+1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
46866+2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
46867+0 0 0 4 4 4
46868+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
46869+4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
46870+158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
46871+153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
46872+37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
46873+4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
46874+4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
46875+154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
46876+174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
46877+32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
46878+28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
46879+50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
46880+0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
46881+2 0 0 0 0 0
46882+4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
46883+0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
46884+174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
46885+165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
46886+4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
46887+4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
46888+4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
46889+174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
46890+60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
46891+136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
46892+22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
46893+136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
46894+26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
46895+37 38 37 0 0 0
46896+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46897+13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
46898+153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
46899+177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
46900+4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
46901+5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
46902+6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
46903+166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
46904+4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
46905+146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
46906+71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
46907+90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
46908+125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
46909+85 115 134 4 0 0
46910+4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
46911+125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
46912+155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
46913+125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
46914+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
46915+0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
46916+5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
46917+37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
46918+4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
46919+90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
46920+2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
46921+13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
46922+166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
46923+60 73 81 4 0 0
46924+4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
46925+174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
46926+156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
46927+4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
46928+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
46929+10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
46930+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
46931+4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
46932+80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
46933+28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
46934+50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
46935+1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
46936+167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
46937+16 19 21 4 0 0
46938+4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
46939+158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
46940+167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
46941+4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
46942+4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
46943+80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
46944+4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
46945+3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
46946+146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
46947+68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
46948+136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
46949+24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
46950+163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
46951+4 0 0 4 3 3
46952+3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
46953+156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
46954+155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
46955+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
46956+2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
46957+136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
46958+0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
46959+0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
46960+136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
46961+28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
46962+22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
46963+137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
46964+60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
46965+3 2 2 4 4 4
46966+3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
46967+157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
46968+37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
46969+4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
46970+0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
46971+101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
46972+14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
46973+22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
46974+136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
46975+17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
46976+2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
46977+166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
46978+13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
46979+4 4 4 4 4 4
46980+1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
46981+163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
46982+4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
46983+4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
46984+40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
46985+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
46986+101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
46987+136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
46988+136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
46989+136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
46990+3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
46991+174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
46992+4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
46993+4 4 4 4 4 4
46994+4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
46995+155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
46996+4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
46997+4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
46998+101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
46999+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47000+136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
47001+136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
47002+136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
47003+90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
47004+85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
47005+167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
47006+6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
47007+5 5 5 5 5 5
47008+1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
47009+131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
47010+6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
47011+0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
47012+101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
47013+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47014+101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
47015+136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
47016+101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
47017+7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
47018+174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
47019+24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
47020+4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
47021+5 5 5 4 4 4
47022+4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
47023+131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
47024+6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
47025+13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
47026+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47027+101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
47028+101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
47029+136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
47030+136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
47031+2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
47032+174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
47033+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47034+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47035+4 4 4 4 4 4
47036+1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
47037+137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
47038+4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
47039+64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
47040+90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
47041+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47042+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47043+136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
47044+101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
47045+37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
47046+167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
47047+3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
47048+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47049+4 4 4 4 4 4
47050+4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
47051+153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
47052+4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
47053+90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
47054+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47055+90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
47056+101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
47057+101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
47058+35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
47059+154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
47060+60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
47061+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47062+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47063+4 4 4 4 4 4
47064+1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
47065+153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
47066+4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
47067+64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
47068+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47069+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47070+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
47071+136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
47072+13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
47073+174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
47074+6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
47075+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47076+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47077+4 4 4 4 4 4
47078+4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
47079+156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
47080+4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
47081+90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
47082+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47083+90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
47084+101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
47085+101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
47086+2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
47087+174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
47088+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47089+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47090+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47091+4 4 4 4 4 4
47092+3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
47093+158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
47094+4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
47095+37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
47096+90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
47097+90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
47098+101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
47099+90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
47100+5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
47101+167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
47102+6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
47103+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47104+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47105+4 4 4 4 4 4
47106+4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
47107+163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
47108+4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
47109+18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
47110+64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
47111+90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
47112+101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
47113+13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
47114+3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
47115+174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
47116+4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
47117+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47118+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47119+4 4 4 4 4 4
47120+1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
47121+167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
47122+4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
47123+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47124+26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
47125+90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
47126+101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
47127+7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
47128+4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
47129+174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
47130+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47131+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47132+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47133+4 4 4 4 4 4
47134+4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
47135+174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
47136+5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
47137+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47138+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47139+90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
47140+101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
47141+2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
47142+3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
47143+153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
47144+4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47145+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47146+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47147+4 4 4 4 4 4
47148+1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
47149+174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
47150+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47151+18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
47152+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47153+26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
47154+35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
47155+2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
47156+3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
47157+131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
47158+4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47159+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47160+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47161+4 4 4 4 4 4
47162+3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
47163+174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
47164+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47165+18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
47166+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47167+26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
47168+7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
47169+4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
47170+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47171+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47172+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47173+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47174+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47175+4 4 4 4 4 4
47176+1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47177+174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
47178+5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
47179+18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
47180+18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
47181+26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
47182+28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
47183+3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
47184+4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47185+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47186+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47187+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47188+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47189+4 4 4 4 4 4
47190+4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
47191+174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
47192+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
47193+10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
47194+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47195+18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
47196+90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
47197+3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
47198+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47199+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47200+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47201+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47202+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47203+4 4 4 4 4 4
47204+1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
47205+177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
47206+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47207+10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
47208+26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
47209+6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
47210+10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
47211+2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
47212+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47213+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47214+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47215+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47216+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47217+4 4 4 4 4 4
47218+4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
47219+177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
47220+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47221+10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
47222+26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
47223+7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
47224+3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
47225+21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
47226+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
47227+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47228+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47229+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47230+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47231+4 4 4 4 4 4
47232+3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47233+190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
47234+5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
47235+10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
47236+24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
47237+18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
47238+28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
47239+26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
47240+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47241+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47242+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47243+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47244+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47245+4 4 4 4 4 4
47246+4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
47247+190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
47248+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47249+10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
47250+0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
47251+26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
47252+37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
47253+90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
47254+4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
47255+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47256+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47257+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47258+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47259+4 4 4 4 4 4
47260+4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
47261+193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
47262+5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
47263+10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
47264+1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
47265+26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
47266+22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
47267+26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
47268+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47269+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47270+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47271+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47272+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47273+4 4 4 4 4 4
47274+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47275+190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
47276+5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
47277+10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
47278+2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
47279+26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
47280+10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
47281+26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
47282+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47283+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47284+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47285+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47286+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47287+4 4 4 4 4 4
47288+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47289+193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
47290+5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
47291+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
47292+13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
47293+10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
47294+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47295+26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
47296+4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
47297+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47298+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47299+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47300+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47301+4 4 4 4 4 4
47302+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47303+190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
47304+5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
47305+28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47306+10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
47307+28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
47308+26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
47309+26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
47310+4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
47311+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47312+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47313+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47314+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47315+4 4 4 4 4 4
47316+4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
47317+193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
47318+5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
47319+4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
47320+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
47321+10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
47322+18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
47323+22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
47324+4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
47325+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47326+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47327+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47328+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47329+4 4 4 4 4 4
47330+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47331+190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
47332+6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
47333+1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
47334+18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
47335+10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
47336+26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
47337+1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
47338+5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
47339+137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47340+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47341+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47342+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47343+4 4 4 4 4 4
47344+4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
47345+193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
47346+2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
47347+4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
47348+10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
47349+10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
47350+26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
47351+2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
47352+3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
47353+131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47354+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47355+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47356+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47357+4 4 4 4 4 4
47358+4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
47359+193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
47360+0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
47361+4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
47362+13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
47363+10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
47364+28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
47365+4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
47366+0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
47367+125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
47368+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47369+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47370+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47371+4 4 4 4 4 4
47372+4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
47373+193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
47374+120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
47375+4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
47376+4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
47377+10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
47378+4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
47379+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
47380+24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
47381+125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
47382+0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47383+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47384+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47385+4 4 4 4 4 4
47386+4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
47387+174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47388+220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
47389+3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
47390+4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
47391+10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
47392+1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
47393+5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
47394+137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
47395+125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
47396+0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47397+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47398+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47399+4 4 4 4 4 4
47400+5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
47401+193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
47402+220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
47403+4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
47404+4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
47405+22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
47406+4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47407+1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
47408+166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
47409+125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
47410+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47411+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47412+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47413+4 4 4 4 4 4
47414+4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
47415+220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
47416+205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
47417+24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
47418+4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
47419+4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
47420+4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
47421+2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
47422+156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
47423+137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
47424+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47425+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47426+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47427+4 4 4 4 4 4
47428+5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
47429+125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
47430+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47431+193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
47432+5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
47433+1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
47434+5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
47435+60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
47436+153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
47437+125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
47438+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47439+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47440+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47441+4 4 4 4 4 4
47442+4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47443+6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
47444+193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
47445+244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
47446+0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
47447+4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
47448+3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
47449+220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
47450+153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
47451+13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47452+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47453+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47454+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47455+4 4 4 4 4 4
47456+5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
47457+6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
47458+244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
47459+220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
47460+3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
47461+4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
47462+0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
47463+177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
47464+158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
47465+4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
47466+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47467+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47468+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47469+4 4 4 4 4 4
47470+5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
47471+6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
47472+177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
47473+220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
47474+125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
47475+4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
47476+37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
47477+174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
47478+158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
47479+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47480+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47481+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47482+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47483+4 4 4 4 4 4
47484+4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
47485+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47486+26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
47487+205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
47488+244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
47489+0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
47490+177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
47491+174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
47492+60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
47493+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47494+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47495+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47496+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47497+4 4 4 4 4 4
47498+5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
47499+6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
47500+6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
47501+220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
47502+220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
47503+0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
47504+220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
47505+174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
47506+4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
47507+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47508+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47509+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47510+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47511+4 4 4 4 4 4
47512+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47513+6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
47514+4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
47515+220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
47516+205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
47517+60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
47518+177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
47519+190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
47520+4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47521+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47522+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47523+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47524+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47525+4 4 4 4 4 4
47526+4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
47527+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
47528+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47529+125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
47530+205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
47531+193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
47532+190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
47533+153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
47534+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47535+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47536+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47537+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47538+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47539+4 4 4 4 4 4
47540+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47541+6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
47542+4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
47543+4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
47544+205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
47545+220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
47546+174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
47547+6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
47548+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47549+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47550+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47551+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47552+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47553+4 4 4 4 4 4
47554+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47555+5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
47556+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47557+4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
47558+220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
47559+190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
47560+193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
47561+4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
47562+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47563+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47564+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47565+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47566+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47567+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 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
47570+4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
47571+6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
47572+174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
47573+193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
47574+193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
47575+6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
47576+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47577+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47578+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47579+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47580+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47581+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 5 5 5 5 5 5 5 5 5
47584+5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
47585+5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47586+6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
47587+193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
47588+60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
47589+5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47590+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47591+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47592+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47593+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47594+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47595+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 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47599+5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
47600+4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
47601+193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
47602+6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
47603+4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
47604+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47605+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47606+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47607+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47608+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47609+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 4 4 4 4 4 4 4 4 4 5 5 5
47613+4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47614+6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
47615+153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
47616+6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
47617+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47618+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47619+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47620+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47621+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47622+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47623+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 4 4 4 4 4 4 4 4 4 4 4 4
47627+4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
47628+6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
47629+24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
47630+6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
47631+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47632+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47633+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47634+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47635+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
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 4 4 4 4 4 4 4 4 4 4 4 4
47641+4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
47642+4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
47643+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
47644+4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
47645+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47646+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47647+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47648+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47649+4 4 4 4 4 4 4 4 4 4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
47655+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
47656+5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
47657+6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
47658+6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
47659+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47660+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47661+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47662+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47663+4 4 4 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
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 4 4 4 4 4 4 4 4 4 4 4 4
47669+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
47670+4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
47671+4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
47672+6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
47673+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47674+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47675+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47676+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
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
47680+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47681+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47682+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47683+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47684+4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
47685+6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
47686+4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
47687+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47688+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47689+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47690+4 4 4 4 4 4 4 4 4 4 4 4 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
47694+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47695+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47696+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47697+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47698+4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
47699+4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
47700+5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47701+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47702+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47703+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47704+4 4 4 4 4 4 4 4 4 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
47708+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47709+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47710+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47711+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47712+4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
47713+5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
47714+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47715+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47716+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47717+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47718+4 4 4 4 4 4 4 4 4 4 4 4 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
47722+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47723+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47724+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47725+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47726+4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
47727+5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
47728+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47729+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47730+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47731+4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
47732+4 4 4 4 4 4 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
47736diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
47737index fe92eed..106e085 100644
47738--- a/drivers/video/mb862xx/mb862xxfb_accel.c
47739+++ b/drivers/video/mb862xx/mb862xxfb_accel.c
47740@@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
47741 struct mb862xxfb_par *par = info->par;
47742
47743 if (info->var.bits_per_pixel == 32) {
47744- info->fbops->fb_fillrect = cfb_fillrect;
47745- info->fbops->fb_copyarea = cfb_copyarea;
47746- info->fbops->fb_imageblit = cfb_imageblit;
47747+ pax_open_kernel();
47748+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47749+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47750+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47751+ pax_close_kernel();
47752 } else {
47753 outreg(disp, GC_L0EM, 3);
47754- info->fbops->fb_fillrect = mb86290fb_fillrect;
47755- info->fbops->fb_copyarea = mb86290fb_copyarea;
47756- info->fbops->fb_imageblit = mb86290fb_imageblit;
47757+ pax_open_kernel();
47758+ *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
47759+ *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
47760+ *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
47761+ pax_close_kernel();
47762 }
47763 outreg(draw, GDC_REG_DRAW_BASE, 0);
47764 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
47765diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
47766index ff22871..b129bed 100644
47767--- a/drivers/video/nvidia/nvidia.c
47768+++ b/drivers/video/nvidia/nvidia.c
47769@@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
47770 info->fix.line_length = (info->var.xres_virtual *
47771 info->var.bits_per_pixel) >> 3;
47772 if (info->var.accel_flags) {
47773- info->fbops->fb_imageblit = nvidiafb_imageblit;
47774- info->fbops->fb_fillrect = nvidiafb_fillrect;
47775- info->fbops->fb_copyarea = nvidiafb_copyarea;
47776- info->fbops->fb_sync = nvidiafb_sync;
47777+ pax_open_kernel();
47778+ *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
47779+ *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
47780+ *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
47781+ *(void **)&info->fbops->fb_sync = nvidiafb_sync;
47782+ pax_close_kernel();
47783 info->pixmap.scan_align = 4;
47784 info->flags &= ~FBINFO_HWACCEL_DISABLED;
47785 info->flags |= FBINFO_READS_FAST;
47786 NVResetGraphics(info);
47787 } else {
47788- info->fbops->fb_imageblit = cfb_imageblit;
47789- info->fbops->fb_fillrect = cfb_fillrect;
47790- info->fbops->fb_copyarea = cfb_copyarea;
47791- info->fbops->fb_sync = NULL;
47792+ pax_open_kernel();
47793+ *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
47794+ *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
47795+ *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
47796+ *(void **)&info->fbops->fb_sync = NULL;
47797+ pax_close_kernel();
47798 info->pixmap.scan_align = 1;
47799 info->flags |= FBINFO_HWACCEL_DISABLED;
47800 info->flags &= ~FBINFO_READS_FAST;
47801@@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
47802 info->pixmap.size = 8 * 1024;
47803 info->pixmap.flags = FB_PIXMAP_SYSTEM;
47804
47805- if (!hwcur)
47806- info->fbops->fb_cursor = NULL;
47807+ if (!hwcur) {
47808+ pax_open_kernel();
47809+ *(void **)&info->fbops->fb_cursor = NULL;
47810+ pax_close_kernel();
47811+ }
47812
47813 info->var.accel_flags = (!noaccel);
47814
47815diff --git a/drivers/video/output.c b/drivers/video/output.c
47816index 0d6f2cd..6285b97 100644
47817--- a/drivers/video/output.c
47818+++ b/drivers/video/output.c
47819@@ -97,7 +97,7 @@ struct output_device *video_output_register(const char *name,
47820 new_dev->props = op;
47821 new_dev->dev.class = &video_output_class;
47822 new_dev->dev.parent = dev;
47823- dev_set_name(&new_dev->dev, name);
47824+ dev_set_name(&new_dev->dev, "%s", name);
47825 dev_set_drvdata(&new_dev->dev, devdata);
47826 ret_code = device_register(&new_dev->dev);
47827 if (ret_code) {
47828diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
47829index 76d9053..dec2bfd 100644
47830--- a/drivers/video/s1d13xxxfb.c
47831+++ b/drivers/video/s1d13xxxfb.c
47832@@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
47833
47834 switch(prod_id) {
47835 case S1D13506_PROD_ID: /* activate acceleration */
47836- s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47837- s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47838+ pax_open_kernel();
47839+ *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
47840+ *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
47841+ pax_close_kernel();
47842 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
47843 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
47844 break;
47845diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
47846index 97bd662..39fab85 100644
47847--- a/drivers/video/smscufx.c
47848+++ b/drivers/video/smscufx.c
47849@@ -1171,7 +1171,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
47850 fb_deferred_io_cleanup(info);
47851 kfree(info->fbdefio);
47852 info->fbdefio = NULL;
47853- info->fbops->fb_mmap = ufx_ops_mmap;
47854+ pax_open_kernel();
47855+ *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
47856+ pax_close_kernel();
47857 }
47858
47859 pr_debug("released /dev/fb%d user=%d count=%d",
47860diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
47861index 86d449e..8e04dc5 100644
47862--- a/drivers/video/udlfb.c
47863+++ b/drivers/video/udlfb.c
47864@@ -619,11 +619,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
47865 dlfb_urb_completion(urb);
47866
47867 error:
47868- atomic_add(bytes_sent, &dev->bytes_sent);
47869- atomic_add(bytes_identical, &dev->bytes_identical);
47870- atomic_add(width*height*2, &dev->bytes_rendered);
47871+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47872+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47873+ atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
47874 end_cycles = get_cycles();
47875- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47876+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47877 >> 10)), /* Kcycles */
47878 &dev->cpu_kcycles_used);
47879
47880@@ -744,11 +744,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
47881 dlfb_urb_completion(urb);
47882
47883 error:
47884- atomic_add(bytes_sent, &dev->bytes_sent);
47885- atomic_add(bytes_identical, &dev->bytes_identical);
47886- atomic_add(bytes_rendered, &dev->bytes_rendered);
47887+ atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
47888+ atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
47889+ atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
47890 end_cycles = get_cycles();
47891- atomic_add(((unsigned int) ((end_cycles - start_cycles)
47892+ atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
47893 >> 10)), /* Kcycles */
47894 &dev->cpu_kcycles_used);
47895 }
47896@@ -989,7 +989,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
47897 fb_deferred_io_cleanup(info);
47898 kfree(info->fbdefio);
47899 info->fbdefio = NULL;
47900- info->fbops->fb_mmap = dlfb_ops_mmap;
47901+ pax_open_kernel();
47902+ *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
47903+ pax_close_kernel();
47904 }
47905
47906 pr_warn("released /dev/fb%d user=%d count=%d\n",
47907@@ -1372,7 +1374,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
47908 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47909 struct dlfb_data *dev = fb_info->par;
47910 return snprintf(buf, PAGE_SIZE, "%u\n",
47911- atomic_read(&dev->bytes_rendered));
47912+ atomic_read_unchecked(&dev->bytes_rendered));
47913 }
47914
47915 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47916@@ -1380,7 +1382,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
47917 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47918 struct dlfb_data *dev = fb_info->par;
47919 return snprintf(buf, PAGE_SIZE, "%u\n",
47920- atomic_read(&dev->bytes_identical));
47921+ atomic_read_unchecked(&dev->bytes_identical));
47922 }
47923
47924 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47925@@ -1388,7 +1390,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
47926 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47927 struct dlfb_data *dev = fb_info->par;
47928 return snprintf(buf, PAGE_SIZE, "%u\n",
47929- atomic_read(&dev->bytes_sent));
47930+ atomic_read_unchecked(&dev->bytes_sent));
47931 }
47932
47933 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47934@@ -1396,7 +1398,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
47935 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47936 struct dlfb_data *dev = fb_info->par;
47937 return snprintf(buf, PAGE_SIZE, "%u\n",
47938- atomic_read(&dev->cpu_kcycles_used));
47939+ atomic_read_unchecked(&dev->cpu_kcycles_used));
47940 }
47941
47942 static ssize_t edid_show(
47943@@ -1456,10 +1458,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
47944 struct fb_info *fb_info = dev_get_drvdata(fbdev);
47945 struct dlfb_data *dev = fb_info->par;
47946
47947- atomic_set(&dev->bytes_rendered, 0);
47948- atomic_set(&dev->bytes_identical, 0);
47949- atomic_set(&dev->bytes_sent, 0);
47950- atomic_set(&dev->cpu_kcycles_used, 0);
47951+ atomic_set_unchecked(&dev->bytes_rendered, 0);
47952+ atomic_set_unchecked(&dev->bytes_identical, 0);
47953+ atomic_set_unchecked(&dev->bytes_sent, 0);
47954+ atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
47955
47956 return count;
47957 }
47958diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
47959index d428445..79a78df 100644
47960--- a/drivers/video/uvesafb.c
47961+++ b/drivers/video/uvesafb.c
47962@@ -19,6 +19,7 @@
47963 #include <linux/io.h>
47964 #include <linux/mutex.h>
47965 #include <linux/slab.h>
47966+#include <linux/moduleloader.h>
47967 #include <video/edid.h>
47968 #include <video/uvesafb.h>
47969 #ifdef CONFIG_X86
47970@@ -569,10 +570,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
47971 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
47972 par->pmi_setpal = par->ypan = 0;
47973 } else {
47974+
47975+#ifdef CONFIG_PAX_KERNEXEC
47976+#ifdef CONFIG_MODULES
47977+ par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
47978+#endif
47979+ if (!par->pmi_code) {
47980+ par->pmi_setpal = par->ypan = 0;
47981+ return 0;
47982+ }
47983+#endif
47984+
47985 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
47986 + task->t.regs.edi);
47987+
47988+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
47989+ pax_open_kernel();
47990+ memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
47991+ pax_close_kernel();
47992+
47993+ par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
47994+ par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
47995+#else
47996 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
47997 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
47998+#endif
47999+
48000 printk(KERN_INFO "uvesafb: protected mode interface info at "
48001 "%04x:%04x\n",
48002 (u16)task->t.regs.es, (u16)task->t.regs.edi);
48003@@ -817,13 +840,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
48004 par->ypan = ypan;
48005
48006 if (par->pmi_setpal || par->ypan) {
48007+#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
48008 if (__supported_pte_mask & _PAGE_NX) {
48009 par->pmi_setpal = par->ypan = 0;
48010 printk(KERN_WARNING "uvesafb: NX protection is actively."
48011 "We have better not to use the PMI.\n");
48012- } else {
48013+ } else
48014+#endif
48015 uvesafb_vbe_getpmi(task, par);
48016- }
48017 }
48018 #else
48019 /* The protected mode interface is not available on non-x86. */
48020@@ -1457,8 +1481,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48021 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
48022
48023 /* Disable blanking if the user requested so. */
48024- if (!blank)
48025- info->fbops->fb_blank = NULL;
48026+ if (!blank) {
48027+ pax_open_kernel();
48028+ *(void **)&info->fbops->fb_blank = NULL;
48029+ pax_close_kernel();
48030+ }
48031
48032 /*
48033 * Find out how much IO memory is required for the mode with
48034@@ -1534,8 +1561,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
48035 info->flags = FBINFO_FLAG_DEFAULT |
48036 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
48037
48038- if (!par->ypan)
48039- info->fbops->fb_pan_display = NULL;
48040+ if (!par->ypan) {
48041+ pax_open_kernel();
48042+ *(void **)&info->fbops->fb_pan_display = NULL;
48043+ pax_close_kernel();
48044+ }
48045 }
48046
48047 static void uvesafb_init_mtrr(struct fb_info *info)
48048@@ -1836,6 +1866,11 @@ out:
48049 if (par->vbe_modes)
48050 kfree(par->vbe_modes);
48051
48052+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48053+ if (par->pmi_code)
48054+ module_free_exec(NULL, par->pmi_code);
48055+#endif
48056+
48057 framebuffer_release(info);
48058 return err;
48059 }
48060@@ -1862,6 +1897,12 @@ static int uvesafb_remove(struct platform_device *dev)
48061 kfree(par->vbe_state_orig);
48062 if (par->vbe_state_saved)
48063 kfree(par->vbe_state_saved);
48064+
48065+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48066+ if (par->pmi_code)
48067+ module_free_exec(NULL, par->pmi_code);
48068+#endif
48069+
48070 }
48071
48072 framebuffer_release(info);
48073diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
48074index 501b340..d80aa17 100644
48075--- a/drivers/video/vesafb.c
48076+++ b/drivers/video/vesafb.c
48077@@ -9,6 +9,7 @@
48078 */
48079
48080 #include <linux/module.h>
48081+#include <linux/moduleloader.h>
48082 #include <linux/kernel.h>
48083 #include <linux/errno.h>
48084 #include <linux/string.h>
48085@@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
48086 static int vram_total __initdata; /* Set total amount of memory */
48087 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
48088 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
48089-static void (*pmi_start)(void) __read_mostly;
48090-static void (*pmi_pal) (void) __read_mostly;
48091+static void (*pmi_start)(void) __read_only;
48092+static void (*pmi_pal) (void) __read_only;
48093 static int depth __read_mostly;
48094 static int vga_compat __read_mostly;
48095 /* --------------------------------------------------------------------- */
48096@@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
48097 unsigned int size_vmode;
48098 unsigned int size_remap;
48099 unsigned int size_total;
48100+ void *pmi_code = NULL;
48101
48102 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
48103 return -ENODEV;
48104@@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
48105 size_remap = size_total;
48106 vesafb_fix.smem_len = size_remap;
48107
48108-#ifndef __i386__
48109- screen_info.vesapm_seg = 0;
48110-#endif
48111-
48112 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
48113 printk(KERN_WARNING
48114 "vesafb: cannot reserve video memory at 0x%lx\n",
48115@@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
48116 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
48117 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
48118
48119+#ifdef __i386__
48120+
48121+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48122+ pmi_code = module_alloc_exec(screen_info.vesapm_size);
48123+ if (!pmi_code)
48124+#elif !defined(CONFIG_PAX_KERNEXEC)
48125+ if (0)
48126+#endif
48127+
48128+#endif
48129+ screen_info.vesapm_seg = 0;
48130+
48131 if (screen_info.vesapm_seg) {
48132- printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
48133- screen_info.vesapm_seg,screen_info.vesapm_off);
48134+ printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
48135+ screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
48136 }
48137
48138 if (screen_info.vesapm_seg < 0xc000)
48139@@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
48140
48141 if (ypan || pmi_setpal) {
48142 unsigned short *pmi_base;
48143+
48144 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
48145- pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
48146- pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
48147+
48148+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48149+ pax_open_kernel();
48150+ memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
48151+#else
48152+ pmi_code = pmi_base;
48153+#endif
48154+
48155+ pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
48156+ pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
48157+
48158+#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48159+ pmi_start = ktva_ktla(pmi_start);
48160+ pmi_pal = ktva_ktla(pmi_pal);
48161+ pax_close_kernel();
48162+#endif
48163+
48164 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
48165 if (pmi_base[3]) {
48166 printk(KERN_INFO "vesafb: pmi: ports = ");
48167@@ -472,8 +498,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48168 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
48169 (ypan ? FBINFO_HWACCEL_YPAN : 0);
48170
48171- if (!ypan)
48172- info->fbops->fb_pan_display = NULL;
48173+ if (!ypan) {
48174+ pax_open_kernel();
48175+ *(void **)&info->fbops->fb_pan_display = NULL;
48176+ pax_close_kernel();
48177+ }
48178
48179 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
48180 err = -ENOMEM;
48181@@ -488,6 +517,11 @@ static int __init vesafb_probe(struct platform_device *dev)
48182 info->node, info->fix.id);
48183 return 0;
48184 err:
48185+
48186+#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
48187+ module_free_exec(NULL, pmi_code);
48188+#endif
48189+
48190 if (info->screen_base)
48191 iounmap(info->screen_base);
48192 framebuffer_release(info);
48193diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
48194index 88714ae..16c2e11 100644
48195--- a/drivers/video/via/via_clock.h
48196+++ b/drivers/video/via/via_clock.h
48197@@ -56,7 +56,7 @@ struct via_clock {
48198
48199 void (*set_engine_pll_state)(u8 state);
48200 void (*set_engine_pll)(struct via_pll_config config);
48201-};
48202+} __no_const;
48203
48204
48205 static inline u32 get_pll_internal_frequency(u32 ref_freq,
48206diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
48207index fef20db..d28b1ab 100644
48208--- a/drivers/xen/xenfs/xenstored.c
48209+++ b/drivers/xen/xenfs/xenstored.c
48210@@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
48211 static int xsd_kva_open(struct inode *inode, struct file *file)
48212 {
48213 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
48214+#ifdef CONFIG_GRKERNSEC_HIDESYM
48215+ NULL);
48216+#else
48217 xen_store_interface);
48218+#endif
48219+
48220 if (!file->private_data)
48221 return -ENOMEM;
48222 return 0;
48223diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
48224index 0ad61c6..f198bd7 100644
48225--- a/fs/9p/vfs_addr.c
48226+++ b/fs/9p/vfs_addr.c
48227@@ -185,7 +185,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
48228
48229 retval = v9fs_file_write_internal(inode,
48230 v9inode->writeback_fid,
48231- (__force const char __user *)buffer,
48232+ (const char __force_user *)buffer,
48233 len, &offset, 0);
48234 if (retval > 0)
48235 retval = 0;
48236diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
48237index d86edc8..40ff2fb 100644
48238--- a/fs/9p/vfs_inode.c
48239+++ b/fs/9p/vfs_inode.c
48240@@ -1314,7 +1314,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
48241 void
48242 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48243 {
48244- char *s = nd_get_link(nd);
48245+ const char *s = nd_get_link(nd);
48246
48247 p9_debug(P9_DEBUG_VFS, " %s %s\n",
48248 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
48249diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
48250index 0efd152..b5802ad 100644
48251--- a/fs/Kconfig.binfmt
48252+++ b/fs/Kconfig.binfmt
48253@@ -89,7 +89,7 @@ config HAVE_AOUT
48254
48255 config BINFMT_AOUT
48256 tristate "Kernel support for a.out and ECOFF binaries"
48257- depends on HAVE_AOUT
48258+ depends on HAVE_AOUT && BROKEN
48259 ---help---
48260 A.out (Assembler.OUTput) is a set of formats for libraries and
48261 executables used in the earliest versions of UNIX. Linux used
48262diff --git a/fs/aio.c b/fs/aio.c
48263index 1dc8786..d3b29e8 100644
48264--- a/fs/aio.c
48265+++ b/fs/aio.c
48266@@ -111,7 +111,7 @@ static int aio_setup_ring(struct kioctx *ctx)
48267 size += sizeof(struct io_event) * nr_events;
48268 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
48269
48270- if (nr_pages < 0)
48271+ if (nr_pages <= 0)
48272 return -EINVAL;
48273
48274 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
48275@@ -1375,18 +1375,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
48276 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48277 {
48278 ssize_t ret;
48279+ struct iovec iovstack;
48280
48281 #ifdef CONFIG_COMPAT
48282 if (compat)
48283 ret = compat_rw_copy_check_uvector(type,
48284 (struct compat_iovec __user *)kiocb->ki_buf,
48285- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48286+ kiocb->ki_nbytes, 1, &iovstack,
48287 &kiocb->ki_iovec);
48288 else
48289 #endif
48290 ret = rw_copy_check_uvector(type,
48291 (struct iovec __user *)kiocb->ki_buf,
48292- kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
48293+ kiocb->ki_nbytes, 1, &iovstack,
48294 &kiocb->ki_iovec);
48295 if (ret < 0)
48296 goto out;
48297@@ -1395,6 +1396,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
48298 if (ret < 0)
48299 goto out;
48300
48301+ if (kiocb->ki_iovec == &iovstack) {
48302+ kiocb->ki_inline_vec = iovstack;
48303+ kiocb->ki_iovec = &kiocb->ki_inline_vec;
48304+ }
48305 kiocb->ki_nr_segs = kiocb->ki_nbytes;
48306 kiocb->ki_cur_seg = 0;
48307 /* ki_nbytes/left now reflect bytes instead of segs */
48308diff --git a/fs/attr.c b/fs/attr.c
48309index 1449adb..a2038c2 100644
48310--- a/fs/attr.c
48311+++ b/fs/attr.c
48312@@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
48313 unsigned long limit;
48314
48315 limit = rlimit(RLIMIT_FSIZE);
48316+ gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
48317 if (limit != RLIM_INFINITY && offset > limit)
48318 goto out_sig;
48319 if (offset > inode->i_sb->s_maxbytes)
48320diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
48321index 3db70da..7aeec5b 100644
48322--- a/fs/autofs4/waitq.c
48323+++ b/fs/autofs4/waitq.c
48324@@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
48325 {
48326 unsigned long sigpipe, flags;
48327 mm_segment_t fs;
48328- const char *data = (const char *)addr;
48329+ const char __user *data = (const char __force_user *)addr;
48330 ssize_t wr = 0;
48331
48332 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
48333@@ -346,6 +346,10 @@ static int validate_request(struct autofs_wait_queue **wait,
48334 return 1;
48335 }
48336
48337+#ifdef CONFIG_GRKERNSEC_HIDESYM
48338+static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
48339+#endif
48340+
48341 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48342 enum autofs_notify notify)
48343 {
48344@@ -379,7 +383,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
48345
48346 /* If this is a direct mount request create a dummy name */
48347 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
48348+#ifdef CONFIG_GRKERNSEC_HIDESYM
48349+ /* this name does get written to userland via autofs4_write() */
48350+ qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
48351+#else
48352 qstr.len = sprintf(name, "%p", dentry);
48353+#endif
48354 else {
48355 qstr.len = autofs4_getpath(sbi, dentry, &name);
48356 if (!qstr.len) {
48357diff --git a/fs/befs/endian.h b/fs/befs/endian.h
48358index 2722387..c8dd2a7 100644
48359--- a/fs/befs/endian.h
48360+++ b/fs/befs/endian.h
48361@@ -11,7 +11,7 @@
48362
48363 #include <asm/byteorder.h>
48364
48365-static inline u64
48366+static inline u64 __intentional_overflow(-1)
48367 fs64_to_cpu(const struct super_block *sb, fs64 n)
48368 {
48369 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48370@@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
48371 return (__force fs64)cpu_to_be64(n);
48372 }
48373
48374-static inline u32
48375+static inline u32 __intentional_overflow(-1)
48376 fs32_to_cpu(const struct super_block *sb, fs32 n)
48377 {
48378 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
48379diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
48380index 8615ee8..388ed68 100644
48381--- a/fs/befs/linuxvfs.c
48382+++ b/fs/befs/linuxvfs.c
48383@@ -510,7 +510,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
48384 {
48385 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
48386 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
48387- char *link = nd_get_link(nd);
48388+ const char *link = nd_get_link(nd);
48389 if (!IS_ERR(link))
48390 kfree(link);
48391 }
48392diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
48393index bbc8f88..7c7ac97 100644
48394--- a/fs/binfmt_aout.c
48395+++ b/fs/binfmt_aout.c
48396@@ -16,6 +16,7 @@
48397 #include <linux/string.h>
48398 #include <linux/fs.h>
48399 #include <linux/file.h>
48400+#include <linux/security.h>
48401 #include <linux/stat.h>
48402 #include <linux/fcntl.h>
48403 #include <linux/ptrace.h>
48404@@ -59,6 +60,8 @@ static int aout_core_dump(struct coredump_params *cprm)
48405 #endif
48406 # define START_STACK(u) ((void __user *)u.start_stack)
48407
48408+ memset(&dump, 0, sizeof(dump));
48409+
48410 fs = get_fs();
48411 set_fs(KERNEL_DS);
48412 has_dumped = 1;
48413@@ -70,10 +73,12 @@ static int aout_core_dump(struct coredump_params *cprm)
48414
48415 /* If the size of the dump file exceeds the rlimit, then see what would happen
48416 if we wrote the stack, but not the data area. */
48417+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
48418 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
48419 dump.u_dsize = 0;
48420
48421 /* Make sure we have enough room to write the stack and data areas. */
48422+ gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
48423 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
48424 dump.u_ssize = 0;
48425
48426@@ -234,6 +239,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
48427 rlim = rlimit(RLIMIT_DATA);
48428 if (rlim >= RLIM_INFINITY)
48429 rlim = ~0;
48430+
48431+ gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
48432 if (ex.a_data + ex.a_bss > rlim)
48433 return -ENOMEM;
48434
48435@@ -268,6 +275,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
48436
48437 install_exec_creds(bprm);
48438
48439+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48440+ current->mm->pax_flags = 0UL;
48441+#endif
48442+
48443+#ifdef CONFIG_PAX_PAGEEXEC
48444+ if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
48445+ current->mm->pax_flags |= MF_PAX_PAGEEXEC;
48446+
48447+#ifdef CONFIG_PAX_EMUTRAMP
48448+ if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
48449+ current->mm->pax_flags |= MF_PAX_EMUTRAMP;
48450+#endif
48451+
48452+#ifdef CONFIG_PAX_MPROTECT
48453+ if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
48454+ current->mm->pax_flags |= MF_PAX_MPROTECT;
48455+#endif
48456+
48457+ }
48458+#endif
48459+
48460 if (N_MAGIC(ex) == OMAGIC) {
48461 unsigned long text_addr, map_size;
48462 loff_t pos;
48463@@ -333,7 +361,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
48464 }
48465
48466 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
48467- PROT_READ | PROT_WRITE | PROT_EXEC,
48468+ PROT_READ | PROT_WRITE,
48469 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
48470 fd_offset + ex.a_text);
48471 if (error != N_DATADDR(ex)) {
48472diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
48473index 86af964..5d53bf6 100644
48474--- a/fs/binfmt_elf.c
48475+++ b/fs/binfmt_elf.c
48476@@ -34,6 +34,7 @@
48477 #include <linux/utsname.h>
48478 #include <linux/coredump.h>
48479 #include <linux/sched.h>
48480+#include <linux/xattr.h>
48481 #include <asm/uaccess.h>
48482 #include <asm/param.h>
48483 #include <asm/page.h>
48484@@ -60,6 +61,10 @@ static int elf_core_dump(struct coredump_params *cprm);
48485 #define elf_core_dump NULL
48486 #endif
48487
48488+#ifdef CONFIG_PAX_MPROTECT
48489+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
48490+#endif
48491+
48492 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
48493 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
48494 #else
48495@@ -79,6 +84,11 @@ static struct linux_binfmt elf_format = {
48496 .load_binary = load_elf_binary,
48497 .load_shlib = load_elf_library,
48498 .core_dump = elf_core_dump,
48499+
48500+#ifdef CONFIG_PAX_MPROTECT
48501+ .handle_mprotect= elf_handle_mprotect,
48502+#endif
48503+
48504 .min_coredump = ELF_EXEC_PAGESIZE,
48505 };
48506
48507@@ -86,6 +96,8 @@ static struct linux_binfmt elf_format = {
48508
48509 static int set_brk(unsigned long start, unsigned long end)
48510 {
48511+ unsigned long e = end;
48512+
48513 start = ELF_PAGEALIGN(start);
48514 end = ELF_PAGEALIGN(end);
48515 if (end > start) {
48516@@ -94,7 +106,7 @@ static int set_brk(unsigned long start, unsigned long end)
48517 if (BAD_ADDR(addr))
48518 return addr;
48519 }
48520- current->mm->start_brk = current->mm->brk = end;
48521+ current->mm->start_brk = current->mm->brk = e;
48522 return 0;
48523 }
48524
48525@@ -155,12 +167,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48526 elf_addr_t __user *u_rand_bytes;
48527 const char *k_platform = ELF_PLATFORM;
48528 const char *k_base_platform = ELF_BASE_PLATFORM;
48529- unsigned char k_rand_bytes[16];
48530+ u32 k_rand_bytes[4];
48531 int items;
48532 elf_addr_t *elf_info;
48533 int ei_index = 0;
48534 const struct cred *cred = current_cred();
48535 struct vm_area_struct *vma;
48536+ unsigned long saved_auxv[AT_VECTOR_SIZE];
48537
48538 /*
48539 * In some cases (e.g. Hyper-Threading), we want to avoid L1
48540@@ -202,8 +215,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48541 * Generate 16 random bytes for userspace PRNG seeding.
48542 */
48543 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
48544- u_rand_bytes = (elf_addr_t __user *)
48545- STACK_ALLOC(p, sizeof(k_rand_bytes));
48546+ srandom32(k_rand_bytes[0] ^ random32());
48547+ srandom32(k_rand_bytes[1] ^ random32());
48548+ srandom32(k_rand_bytes[2] ^ random32());
48549+ srandom32(k_rand_bytes[3] ^ random32());
48550+ p = STACK_ROUND(p, sizeof(k_rand_bytes));
48551+ u_rand_bytes = (elf_addr_t __user *) p;
48552 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
48553 return -EFAULT;
48554
48555@@ -315,9 +332,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
48556 return -EFAULT;
48557 current->mm->env_end = p;
48558
48559+ memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
48560+
48561 /* Put the elf_info on the stack in the right place. */
48562 sp = (elf_addr_t __user *)envp + 1;
48563- if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
48564+ if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
48565 return -EFAULT;
48566 return 0;
48567 }
48568@@ -385,15 +404,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
48569 an ELF header */
48570
48571 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48572- struct file *interpreter, unsigned long *interp_map_addr,
48573- unsigned long no_base)
48574+ struct file *interpreter, unsigned long no_base)
48575 {
48576 struct elf_phdr *elf_phdata;
48577 struct elf_phdr *eppnt;
48578- unsigned long load_addr = 0;
48579+ unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
48580 int load_addr_set = 0;
48581 unsigned long last_bss = 0, elf_bss = 0;
48582- unsigned long error = ~0UL;
48583+ unsigned long error = -EINVAL;
48584 unsigned long total_size;
48585 int retval, i, size;
48586
48587@@ -439,6 +457,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48588 goto out_close;
48589 }
48590
48591+#ifdef CONFIG_PAX_SEGMEXEC
48592+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
48593+ pax_task_size = SEGMEXEC_TASK_SIZE;
48594+#endif
48595+
48596 eppnt = elf_phdata;
48597 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
48598 if (eppnt->p_type == PT_LOAD) {
48599@@ -462,8 +485,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48600 map_addr = elf_map(interpreter, load_addr + vaddr,
48601 eppnt, elf_prot, elf_type, total_size);
48602 total_size = 0;
48603- if (!*interp_map_addr)
48604- *interp_map_addr = map_addr;
48605 error = map_addr;
48606 if (BAD_ADDR(map_addr))
48607 goto out_close;
48608@@ -482,8 +503,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
48609 k = load_addr + eppnt->p_vaddr;
48610 if (BAD_ADDR(k) ||
48611 eppnt->p_filesz > eppnt->p_memsz ||
48612- eppnt->p_memsz > TASK_SIZE ||
48613- TASK_SIZE - eppnt->p_memsz < k) {
48614+ eppnt->p_memsz > pax_task_size ||
48615+ pax_task_size - eppnt->p_memsz < k) {
48616 error = -ENOMEM;
48617 goto out_close;
48618 }
48619@@ -535,6 +556,315 @@ out:
48620 return error;
48621 }
48622
48623+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48624+#ifdef CONFIG_PAX_SOFTMODE
48625+static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
48626+{
48627+ unsigned long pax_flags = 0UL;
48628+
48629+#ifdef CONFIG_PAX_PAGEEXEC
48630+ if (elf_phdata->p_flags & PF_PAGEEXEC)
48631+ pax_flags |= MF_PAX_PAGEEXEC;
48632+#endif
48633+
48634+#ifdef CONFIG_PAX_SEGMEXEC
48635+ if (elf_phdata->p_flags & PF_SEGMEXEC)
48636+ pax_flags |= MF_PAX_SEGMEXEC;
48637+#endif
48638+
48639+#ifdef CONFIG_PAX_EMUTRAMP
48640+ if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48641+ pax_flags |= MF_PAX_EMUTRAMP;
48642+#endif
48643+
48644+#ifdef CONFIG_PAX_MPROTECT
48645+ if (elf_phdata->p_flags & PF_MPROTECT)
48646+ pax_flags |= MF_PAX_MPROTECT;
48647+#endif
48648+
48649+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48650+ if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
48651+ pax_flags |= MF_PAX_RANDMMAP;
48652+#endif
48653+
48654+ return pax_flags;
48655+}
48656+#endif
48657+
48658+static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
48659+{
48660+ unsigned long pax_flags = 0UL;
48661+
48662+#ifdef CONFIG_PAX_PAGEEXEC
48663+ if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
48664+ pax_flags |= MF_PAX_PAGEEXEC;
48665+#endif
48666+
48667+#ifdef CONFIG_PAX_SEGMEXEC
48668+ if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
48669+ pax_flags |= MF_PAX_SEGMEXEC;
48670+#endif
48671+
48672+#ifdef CONFIG_PAX_EMUTRAMP
48673+ if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
48674+ pax_flags |= MF_PAX_EMUTRAMP;
48675+#endif
48676+
48677+#ifdef CONFIG_PAX_MPROTECT
48678+ if (!(elf_phdata->p_flags & PF_NOMPROTECT))
48679+ pax_flags |= MF_PAX_MPROTECT;
48680+#endif
48681+
48682+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48683+ if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
48684+ pax_flags |= MF_PAX_RANDMMAP;
48685+#endif
48686+
48687+ return pax_flags;
48688+}
48689+#endif
48690+
48691+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48692+#ifdef CONFIG_PAX_SOFTMODE
48693+static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
48694+{
48695+ unsigned long pax_flags = 0UL;
48696+
48697+#ifdef CONFIG_PAX_PAGEEXEC
48698+ if (pax_flags_softmode & MF_PAX_PAGEEXEC)
48699+ pax_flags |= MF_PAX_PAGEEXEC;
48700+#endif
48701+
48702+#ifdef CONFIG_PAX_SEGMEXEC
48703+ if (pax_flags_softmode & MF_PAX_SEGMEXEC)
48704+ pax_flags |= MF_PAX_SEGMEXEC;
48705+#endif
48706+
48707+#ifdef CONFIG_PAX_EMUTRAMP
48708+ if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
48709+ pax_flags |= MF_PAX_EMUTRAMP;
48710+#endif
48711+
48712+#ifdef CONFIG_PAX_MPROTECT
48713+ if (pax_flags_softmode & MF_PAX_MPROTECT)
48714+ pax_flags |= MF_PAX_MPROTECT;
48715+#endif
48716+
48717+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48718+ if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
48719+ pax_flags |= MF_PAX_RANDMMAP;
48720+#endif
48721+
48722+ return pax_flags;
48723+}
48724+#endif
48725+
48726+static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
48727+{
48728+ unsigned long pax_flags = 0UL;
48729+
48730+#ifdef CONFIG_PAX_PAGEEXEC
48731+ if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
48732+ pax_flags |= MF_PAX_PAGEEXEC;
48733+#endif
48734+
48735+#ifdef CONFIG_PAX_SEGMEXEC
48736+ if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
48737+ pax_flags |= MF_PAX_SEGMEXEC;
48738+#endif
48739+
48740+#ifdef CONFIG_PAX_EMUTRAMP
48741+ if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
48742+ pax_flags |= MF_PAX_EMUTRAMP;
48743+#endif
48744+
48745+#ifdef CONFIG_PAX_MPROTECT
48746+ if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
48747+ pax_flags |= MF_PAX_MPROTECT;
48748+#endif
48749+
48750+#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
48751+ if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
48752+ pax_flags |= MF_PAX_RANDMMAP;
48753+#endif
48754+
48755+ return pax_flags;
48756+}
48757+#endif
48758+
48759+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48760+static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
48761+{
48762+ unsigned long pax_flags = 0UL;
48763+
48764+#ifdef CONFIG_PAX_EI_PAX
48765+
48766+#ifdef CONFIG_PAX_PAGEEXEC
48767+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
48768+ pax_flags |= MF_PAX_PAGEEXEC;
48769+#endif
48770+
48771+#ifdef CONFIG_PAX_SEGMEXEC
48772+ if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
48773+ pax_flags |= MF_PAX_SEGMEXEC;
48774+#endif
48775+
48776+#ifdef CONFIG_PAX_EMUTRAMP
48777+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
48778+ pax_flags |= MF_PAX_EMUTRAMP;
48779+#endif
48780+
48781+#ifdef CONFIG_PAX_MPROTECT
48782+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
48783+ pax_flags |= MF_PAX_MPROTECT;
48784+#endif
48785+
48786+#ifdef CONFIG_PAX_ASLR
48787+ if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
48788+ pax_flags |= MF_PAX_RANDMMAP;
48789+#endif
48790+
48791+#else
48792+
48793+#ifdef CONFIG_PAX_PAGEEXEC
48794+ pax_flags |= MF_PAX_PAGEEXEC;
48795+#endif
48796+
48797+#ifdef CONFIG_PAX_SEGMEXEC
48798+ pax_flags |= MF_PAX_SEGMEXEC;
48799+#endif
48800+
48801+#ifdef CONFIG_PAX_MPROTECT
48802+ pax_flags |= MF_PAX_MPROTECT;
48803+#endif
48804+
48805+#ifdef CONFIG_PAX_RANDMMAP
48806+ if (randomize_va_space)
48807+ pax_flags |= MF_PAX_RANDMMAP;
48808+#endif
48809+
48810+#endif
48811+
48812+ return pax_flags;
48813+}
48814+
48815+static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
48816+{
48817+
48818+#ifdef CONFIG_PAX_PT_PAX_FLAGS
48819+ unsigned long i;
48820+
48821+ for (i = 0UL; i < elf_ex->e_phnum; i++)
48822+ if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
48823+ if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
48824+ ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
48825+ ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
48826+ ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
48827+ ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
48828+ return ~0UL;
48829+
48830+#ifdef CONFIG_PAX_SOFTMODE
48831+ if (pax_softmode)
48832+ return pax_parse_pt_pax_softmode(&elf_phdata[i]);
48833+ else
48834+#endif
48835+
48836+ return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
48837+ break;
48838+ }
48839+#endif
48840+
48841+ return ~0UL;
48842+}
48843+
48844+static unsigned long pax_parse_xattr_pax(struct file * const file)
48845+{
48846+
48847+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
48848+ ssize_t xattr_size, i;
48849+ unsigned char xattr_value[sizeof("pemrs") - 1];
48850+ unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
48851+
48852+ xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
48853+ if (xattr_size <= 0 || xattr_size > sizeof xattr_value)
48854+ return ~0UL;
48855+
48856+ for (i = 0; i < xattr_size; i++)
48857+ switch (xattr_value[i]) {
48858+ default:
48859+ return ~0UL;
48860+
48861+#define parse_flag(option1, option2, flag) \
48862+ case option1: \
48863+ if (pax_flags_hardmode & MF_PAX_##flag) \
48864+ return ~0UL; \
48865+ pax_flags_hardmode |= MF_PAX_##flag; \
48866+ break; \
48867+ case option2: \
48868+ if (pax_flags_softmode & MF_PAX_##flag) \
48869+ return ~0UL; \
48870+ pax_flags_softmode |= MF_PAX_##flag; \
48871+ break;
48872+
48873+ parse_flag('p', 'P', PAGEEXEC);
48874+ parse_flag('e', 'E', EMUTRAMP);
48875+ parse_flag('m', 'M', MPROTECT);
48876+ parse_flag('r', 'R', RANDMMAP);
48877+ parse_flag('s', 'S', SEGMEXEC);
48878+
48879+#undef parse_flag
48880+ }
48881+
48882+ if (pax_flags_hardmode & pax_flags_softmode)
48883+ return ~0UL;
48884+
48885+#ifdef CONFIG_PAX_SOFTMODE
48886+ if (pax_softmode)
48887+ return pax_parse_xattr_pax_softmode(pax_flags_softmode);
48888+ else
48889+#endif
48890+
48891+ return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
48892+#else
48893+ return ~0UL;
48894+#endif
48895+
48896+}
48897+
48898+static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
48899+{
48900+ unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
48901+
48902+ pax_flags = pax_parse_ei_pax(elf_ex);
48903+ pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
48904+ xattr_pax_flags = pax_parse_xattr_pax(file);
48905+
48906+ if (pt_pax_flags == ~0UL)
48907+ pt_pax_flags = xattr_pax_flags;
48908+ else if (xattr_pax_flags == ~0UL)
48909+ xattr_pax_flags = pt_pax_flags;
48910+ if (pt_pax_flags != xattr_pax_flags)
48911+ return -EINVAL;
48912+ if (pt_pax_flags != ~0UL)
48913+ pax_flags = pt_pax_flags;
48914+
48915+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
48916+ if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
48917+ if ((__supported_pte_mask & _PAGE_NX))
48918+ pax_flags &= ~MF_PAX_SEGMEXEC;
48919+ else
48920+ pax_flags &= ~MF_PAX_PAGEEXEC;
48921+ }
48922+#endif
48923+
48924+ if (0 > pax_check_flags(&pax_flags))
48925+ return -EINVAL;
48926+
48927+ current->mm->pax_flags = pax_flags;
48928+ return 0;
48929+}
48930+#endif
48931+
48932 /*
48933 * These are the functions used to load ELF style executables and shared
48934 * libraries. There is no binary dependent code anywhere else.
48935@@ -551,6 +881,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
48936 {
48937 unsigned int random_variable = 0;
48938
48939+#ifdef CONFIG_PAX_RANDUSTACK
48940+ if (current->mm->pax_flags & MF_PAX_RANDMMAP)
48941+ return stack_top - current->mm->delta_stack;
48942+#endif
48943+
48944 if ((current->flags & PF_RANDOMIZE) &&
48945 !(current->personality & ADDR_NO_RANDOMIZE)) {
48946 random_variable = get_random_int() & STACK_RND_MASK;
48947@@ -569,7 +904,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
48948 unsigned long load_addr = 0, load_bias = 0;
48949 int load_addr_set = 0;
48950 char * elf_interpreter = NULL;
48951- unsigned long error;
48952+ unsigned long error = 0;
48953 struct elf_phdr *elf_ppnt, *elf_phdata;
48954 unsigned long elf_bss, elf_brk;
48955 int retval, i;
48956@@ -579,12 +914,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
48957 unsigned long start_code, end_code, start_data, end_data;
48958 unsigned long reloc_func_desc __maybe_unused = 0;
48959 int executable_stack = EXSTACK_DEFAULT;
48960- unsigned long def_flags = 0;
48961 struct pt_regs *regs = current_pt_regs();
48962 struct {
48963 struct elfhdr elf_ex;
48964 struct elfhdr interp_elf_ex;
48965 } *loc;
48966+ unsigned long pax_task_size = TASK_SIZE;
48967
48968 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
48969 if (!loc) {
48970@@ -720,11 +1055,81 @@ static int load_elf_binary(struct linux_binprm *bprm)
48971 goto out_free_dentry;
48972
48973 /* OK, This is the point of no return */
48974- current->mm->def_flags = def_flags;
48975+
48976+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48977+ current->mm->pax_flags = 0UL;
48978+#endif
48979+
48980+#ifdef CONFIG_PAX_DLRESOLVE
48981+ current->mm->call_dl_resolve = 0UL;
48982+#endif
48983+
48984+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
48985+ current->mm->call_syscall = 0UL;
48986+#endif
48987+
48988+#ifdef CONFIG_PAX_ASLR
48989+ current->mm->delta_mmap = 0UL;
48990+ current->mm->delta_stack = 0UL;
48991+#endif
48992+
48993+ current->mm->def_flags = 0;
48994+
48995+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48996+ if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
48997+ send_sig(SIGKILL, current, 0);
48998+ goto out_free_dentry;
48999+ }
49000+#endif
49001+
49002+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49003+ pax_set_initial_flags(bprm);
49004+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
49005+ if (pax_set_initial_flags_func)
49006+ (pax_set_initial_flags_func)(bprm);
49007+#endif
49008+
49009+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49010+ if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
49011+ current->mm->context.user_cs_limit = PAGE_SIZE;
49012+ current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
49013+ }
49014+#endif
49015+
49016+#ifdef CONFIG_PAX_SEGMEXEC
49017+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
49018+ current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
49019+ current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
49020+ pax_task_size = SEGMEXEC_TASK_SIZE;
49021+ current->mm->def_flags |= VM_NOHUGEPAGE;
49022+ }
49023+#endif
49024+
49025+#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
49026+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49027+ set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
49028+ put_cpu();
49029+ }
49030+#endif
49031
49032 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
49033 may depend on the personality. */
49034 SET_PERSONALITY(loc->elf_ex);
49035+
49036+#ifdef CONFIG_PAX_ASLR
49037+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49038+ current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
49039+ current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
49040+ }
49041+#endif
49042+
49043+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49044+ if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49045+ executable_stack = EXSTACK_DISABLE_X;
49046+ current->personality &= ~READ_IMPLIES_EXEC;
49047+ } else
49048+#endif
49049+
49050 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
49051 current->personality |= READ_IMPLIES_EXEC;
49052
49053@@ -815,6 +1220,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
49054 #else
49055 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
49056 #endif
49057+
49058+#ifdef CONFIG_PAX_RANDMMAP
49059+ /* PaX: randomize base address at the default exe base if requested */
49060+ if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
49061+#ifdef CONFIG_SPARC64
49062+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
49063+#else
49064+ load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
49065+#endif
49066+ load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
49067+ elf_flags |= MAP_FIXED;
49068+ }
49069+#endif
49070+
49071 }
49072
49073 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
49074@@ -847,9 +1266,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
49075 * allowed task size. Note that p_filesz must always be
49076 * <= p_memsz so it is only necessary to check p_memsz.
49077 */
49078- if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49079- elf_ppnt->p_memsz > TASK_SIZE ||
49080- TASK_SIZE - elf_ppnt->p_memsz < k) {
49081+ if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
49082+ elf_ppnt->p_memsz > pax_task_size ||
49083+ pax_task_size - elf_ppnt->p_memsz < k) {
49084 /* set_brk can never work. Avoid overflows. */
49085 send_sig(SIGKILL, current, 0);
49086 retval = -EINVAL;
49087@@ -888,17 +1307,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
49088 goto out_free_dentry;
49089 }
49090 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
49091- send_sig(SIGSEGV, current, 0);
49092- retval = -EFAULT; /* Nobody gets to see this, but.. */
49093- goto out_free_dentry;
49094+ /*
49095+ * This bss-zeroing can fail if the ELF
49096+ * file specifies odd protections. So
49097+ * we don't check the return value
49098+ */
49099 }
49100
49101+#ifdef CONFIG_PAX_RANDMMAP
49102+ if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
49103+ unsigned long start, size, flags;
49104+ vm_flags_t vm_flags;
49105+
49106+ start = ELF_PAGEALIGN(elf_brk);
49107+ size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
49108+ flags = MAP_FIXED | MAP_PRIVATE;
49109+ vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
49110+
49111+ down_write(&current->mm->mmap_sem);
49112+ start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
49113+ retval = -ENOMEM;
49114+ if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
49115+// if (current->personality & ADDR_NO_RANDOMIZE)
49116+// vm_flags |= VM_READ | VM_MAYREAD;
49117+ start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
49118+ retval = IS_ERR_VALUE(start) ? start : 0;
49119+ }
49120+ up_write(&current->mm->mmap_sem);
49121+ if (retval == 0)
49122+ retval = set_brk(start + size, start + size + PAGE_SIZE);
49123+ if (retval < 0) {
49124+ send_sig(SIGKILL, current, 0);
49125+ goto out_free_dentry;
49126+ }
49127+ }
49128+#endif
49129+
49130 if (elf_interpreter) {
49131- unsigned long interp_map_addr = 0;
49132-
49133 elf_entry = load_elf_interp(&loc->interp_elf_ex,
49134 interpreter,
49135- &interp_map_addr,
49136 load_bias);
49137 if (!IS_ERR((void *)elf_entry)) {
49138 /*
49139@@ -1120,7 +1567,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
49140 * Decide what to dump of a segment, part, all or none.
49141 */
49142 static unsigned long vma_dump_size(struct vm_area_struct *vma,
49143- unsigned long mm_flags)
49144+ unsigned long mm_flags, long signr)
49145 {
49146 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
49147
49148@@ -1158,7 +1605,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
49149 if (vma->vm_file == NULL)
49150 return 0;
49151
49152- if (FILTER(MAPPED_PRIVATE))
49153+ if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
49154 goto whole;
49155
49156 /*
49157@@ -1383,9 +1830,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
49158 {
49159 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
49160 int i = 0;
49161- do
49162+ do {
49163 i += 2;
49164- while (auxv[i - 2] != AT_NULL);
49165+ } while (auxv[i - 2] != AT_NULL);
49166 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
49167 }
49168
49169@@ -1394,7 +1841,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
49170 {
49171 mm_segment_t old_fs = get_fs();
49172 set_fs(KERNEL_DS);
49173- copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
49174+ copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
49175 set_fs(old_fs);
49176 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
49177 }
49178@@ -2015,14 +2462,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
49179 }
49180
49181 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
49182- unsigned long mm_flags)
49183+ struct coredump_params *cprm)
49184 {
49185 struct vm_area_struct *vma;
49186 size_t size = 0;
49187
49188 for (vma = first_vma(current, gate_vma); vma != NULL;
49189 vma = next_vma(vma, gate_vma))
49190- size += vma_dump_size(vma, mm_flags);
49191+ size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49192 return size;
49193 }
49194
49195@@ -2116,7 +2563,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49196
49197 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
49198
49199- offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
49200+ offset += elf_core_vma_data_size(gate_vma, cprm);
49201 offset += elf_core_extra_data_size();
49202 e_shoff = offset;
49203
49204@@ -2130,10 +2577,12 @@ static int elf_core_dump(struct coredump_params *cprm)
49205 offset = dataoff;
49206
49207 size += sizeof(*elf);
49208+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49209 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
49210 goto end_coredump;
49211
49212 size += sizeof(*phdr4note);
49213+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49214 if (size > cprm->limit
49215 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
49216 goto end_coredump;
49217@@ -2147,7 +2596,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49218 phdr.p_offset = offset;
49219 phdr.p_vaddr = vma->vm_start;
49220 phdr.p_paddr = 0;
49221- phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
49222+ phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49223 phdr.p_memsz = vma->vm_end - vma->vm_start;
49224 offset += phdr.p_filesz;
49225 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
49226@@ -2158,6 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49227 phdr.p_align = ELF_EXEC_PAGESIZE;
49228
49229 size += sizeof(phdr);
49230+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49231 if (size > cprm->limit
49232 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
49233 goto end_coredump;
49234@@ -2182,7 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49235 unsigned long addr;
49236 unsigned long end;
49237
49238- end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
49239+ end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
49240
49241 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
49242 struct page *page;
49243@@ -2191,6 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49244 page = get_dump_page(addr);
49245 if (page) {
49246 void *kaddr = kmap(page);
49247+ gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
49248 stop = ((size += PAGE_SIZE) > cprm->limit) ||
49249 !dump_write(cprm->file, kaddr,
49250 PAGE_SIZE);
49251@@ -2208,6 +2659,7 @@ static int elf_core_dump(struct coredump_params *cprm)
49252
49253 if (e_phnum == PN_XNUM) {
49254 size += sizeof(*shdr4extnum);
49255+ gr_learn_resource(current, RLIMIT_CORE, size, 1);
49256 if (size > cprm->limit
49257 || !dump_write(cprm->file, shdr4extnum,
49258 sizeof(*shdr4extnum)))
49259@@ -2228,6 +2680,97 @@ out:
49260
49261 #endif /* CONFIG_ELF_CORE */
49262
49263+#ifdef CONFIG_PAX_MPROTECT
49264+/* PaX: non-PIC ELF libraries need relocations on their executable segments
49265+ * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
49266+ * we'll remove VM_MAYWRITE for good on RELRO segments.
49267+ *
49268+ * The checks favour ld-linux.so behaviour which operates on a per ELF segment
49269+ * basis because we want to allow the common case and not the special ones.
49270+ */
49271+static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
49272+{
49273+ struct elfhdr elf_h;
49274+ struct elf_phdr elf_p;
49275+ unsigned long i;
49276+ unsigned long oldflags;
49277+ bool is_textrel_rw, is_textrel_rx, is_relro;
49278+
49279+ if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
49280+ return;
49281+
49282+ oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
49283+ newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
49284+
49285+#ifdef CONFIG_PAX_ELFRELOCS
49286+ /* possible TEXTREL */
49287+ is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
49288+ 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);
49289+#else
49290+ is_textrel_rw = false;
49291+ is_textrel_rx = false;
49292+#endif
49293+
49294+ /* possible RELRO */
49295+ is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
49296+
49297+ if (!is_textrel_rw && !is_textrel_rx && !is_relro)
49298+ return;
49299+
49300+ if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
49301+ memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
49302+
49303+#ifdef CONFIG_PAX_ETEXECRELOCS
49304+ ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49305+#else
49306+ ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
49307+#endif
49308+
49309+ (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
49310+ !elf_check_arch(&elf_h) ||
49311+ elf_h.e_phentsize != sizeof(struct elf_phdr) ||
49312+ elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
49313+ return;
49314+
49315+ for (i = 0UL; i < elf_h.e_phnum; i++) {
49316+ if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
49317+ return;
49318+ switch (elf_p.p_type) {
49319+ case PT_DYNAMIC:
49320+ if (!is_textrel_rw && !is_textrel_rx)
49321+ continue;
49322+ i = 0UL;
49323+ while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
49324+ elf_dyn dyn;
49325+
49326+ if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
49327+ return;
49328+ if (dyn.d_tag == DT_NULL)
49329+ return;
49330+ if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
49331+ gr_log_textrel(vma);
49332+ if (is_textrel_rw)
49333+ vma->vm_flags |= VM_MAYWRITE;
49334+ else
49335+ /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
49336+ vma->vm_flags &= ~VM_MAYWRITE;
49337+ return;
49338+ }
49339+ i++;
49340+ }
49341+ return;
49342+
49343+ case PT_GNU_RELRO:
49344+ if (!is_relro)
49345+ continue;
49346+ if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
49347+ vma->vm_flags &= ~VM_MAYWRITE;
49348+ return;
49349+ }
49350+ }
49351+}
49352+#endif
49353+
49354 static int __init init_elf_binfmt(void)
49355 {
49356 register_binfmt(&elf_format);
49357diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
49358index 2036d21..b0430d0 100644
49359--- a/fs/binfmt_flat.c
49360+++ b/fs/binfmt_flat.c
49361@@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
49362 realdatastart = (unsigned long) -ENOMEM;
49363 printk("Unable to allocate RAM for process data, errno %d\n",
49364 (int)-realdatastart);
49365+ down_write(&current->mm->mmap_sem);
49366 vm_munmap(textpos, text_len);
49367+ up_write(&current->mm->mmap_sem);
49368 ret = realdatastart;
49369 goto err;
49370 }
49371@@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49372 }
49373 if (IS_ERR_VALUE(result)) {
49374 printk("Unable to read data+bss, errno %d\n", (int)-result);
49375+ down_write(&current->mm->mmap_sem);
49376 vm_munmap(textpos, text_len);
49377 vm_munmap(realdatastart, len);
49378+ up_write(&current->mm->mmap_sem);
49379 ret = result;
49380 goto err;
49381 }
49382@@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
49383 }
49384 if (IS_ERR_VALUE(result)) {
49385 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
49386+ down_write(&current->mm->mmap_sem);
49387 vm_munmap(textpos, text_len + data_len + extra +
49388 MAX_SHARED_LIBS * sizeof(unsigned long));
49389+ up_write(&current->mm->mmap_sem);
49390 ret = result;
49391 goto err;
49392 }
49393diff --git a/fs/bio.c b/fs/bio.c
49394index b96fc6c..431d628 100644
49395--- a/fs/bio.c
49396+++ b/fs/bio.c
49397@@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
49398 /*
49399 * Overflow, abort
49400 */
49401- if (end < start)
49402+ if (end < start || end - start > INT_MAX - nr_pages)
49403 return ERR_PTR(-EINVAL);
49404
49405 nr_pages += end - start;
49406@@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
49407 /*
49408 * Overflow, abort
49409 */
49410- if (end < start)
49411+ if (end < start || end - start > INT_MAX - nr_pages)
49412 return ERR_PTR(-EINVAL);
49413
49414 nr_pages += end - start;
49415@@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
49416 const int read = bio_data_dir(bio) == READ;
49417 struct bio_map_data *bmd = bio->bi_private;
49418 int i;
49419- char *p = bmd->sgvecs[0].iov_base;
49420+ char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
49421
49422 __bio_for_each_segment(bvec, bio, i, 0) {
49423 char *addr = page_address(bvec->bv_page);
49424diff --git a/fs/block_dev.c b/fs/block_dev.c
49425index aae187a..fd790ba 100644
49426--- a/fs/block_dev.c
49427+++ b/fs/block_dev.c
49428@@ -652,7 +652,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
49429 else if (bdev->bd_contains == bdev)
49430 return true; /* is a whole device which isn't held */
49431
49432- else if (whole->bd_holder == bd_may_claim)
49433+ else if (whole->bd_holder == (void *)bd_may_claim)
49434 return true; /* is a partition of a device that is being partitioned */
49435 else if (whole->bd_holder != NULL)
49436 return false; /* is a partition of a held device */
49437diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
49438index ca9d8f1..8c0142d 100644
49439--- a/fs/btrfs/ctree.c
49440+++ b/fs/btrfs/ctree.c
49441@@ -1036,9 +1036,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
49442 free_extent_buffer(buf);
49443 add_root_to_dirty_list(root);
49444 } else {
49445- if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
49446- parent_start = parent->start;
49447- else
49448+ if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
49449+ if (parent)
49450+ parent_start = parent->start;
49451+ else
49452+ parent_start = 0;
49453+ } else
49454 parent_start = 0;
49455
49456 WARN_ON(trans->transid != btrfs_header_generation(parent));
49457diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
49458index f49b62f..07834ab 100644
49459--- a/fs/btrfs/ioctl.c
49460+++ b/fs/btrfs/ioctl.c
49461@@ -3077,9 +3077,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49462 for (i = 0; i < num_types; i++) {
49463 struct btrfs_space_info *tmp;
49464
49465+ /* Don't copy in more than we allocated */
49466 if (!slot_count)
49467 break;
49468
49469+ slot_count--;
49470+
49471 info = NULL;
49472 rcu_read_lock();
49473 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
49474@@ -3101,10 +3104,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
49475 memcpy(dest, &space, sizeof(space));
49476 dest++;
49477 space_args.total_spaces++;
49478- slot_count--;
49479 }
49480- if (!slot_count)
49481- break;
49482 }
49483 up_read(&info->groups_sem);
49484 }
49485diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
49486index f6b8859..54fe8c5 100644
49487--- a/fs/btrfs/super.c
49488+++ b/fs/btrfs/super.c
49489@@ -266,7 +266,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
49490 function, line, errstr);
49491 return;
49492 }
49493- ACCESS_ONCE(trans->transaction->aborted) = errno;
49494+ ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
49495 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
49496 }
49497 /*
49498diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
49499index 622f469..e8d2d55 100644
49500--- a/fs/cachefiles/bind.c
49501+++ b/fs/cachefiles/bind.c
49502@@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
49503 args);
49504
49505 /* start by checking things over */
49506- ASSERT(cache->fstop_percent >= 0 &&
49507- cache->fstop_percent < cache->fcull_percent &&
49508+ ASSERT(cache->fstop_percent < cache->fcull_percent &&
49509 cache->fcull_percent < cache->frun_percent &&
49510 cache->frun_percent < 100);
49511
49512- ASSERT(cache->bstop_percent >= 0 &&
49513- cache->bstop_percent < cache->bcull_percent &&
49514+ ASSERT(cache->bstop_percent < cache->bcull_percent &&
49515 cache->bcull_percent < cache->brun_percent &&
49516 cache->brun_percent < 100);
49517
49518diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
49519index 0a1467b..6a53245 100644
49520--- a/fs/cachefiles/daemon.c
49521+++ b/fs/cachefiles/daemon.c
49522@@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
49523 if (n > buflen)
49524 return -EMSGSIZE;
49525
49526- if (copy_to_user(_buffer, buffer, n) != 0)
49527+ if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
49528 return -EFAULT;
49529
49530 return n;
49531@@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
49532 if (test_bit(CACHEFILES_DEAD, &cache->flags))
49533 return -EIO;
49534
49535- if (datalen < 0 || datalen > PAGE_SIZE - 1)
49536+ if (datalen > PAGE_SIZE - 1)
49537 return -EOPNOTSUPP;
49538
49539 /* drag the command string into the kernel so we can parse it */
49540@@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
49541 if (args[0] != '%' || args[1] != '\0')
49542 return -EINVAL;
49543
49544- if (fstop < 0 || fstop >= cache->fcull_percent)
49545+ if (fstop >= cache->fcull_percent)
49546 return cachefiles_daemon_range_error(cache, args);
49547
49548 cache->fstop_percent = fstop;
49549@@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
49550 if (args[0] != '%' || args[1] != '\0')
49551 return -EINVAL;
49552
49553- if (bstop < 0 || bstop >= cache->bcull_percent)
49554+ if (bstop >= cache->bcull_percent)
49555 return cachefiles_daemon_range_error(cache, args);
49556
49557 cache->bstop_percent = bstop;
49558diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
49559index 4938251..7e01445 100644
49560--- a/fs/cachefiles/internal.h
49561+++ b/fs/cachefiles/internal.h
49562@@ -59,7 +59,7 @@ struct cachefiles_cache {
49563 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
49564 struct rb_root active_nodes; /* active nodes (can't be culled) */
49565 rwlock_t active_lock; /* lock for active_nodes */
49566- atomic_t gravecounter; /* graveyard uniquifier */
49567+ atomic_unchecked_t gravecounter; /* graveyard uniquifier */
49568 unsigned frun_percent; /* when to stop culling (% files) */
49569 unsigned fcull_percent; /* when to start culling (% files) */
49570 unsigned fstop_percent; /* when to stop allocating (% files) */
49571@@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
49572 * proc.c
49573 */
49574 #ifdef CONFIG_CACHEFILES_HISTOGRAM
49575-extern atomic_t cachefiles_lookup_histogram[HZ];
49576-extern atomic_t cachefiles_mkdir_histogram[HZ];
49577-extern atomic_t cachefiles_create_histogram[HZ];
49578+extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49579+extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49580+extern atomic_unchecked_t cachefiles_create_histogram[HZ];
49581
49582 extern int __init cachefiles_proc_init(void);
49583 extern void cachefiles_proc_cleanup(void);
49584 static inline
49585-void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
49586+void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
49587 {
49588 unsigned long jif = jiffies - start_jif;
49589 if (jif >= HZ)
49590 jif = HZ - 1;
49591- atomic_inc(&histogram[jif]);
49592+ atomic_inc_unchecked(&histogram[jif]);
49593 }
49594
49595 #else
49596diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
49597index 8c01c5fc..15f982e 100644
49598--- a/fs/cachefiles/namei.c
49599+++ b/fs/cachefiles/namei.c
49600@@ -317,7 +317,7 @@ try_again:
49601 /* first step is to make up a grave dentry in the graveyard */
49602 sprintf(nbuffer, "%08x%08x",
49603 (uint32_t) get_seconds(),
49604- (uint32_t) atomic_inc_return(&cache->gravecounter));
49605+ (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
49606
49607 /* do the multiway lock magic */
49608 trap = lock_rename(cache->graveyard, dir);
49609diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
49610index eccd339..4c1d995 100644
49611--- a/fs/cachefiles/proc.c
49612+++ b/fs/cachefiles/proc.c
49613@@ -14,9 +14,9 @@
49614 #include <linux/seq_file.h>
49615 #include "internal.h"
49616
49617-atomic_t cachefiles_lookup_histogram[HZ];
49618-atomic_t cachefiles_mkdir_histogram[HZ];
49619-atomic_t cachefiles_create_histogram[HZ];
49620+atomic_unchecked_t cachefiles_lookup_histogram[HZ];
49621+atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
49622+atomic_unchecked_t cachefiles_create_histogram[HZ];
49623
49624 /*
49625 * display the latency histogram
49626@@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
49627 return 0;
49628 default:
49629 index = (unsigned long) v - 3;
49630- x = atomic_read(&cachefiles_lookup_histogram[index]);
49631- y = atomic_read(&cachefiles_mkdir_histogram[index]);
49632- z = atomic_read(&cachefiles_create_histogram[index]);
49633+ x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
49634+ y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
49635+ z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
49636 if (x == 0 && y == 0 && z == 0)
49637 return 0;
49638
49639diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
49640index 4809922..aab2c39 100644
49641--- a/fs/cachefiles/rdwr.c
49642+++ b/fs/cachefiles/rdwr.c
49643@@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
49644 old_fs = get_fs();
49645 set_fs(KERNEL_DS);
49646 ret = file->f_op->write(
49647- file, (const void __user *) data, len, &pos);
49648+ file, (const void __force_user *) data, len, &pos);
49649 set_fs(old_fs);
49650 kunmap(page);
49651 if (ret != len)
49652diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
49653index 6d797f4..0ace2e5 100644
49654--- a/fs/ceph/dir.c
49655+++ b/fs/ceph/dir.c
49656@@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
49657 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
49658 struct ceph_mds_client *mdsc = fsc->mdsc;
49659 unsigned frag = fpos_frag(filp->f_pos);
49660- int off = fpos_off(filp->f_pos);
49661+ unsigned int off = fpos_off(filp->f_pos);
49662 int err;
49663 u32 ftype;
49664 struct ceph_mds_reply_info_parsed *rinfo;
49665diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
49666index d9ea6ed..1e6c8ac 100644
49667--- a/fs/cifs/cifs_debug.c
49668+++ b/fs/cifs/cifs_debug.c
49669@@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49670
49671 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
49672 #ifdef CONFIG_CIFS_STATS2
49673- atomic_set(&totBufAllocCount, 0);
49674- atomic_set(&totSmBufAllocCount, 0);
49675+ atomic_set_unchecked(&totBufAllocCount, 0);
49676+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49677 #endif /* CONFIG_CIFS_STATS2 */
49678 spin_lock(&cifs_tcp_ses_lock);
49679 list_for_each(tmp1, &cifs_tcp_ses_list) {
49680@@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
49681 tcon = list_entry(tmp3,
49682 struct cifs_tcon,
49683 tcon_list);
49684- atomic_set(&tcon->num_smbs_sent, 0);
49685+ atomic_set_unchecked(&tcon->num_smbs_sent, 0);
49686 if (server->ops->clear_stats)
49687 server->ops->clear_stats(tcon);
49688 }
49689@@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49690 smBufAllocCount.counter, cifs_min_small);
49691 #ifdef CONFIG_CIFS_STATS2
49692 seq_printf(m, "Total Large %d Small %d Allocations\n",
49693- atomic_read(&totBufAllocCount),
49694- atomic_read(&totSmBufAllocCount));
49695+ atomic_read_unchecked(&totBufAllocCount),
49696+ atomic_read_unchecked(&totSmBufAllocCount));
49697 #endif /* CONFIG_CIFS_STATS2 */
49698
49699 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
49700@@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
49701 if (tcon->need_reconnect)
49702 seq_puts(m, "\tDISCONNECTED ");
49703 seq_printf(m, "\nSMBs: %d",
49704- atomic_read(&tcon->num_smbs_sent));
49705+ atomic_read_unchecked(&tcon->num_smbs_sent));
49706 if (server->ops->print_stats)
49707 server->ops->print_stats(m, tcon);
49708 }
49709diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
49710index 345fc89..b2acae5 100644
49711--- a/fs/cifs/cifsfs.c
49712+++ b/fs/cifs/cifsfs.c
49713@@ -1033,7 +1033,7 @@ cifs_init_request_bufs(void)
49714 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
49715 cifs_req_cachep = kmem_cache_create("cifs_request",
49716 CIFSMaxBufSize + max_hdr_size, 0,
49717- SLAB_HWCACHE_ALIGN, NULL);
49718+ SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
49719 if (cifs_req_cachep == NULL)
49720 return -ENOMEM;
49721
49722@@ -1060,7 +1060,7 @@ cifs_init_request_bufs(void)
49723 efficient to alloc 1 per page off the slab compared to 17K (5page)
49724 alloc of large cifs buffers even when page debugging is on */
49725 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
49726- MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
49727+ MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
49728 NULL);
49729 if (cifs_sm_req_cachep == NULL) {
49730 mempool_destroy(cifs_req_poolp);
49731@@ -1145,8 +1145,8 @@ init_cifs(void)
49732 atomic_set(&bufAllocCount, 0);
49733 atomic_set(&smBufAllocCount, 0);
49734 #ifdef CONFIG_CIFS_STATS2
49735- atomic_set(&totBufAllocCount, 0);
49736- atomic_set(&totSmBufAllocCount, 0);
49737+ atomic_set_unchecked(&totBufAllocCount, 0);
49738+ atomic_set_unchecked(&totSmBufAllocCount, 0);
49739 #endif /* CONFIG_CIFS_STATS2 */
49740
49741 atomic_set(&midCount, 0);
49742diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
49743index 4f07f6f..55de8ce 100644
49744--- a/fs/cifs/cifsglob.h
49745+++ b/fs/cifs/cifsglob.h
49746@@ -751,35 +751,35 @@ struct cifs_tcon {
49747 __u16 Flags; /* optional support bits */
49748 enum statusEnum tidStatus;
49749 #ifdef CONFIG_CIFS_STATS
49750- atomic_t num_smbs_sent;
49751+ atomic_unchecked_t num_smbs_sent;
49752 union {
49753 struct {
49754- atomic_t num_writes;
49755- atomic_t num_reads;
49756- atomic_t num_flushes;
49757- atomic_t num_oplock_brks;
49758- atomic_t num_opens;
49759- atomic_t num_closes;
49760- atomic_t num_deletes;
49761- atomic_t num_mkdirs;
49762- atomic_t num_posixopens;
49763- atomic_t num_posixmkdirs;
49764- atomic_t num_rmdirs;
49765- atomic_t num_renames;
49766- atomic_t num_t2renames;
49767- atomic_t num_ffirst;
49768- atomic_t num_fnext;
49769- atomic_t num_fclose;
49770- atomic_t num_hardlinks;
49771- atomic_t num_symlinks;
49772- atomic_t num_locks;
49773- atomic_t num_acl_get;
49774- atomic_t num_acl_set;
49775+ atomic_unchecked_t num_writes;
49776+ atomic_unchecked_t num_reads;
49777+ atomic_unchecked_t num_flushes;
49778+ atomic_unchecked_t num_oplock_brks;
49779+ atomic_unchecked_t num_opens;
49780+ atomic_unchecked_t num_closes;
49781+ atomic_unchecked_t num_deletes;
49782+ atomic_unchecked_t num_mkdirs;
49783+ atomic_unchecked_t num_posixopens;
49784+ atomic_unchecked_t num_posixmkdirs;
49785+ atomic_unchecked_t num_rmdirs;
49786+ atomic_unchecked_t num_renames;
49787+ atomic_unchecked_t num_t2renames;
49788+ atomic_unchecked_t num_ffirst;
49789+ atomic_unchecked_t num_fnext;
49790+ atomic_unchecked_t num_fclose;
49791+ atomic_unchecked_t num_hardlinks;
49792+ atomic_unchecked_t num_symlinks;
49793+ atomic_unchecked_t num_locks;
49794+ atomic_unchecked_t num_acl_get;
49795+ atomic_unchecked_t num_acl_set;
49796 } cifs_stats;
49797 #ifdef CONFIG_CIFS_SMB2
49798 struct {
49799- atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49800- atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49801+ atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
49802+ atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
49803 } smb2_stats;
49804 #endif /* CONFIG_CIFS_SMB2 */
49805 } stats;
49806@@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
49807 }
49808
49809 #ifdef CONFIG_CIFS_STATS
49810-#define cifs_stats_inc atomic_inc
49811+#define cifs_stats_inc atomic_inc_unchecked
49812
49813 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
49814 unsigned int bytes)
49815@@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
49816 /* Various Debug counters */
49817 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
49818 #ifdef CONFIG_CIFS_STATS2
49819-GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
49820-GLOBAL_EXTERN atomic_t totSmBufAllocCount;
49821+GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
49822+GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
49823 #endif
49824 GLOBAL_EXTERN atomic_t smBufAllocCount;
49825 GLOBAL_EXTERN atomic_t midCount;
49826diff --git a/fs/cifs/link.c b/fs/cifs/link.c
49827index 9f6c4c4..8de307a 100644
49828--- a/fs/cifs/link.c
49829+++ b/fs/cifs/link.c
49830@@ -616,7 +616,7 @@ symlink_exit:
49831
49832 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
49833 {
49834- char *p = nd_get_link(nd);
49835+ const char *p = nd_get_link(nd);
49836 if (!IS_ERR(p))
49837 kfree(p);
49838 }
49839diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
49840index 1b15bf8..1ce489e 100644
49841--- a/fs/cifs/misc.c
49842+++ b/fs/cifs/misc.c
49843@@ -169,7 +169,7 @@ cifs_buf_get(void)
49844 memset(ret_buf, 0, buf_size + 3);
49845 atomic_inc(&bufAllocCount);
49846 #ifdef CONFIG_CIFS_STATS2
49847- atomic_inc(&totBufAllocCount);
49848+ atomic_inc_unchecked(&totBufAllocCount);
49849 #endif /* CONFIG_CIFS_STATS2 */
49850 }
49851
49852@@ -204,7 +204,7 @@ cifs_small_buf_get(void)
49853 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
49854 atomic_inc(&smBufAllocCount);
49855 #ifdef CONFIG_CIFS_STATS2
49856- atomic_inc(&totSmBufAllocCount);
49857+ atomic_inc_unchecked(&totSmBufAllocCount);
49858 #endif /* CONFIG_CIFS_STATS2 */
49859
49860 }
49861diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
49862index 47bc5a8..10decbe 100644
49863--- a/fs/cifs/smb1ops.c
49864+++ b/fs/cifs/smb1ops.c
49865@@ -586,27 +586,27 @@ static void
49866 cifs_clear_stats(struct cifs_tcon *tcon)
49867 {
49868 #ifdef CONFIG_CIFS_STATS
49869- atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
49870- atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
49871- atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
49872- atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49873- atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
49874- atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
49875- atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49876- atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
49877- atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
49878- atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
49879- atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
49880- atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
49881- atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
49882- atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
49883- atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
49884- atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
49885- atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
49886- atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
49887- atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
49888- atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
49889- atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
49890+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
49891+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
49892+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
49893+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
49894+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
49895+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
49896+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
49897+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
49898+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
49899+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
49900+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
49901+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
49902+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
49903+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
49904+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
49905+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
49906+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
49907+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
49908+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
49909+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
49910+ atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
49911 #endif
49912 }
49913
49914@@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49915 {
49916 #ifdef CONFIG_CIFS_STATS
49917 seq_printf(m, " Oplocks breaks: %d",
49918- atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
49919+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
49920 seq_printf(m, "\nReads: %d Bytes: %llu",
49921- atomic_read(&tcon->stats.cifs_stats.num_reads),
49922+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
49923 (long long)(tcon->bytes_read));
49924 seq_printf(m, "\nWrites: %d Bytes: %llu",
49925- atomic_read(&tcon->stats.cifs_stats.num_writes),
49926+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
49927 (long long)(tcon->bytes_written));
49928 seq_printf(m, "\nFlushes: %d",
49929- atomic_read(&tcon->stats.cifs_stats.num_flushes));
49930+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
49931 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
49932- atomic_read(&tcon->stats.cifs_stats.num_locks),
49933- atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
49934- atomic_read(&tcon->stats.cifs_stats.num_symlinks));
49935+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
49936+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
49937+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
49938 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
49939- atomic_read(&tcon->stats.cifs_stats.num_opens),
49940- atomic_read(&tcon->stats.cifs_stats.num_closes),
49941- atomic_read(&tcon->stats.cifs_stats.num_deletes));
49942+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
49943+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
49944+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
49945 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
49946- atomic_read(&tcon->stats.cifs_stats.num_posixopens),
49947- atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
49948+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
49949+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
49950 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
49951- atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
49952- atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
49953+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
49954+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
49955 seq_printf(m, "\nRenames: %d T2 Renames %d",
49956- atomic_read(&tcon->stats.cifs_stats.num_renames),
49957- atomic_read(&tcon->stats.cifs_stats.num_t2renames));
49958+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
49959+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
49960 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
49961- atomic_read(&tcon->stats.cifs_stats.num_ffirst),
49962- atomic_read(&tcon->stats.cifs_stats.num_fnext),
49963- atomic_read(&tcon->stats.cifs_stats.num_fclose));
49964+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
49965+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
49966+ atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
49967 #endif
49968 }
49969
49970diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
49971index bceffe7..cd1ae59 100644
49972--- a/fs/cifs/smb2ops.c
49973+++ b/fs/cifs/smb2ops.c
49974@@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
49975 #ifdef CONFIG_CIFS_STATS
49976 int i;
49977 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
49978- atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49979- atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49980+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
49981+ atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
49982 }
49983 #endif
49984 }
49985@@ -284,66 +284,66 @@ static void
49986 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
49987 {
49988 #ifdef CONFIG_CIFS_STATS
49989- atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49990- atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49991+ atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
49992+ atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
49993 seq_printf(m, "\nNegotiates: %d sent %d failed",
49994- atomic_read(&sent[SMB2_NEGOTIATE_HE]),
49995- atomic_read(&failed[SMB2_NEGOTIATE_HE]));
49996+ atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
49997+ atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
49998 seq_printf(m, "\nSessionSetups: %d sent %d failed",
49999- atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
50000- atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
50001+ atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
50002+ atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
50003 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
50004 seq_printf(m, "\nLogoffs: %d sent %d failed",
50005- atomic_read(&sent[SMB2_LOGOFF_HE]),
50006- atomic_read(&failed[SMB2_LOGOFF_HE]));
50007+ atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
50008+ atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
50009 seq_printf(m, "\nTreeConnects: %d sent %d failed",
50010- atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
50011- atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
50012+ atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
50013+ atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
50014 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
50015- atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
50016- atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
50017+ atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
50018+ atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
50019 seq_printf(m, "\nCreates: %d sent %d failed",
50020- atomic_read(&sent[SMB2_CREATE_HE]),
50021- atomic_read(&failed[SMB2_CREATE_HE]));
50022+ atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
50023+ atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
50024 seq_printf(m, "\nCloses: %d sent %d failed",
50025- atomic_read(&sent[SMB2_CLOSE_HE]),
50026- atomic_read(&failed[SMB2_CLOSE_HE]));
50027+ atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
50028+ atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
50029 seq_printf(m, "\nFlushes: %d sent %d failed",
50030- atomic_read(&sent[SMB2_FLUSH_HE]),
50031- atomic_read(&failed[SMB2_FLUSH_HE]));
50032+ atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
50033+ atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
50034 seq_printf(m, "\nReads: %d sent %d failed",
50035- atomic_read(&sent[SMB2_READ_HE]),
50036- atomic_read(&failed[SMB2_READ_HE]));
50037+ atomic_read_unchecked(&sent[SMB2_READ_HE]),
50038+ atomic_read_unchecked(&failed[SMB2_READ_HE]));
50039 seq_printf(m, "\nWrites: %d sent %d failed",
50040- atomic_read(&sent[SMB2_WRITE_HE]),
50041- atomic_read(&failed[SMB2_WRITE_HE]));
50042+ atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
50043+ atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
50044 seq_printf(m, "\nLocks: %d sent %d failed",
50045- atomic_read(&sent[SMB2_LOCK_HE]),
50046- atomic_read(&failed[SMB2_LOCK_HE]));
50047+ atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
50048+ atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
50049 seq_printf(m, "\nIOCTLs: %d sent %d failed",
50050- atomic_read(&sent[SMB2_IOCTL_HE]),
50051- atomic_read(&failed[SMB2_IOCTL_HE]));
50052+ atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
50053+ atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
50054 seq_printf(m, "\nCancels: %d sent %d failed",
50055- atomic_read(&sent[SMB2_CANCEL_HE]),
50056- atomic_read(&failed[SMB2_CANCEL_HE]));
50057+ atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
50058+ atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
50059 seq_printf(m, "\nEchos: %d sent %d failed",
50060- atomic_read(&sent[SMB2_ECHO_HE]),
50061- atomic_read(&failed[SMB2_ECHO_HE]));
50062+ atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
50063+ atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
50064 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
50065- atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
50066- atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
50067+ atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
50068+ atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
50069 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
50070- atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
50071- atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
50072+ atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
50073+ atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
50074 seq_printf(m, "\nQueryInfos: %d sent %d failed",
50075- atomic_read(&sent[SMB2_QUERY_INFO_HE]),
50076- atomic_read(&failed[SMB2_QUERY_INFO_HE]));
50077+ atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
50078+ atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
50079 seq_printf(m, "\nSetInfos: %d sent %d failed",
50080- atomic_read(&sent[SMB2_SET_INFO_HE]),
50081- atomic_read(&failed[SMB2_SET_INFO_HE]));
50082+ atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
50083+ atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
50084 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
50085- atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
50086- atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
50087+ atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
50088+ atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
50089 #endif
50090 }
50091
50092diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
50093index 41d9d07..dbb4772 100644
50094--- a/fs/cifs/smb2pdu.c
50095+++ b/fs/cifs/smb2pdu.c
50096@@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
50097 default:
50098 cERROR(1, "info level %u isn't supported",
50099 srch_inf->info_level);
50100- rc = -EINVAL;
50101- goto qdir_exit;
50102+ return -EINVAL;
50103 }
50104
50105 req->FileIndex = cpu_to_le32(index);
50106diff --git a/fs/coda/cache.c b/fs/coda/cache.c
50107index 1da168c..8bc7ff6 100644
50108--- a/fs/coda/cache.c
50109+++ b/fs/coda/cache.c
50110@@ -24,7 +24,7 @@
50111 #include "coda_linux.h"
50112 #include "coda_cache.h"
50113
50114-static atomic_t permission_epoch = ATOMIC_INIT(0);
50115+static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
50116
50117 /* replace or extend an acl cache hit */
50118 void coda_cache_enter(struct inode *inode, int mask)
50119@@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
50120 struct coda_inode_info *cii = ITOC(inode);
50121
50122 spin_lock(&cii->c_lock);
50123- cii->c_cached_epoch = atomic_read(&permission_epoch);
50124+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
50125 if (!uid_eq(cii->c_uid, current_fsuid())) {
50126 cii->c_uid = current_fsuid();
50127 cii->c_cached_perm = mask;
50128@@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
50129 {
50130 struct coda_inode_info *cii = ITOC(inode);
50131 spin_lock(&cii->c_lock);
50132- cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
50133+ cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
50134 spin_unlock(&cii->c_lock);
50135 }
50136
50137 /* remove all acl caches */
50138 void coda_cache_clear_all(struct super_block *sb)
50139 {
50140- atomic_inc(&permission_epoch);
50141+ atomic_inc_unchecked(&permission_epoch);
50142 }
50143
50144
50145@@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
50146 spin_lock(&cii->c_lock);
50147 hit = (mask & cii->c_cached_perm) == mask &&
50148 uid_eq(cii->c_uid, current_fsuid()) &&
50149- cii->c_cached_epoch == atomic_read(&permission_epoch);
50150+ cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
50151 spin_unlock(&cii->c_lock);
50152
50153 return hit;
50154diff --git a/fs/compat.c b/fs/compat.c
50155index d487985..c9e04b1 100644
50156--- a/fs/compat.c
50157+++ b/fs/compat.c
50158@@ -54,7 +54,7 @@
50159 #include <asm/ioctls.h>
50160 #include "internal.h"
50161
50162-int compat_log = 1;
50163+int compat_log = 0;
50164
50165 int compat_printk(const char *fmt, ...)
50166 {
50167@@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
50168
50169 set_fs(KERNEL_DS);
50170 /* The __user pointer cast is valid because of the set_fs() */
50171- ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
50172+ ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
50173 set_fs(oldfs);
50174 /* truncating is ok because it's a user address */
50175 if (!ret)
50176@@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
50177 goto out;
50178
50179 ret = -EINVAL;
50180- if (nr_segs > UIO_MAXIOV || nr_segs < 0)
50181+ if (nr_segs > UIO_MAXIOV)
50182 goto out;
50183 if (nr_segs > fast_segs) {
50184 ret = -ENOMEM;
50185@@ -835,6 +835,7 @@ struct compat_old_linux_dirent {
50186
50187 struct compat_readdir_callback {
50188 struct compat_old_linux_dirent __user *dirent;
50189+ struct file * file;
50190 int result;
50191 };
50192
50193@@ -852,6 +853,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
50194 buf->result = -EOVERFLOW;
50195 return -EOVERFLOW;
50196 }
50197+
50198+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50199+ return 0;
50200+
50201 buf->result++;
50202 dirent = buf->dirent;
50203 if (!access_ok(VERIFY_WRITE, dirent,
50204@@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
50205
50206 buf.result = 0;
50207 buf.dirent = dirent;
50208+ buf.file = f.file;
50209
50210 error = vfs_readdir(f.file, compat_fillonedir, &buf);
50211 if (buf.result)
50212@@ -901,6 +907,7 @@ struct compat_linux_dirent {
50213 struct compat_getdents_callback {
50214 struct compat_linux_dirent __user *current_dir;
50215 struct compat_linux_dirent __user *previous;
50216+ struct file * file;
50217 int count;
50218 int error;
50219 };
50220@@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
50221 buf->error = -EOVERFLOW;
50222 return -EOVERFLOW;
50223 }
50224+
50225+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50226+ return 0;
50227+
50228 dirent = buf->previous;
50229 if (dirent) {
50230 if (__put_user(offset, &dirent->d_off))
50231@@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50232 buf.previous = NULL;
50233 buf.count = count;
50234 buf.error = 0;
50235+ buf.file = f.file;
50236
50237 error = vfs_readdir(f.file, compat_filldir, &buf);
50238 if (error >= 0)
50239@@ -987,6 +999,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
50240 struct compat_getdents_callback64 {
50241 struct linux_dirent64 __user *current_dir;
50242 struct linux_dirent64 __user *previous;
50243+ struct file * file;
50244 int count;
50245 int error;
50246 };
50247@@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
50248 buf->error = -EINVAL; /* only used if we fail.. */
50249 if (reclen > buf->count)
50250 return -EINVAL;
50251+
50252+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50253+ return 0;
50254+
50255 dirent = buf->previous;
50256
50257 if (dirent) {
50258@@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
50259 buf.previous = NULL;
50260 buf.count = count;
50261 buf.error = 0;
50262+ buf.file = f.file;
50263
50264 error = vfs_readdir(f.file, compat_filldir64, &buf);
50265 if (error >= 0)
50266 error = buf.error;
50267 lastdirent = buf.previous;
50268 if (lastdirent) {
50269- typeof(lastdirent->d_off) d_off = f.file->f_pos;
50270+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
50271 if (__put_user_unaligned(d_off, &lastdirent->d_off))
50272 error = -EFAULT;
50273 else
50274diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
50275index a81147e..20bf2b5 100644
50276--- a/fs/compat_binfmt_elf.c
50277+++ b/fs/compat_binfmt_elf.c
50278@@ -30,11 +30,13 @@
50279 #undef elf_phdr
50280 #undef elf_shdr
50281 #undef elf_note
50282+#undef elf_dyn
50283 #undef elf_addr_t
50284 #define elfhdr elf32_hdr
50285 #define elf_phdr elf32_phdr
50286 #define elf_shdr elf32_shdr
50287 #define elf_note elf32_note
50288+#define elf_dyn Elf32_Dyn
50289 #define elf_addr_t Elf32_Addr
50290
50291 /*
50292diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
50293index 3ced75f..b28d192 100644
50294--- a/fs/compat_ioctl.c
50295+++ b/fs/compat_ioctl.c
50296@@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
50297 return -EFAULT;
50298 if (__get_user(udata, &ss32->iomem_base))
50299 return -EFAULT;
50300- ss.iomem_base = compat_ptr(udata);
50301+ ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
50302 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
50303 __get_user(ss.port_high, &ss32->port_high))
50304 return -EFAULT;
50305@@ -704,8 +704,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
50306 for (i = 0; i < nmsgs; i++) {
50307 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
50308 return -EFAULT;
50309- if (get_user(datap, &umsgs[i].buf) ||
50310- put_user(compat_ptr(datap), &tmsgs[i].buf))
50311+ if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
50312+ put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
50313 return -EFAULT;
50314 }
50315 return sys_ioctl(fd, cmd, (unsigned long)tdata);
50316@@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
50317 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
50318 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
50319 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
50320- copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50321+ copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
50322 return -EFAULT;
50323
50324 return ioctl_preallocate(file, p);
50325@@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
50326 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
50327 {
50328 unsigned int a, b;
50329- a = *(unsigned int *)p;
50330- b = *(unsigned int *)q;
50331+ a = *(const unsigned int *)p;
50332+ b = *(const unsigned int *)q;
50333 if (a > b)
50334 return 1;
50335 if (a < b)
50336diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
50337index 7aabc6a..34c1197 100644
50338--- a/fs/configfs/dir.c
50339+++ b/fs/configfs/dir.c
50340@@ -1565,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50341 }
50342 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
50343 struct configfs_dirent *next;
50344- const char * name;
50345+ const unsigned char * name;
50346+ char d_name[sizeof(next->s_dentry->d_iname)];
50347 int len;
50348 struct inode *inode = NULL;
50349
50350@@ -1575,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
50351 continue;
50352
50353 name = configfs_get_name(next);
50354- len = strlen(name);
50355+ if (next->s_dentry && name == next->s_dentry->d_iname) {
50356+ len = next->s_dentry->d_name.len;
50357+ memcpy(d_name, name, len);
50358+ name = d_name;
50359+ } else
50360+ len = strlen(name);
50361
50362 /*
50363 * We'll have a dentry and an inode for
50364diff --git a/fs/coredump.c b/fs/coredump.c
50365index c647965..a77bff3 100644
50366--- a/fs/coredump.c
50367+++ b/fs/coredump.c
50368@@ -52,7 +52,7 @@ struct core_name {
50369 char *corename;
50370 int used, size;
50371 };
50372-static atomic_t call_count = ATOMIC_INIT(1);
50373+static atomic_unchecked_t call_count = ATOMIC_INIT(1);
50374
50375 /* The maximal length of core_pattern is also specified in sysctl.c */
50376
50377@@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
50378 {
50379 char *old_corename = cn->corename;
50380
50381- cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
50382+ cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
50383 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
50384
50385 if (!cn->corename) {
50386@@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
50387 int pid_in_pattern = 0;
50388 int err = 0;
50389
50390- cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
50391+ cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
50392 cn->corename = kmalloc(cn->size, GFP_KERNEL);
50393 cn->used = 0;
50394
50395@@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
50396 pipe = file_inode(file)->i_pipe;
50397
50398 pipe_lock(pipe);
50399- pipe->readers++;
50400- pipe->writers--;
50401+ atomic_inc(&pipe->readers);
50402+ atomic_dec(&pipe->writers);
50403
50404- while ((pipe->readers > 1) && (!signal_pending(current))) {
50405+ while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
50406 wake_up_interruptible_sync(&pipe->wait);
50407 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
50408 pipe_wait(pipe);
50409 }
50410
50411- pipe->readers--;
50412- pipe->writers++;
50413+ atomic_dec(&pipe->readers);
50414+ atomic_inc(&pipe->writers);
50415 pipe_unlock(pipe);
50416
50417 }
50418@@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
50419 int ispipe;
50420 struct files_struct *displaced;
50421 bool need_nonrelative = false;
50422- static atomic_t core_dump_count = ATOMIC_INIT(0);
50423+ static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
50424+ long signr = siginfo->si_signo;
50425 struct coredump_params cprm = {
50426 .siginfo = siginfo,
50427 .regs = signal_pt_regs(),
50428@@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
50429 .mm_flags = mm->flags,
50430 };
50431
50432- audit_core_dumps(siginfo->si_signo);
50433+ audit_core_dumps(signr);
50434+
50435+ if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
50436+ gr_handle_brute_attach(cprm.mm_flags);
50437
50438 binfmt = mm->binfmt;
50439 if (!binfmt || !binfmt->core_dump)
50440@@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
50441 need_nonrelative = true;
50442 }
50443
50444- retval = coredump_wait(siginfo->si_signo, &core_state);
50445+ retval = coredump_wait(signr, &core_state);
50446 if (retval < 0)
50447 goto fail_creds;
50448
50449@@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
50450 }
50451 cprm.limit = RLIM_INFINITY;
50452
50453- dump_count = atomic_inc_return(&core_dump_count);
50454+ dump_count = atomic_inc_return_unchecked(&core_dump_count);
50455 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
50456 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
50457 task_tgid_vnr(current), current->comm);
50458@@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
50459 } else {
50460 struct inode *inode;
50461
50462+ gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
50463+
50464 if (cprm.limit < binfmt->min_coredump)
50465 goto fail_unlock;
50466
50467@@ -640,7 +646,7 @@ close_fail:
50468 filp_close(cprm.file, NULL);
50469 fail_dropcount:
50470 if (ispipe)
50471- atomic_dec(&core_dump_count);
50472+ atomic_dec_unchecked(&core_dump_count);
50473 fail_unlock:
50474 kfree(cn.corename);
50475 fail_corename:
50476@@ -659,7 +665,7 @@ fail:
50477 */
50478 int dump_write(struct file *file, const void *addr, int nr)
50479 {
50480- return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
50481+ return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
50482 }
50483 EXPORT_SYMBOL(dump_write);
50484
50485diff --git a/fs/dcache.c b/fs/dcache.c
50486index e689268..f36956e 100644
50487--- a/fs/dcache.c
50488+++ b/fs/dcache.c
50489@@ -3100,7 +3100,7 @@ void __init vfs_caches_init(unsigned long mempages)
50490 mempages -= reserve;
50491
50492 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
50493- SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
50494+ SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
50495
50496 dcache_init();
50497 inode_init();
50498diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
50499index 4888cb3..e0f7cf8 100644
50500--- a/fs/debugfs/inode.c
50501+++ b/fs/debugfs/inode.c
50502@@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
50503 */
50504 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
50505 {
50506+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50507+ return __create_file(name, S_IFDIR | S_IRWXU,
50508+#else
50509 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
50510+#endif
50511 parent, NULL, NULL);
50512 }
50513 EXPORT_SYMBOL_GPL(debugfs_create_dir);
50514diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
50515index 5eab400..810a3f5 100644
50516--- a/fs/ecryptfs/inode.c
50517+++ b/fs/ecryptfs/inode.c
50518@@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
50519 old_fs = get_fs();
50520 set_fs(get_ds());
50521 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
50522- (char __user *)lower_buf,
50523+ (char __force_user *)lower_buf,
50524 PATH_MAX);
50525 set_fs(old_fs);
50526 if (rc < 0)
50527@@ -706,7 +706,7 @@ out:
50528 static void
50529 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
50530 {
50531- char *buf = nd_get_link(nd);
50532+ const char *buf = nd_get_link(nd);
50533 if (!IS_ERR(buf)) {
50534 /* Free the char* */
50535 kfree(buf);
50536diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
50537index e4141f2..d8263e8 100644
50538--- a/fs/ecryptfs/miscdev.c
50539+++ b/fs/ecryptfs/miscdev.c
50540@@ -304,7 +304,7 @@ check_list:
50541 goto out_unlock_msg_ctx;
50542 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
50543 if (msg_ctx->msg) {
50544- if (copy_to_user(&buf[i], packet_length, packet_length_size))
50545+ if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
50546 goto out_unlock_msg_ctx;
50547 i += packet_length_size;
50548 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
50549diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
50550index 6a16053..2155147 100644
50551--- a/fs/ecryptfs/read_write.c
50552+++ b/fs/ecryptfs/read_write.c
50553@@ -240,7 +240,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
50554 return -EIO;
50555 fs_save = get_fs();
50556 set_fs(get_ds());
50557- rc = vfs_read(lower_file, data, size, &offset);
50558+ rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
50559 set_fs(fs_save);
50560 return rc;
50561 }
50562diff --git a/fs/exec.c b/fs/exec.c
50563index 6d56ff2..f65b4ca 100644
50564--- a/fs/exec.c
50565+++ b/fs/exec.c
50566@@ -55,8 +55,20 @@
50567 #include <linux/pipe_fs_i.h>
50568 #include <linux/oom.h>
50569 #include <linux/compat.h>
50570+#include <linux/random.h>
50571+#include <linux/seq_file.h>
50572+#include <linux/coredump.h>
50573+#include <linux/mman.h>
50574+
50575+#ifdef CONFIG_PAX_REFCOUNT
50576+#include <linux/kallsyms.h>
50577+#include <linux/kdebug.h>
50578+#endif
50579+
50580+#include <trace/events/fs.h>
50581
50582 #include <asm/uaccess.h>
50583+#include <asm/sections.h>
50584 #include <asm/mmu_context.h>
50585 #include <asm/tlb.h>
50586
50587@@ -66,6 +78,18 @@
50588
50589 #include <trace/events/sched.h>
50590
50591+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
50592+void __weak pax_set_initial_flags(struct linux_binprm *bprm)
50593+{
50594+ 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");
50595+}
50596+#endif
50597+
50598+#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
50599+void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
50600+EXPORT_SYMBOL(pax_set_initial_flags_func);
50601+#endif
50602+
50603 int suid_dumpable = 0;
50604
50605 static LIST_HEAD(formats);
50606@@ -75,8 +99,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
50607 {
50608 BUG_ON(!fmt);
50609 write_lock(&binfmt_lock);
50610- insert ? list_add(&fmt->lh, &formats) :
50611- list_add_tail(&fmt->lh, &formats);
50612+ insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
50613+ pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
50614 write_unlock(&binfmt_lock);
50615 }
50616
50617@@ -85,7 +109,7 @@ EXPORT_SYMBOL(__register_binfmt);
50618 void unregister_binfmt(struct linux_binfmt * fmt)
50619 {
50620 write_lock(&binfmt_lock);
50621- list_del(&fmt->lh);
50622+ pax_list_del((struct list_head *)&fmt->lh);
50623 write_unlock(&binfmt_lock);
50624 }
50625
50626@@ -180,18 +204,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50627 int write)
50628 {
50629 struct page *page;
50630- int ret;
50631
50632-#ifdef CONFIG_STACK_GROWSUP
50633- if (write) {
50634- ret = expand_downwards(bprm->vma, pos);
50635- if (ret < 0)
50636- return NULL;
50637- }
50638-#endif
50639- ret = get_user_pages(current, bprm->mm, pos,
50640- 1, write, 1, &page, NULL);
50641- if (ret <= 0)
50642+ if (0 > expand_downwards(bprm->vma, pos))
50643+ return NULL;
50644+ if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
50645 return NULL;
50646
50647 if (write) {
50648@@ -207,6 +223,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
50649 if (size <= ARG_MAX)
50650 return page;
50651
50652+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50653+ // only allow 512KB for argv+env on suid/sgid binaries
50654+ // to prevent easy ASLR exhaustion
50655+ if (((!uid_eq(bprm->cred->euid, current_euid())) ||
50656+ (!gid_eq(bprm->cred->egid, current_egid()))) &&
50657+ (size > (512 * 1024))) {
50658+ put_page(page);
50659+ return NULL;
50660+ }
50661+#endif
50662+
50663 /*
50664 * Limit to 1/4-th the stack size for the argv+env strings.
50665 * This ensures that:
50666@@ -266,6 +293,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50667 vma->vm_end = STACK_TOP_MAX;
50668 vma->vm_start = vma->vm_end - PAGE_SIZE;
50669 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
50670+
50671+#ifdef CONFIG_PAX_SEGMEXEC
50672+ vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
50673+#endif
50674+
50675 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
50676 INIT_LIST_HEAD(&vma->anon_vma_chain);
50677
50678@@ -276,6 +308,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
50679 mm->stack_vm = mm->total_vm = 1;
50680 up_write(&mm->mmap_sem);
50681 bprm->p = vma->vm_end - sizeof(void *);
50682+
50683+#ifdef CONFIG_PAX_RANDUSTACK
50684+ if (randomize_va_space)
50685+ bprm->p ^= random32() & ~PAGE_MASK;
50686+#endif
50687+
50688 return 0;
50689 err:
50690 up_write(&mm->mmap_sem);
50691@@ -396,7 +434,7 @@ struct user_arg_ptr {
50692 } ptr;
50693 };
50694
50695-static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50696+const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50697 {
50698 const char __user *native;
50699
50700@@ -405,14 +443,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
50701 compat_uptr_t compat;
50702
50703 if (get_user(compat, argv.ptr.compat + nr))
50704- return ERR_PTR(-EFAULT);
50705+ return (const char __force_user *)ERR_PTR(-EFAULT);
50706
50707 return compat_ptr(compat);
50708 }
50709 #endif
50710
50711 if (get_user(native, argv.ptr.native + nr))
50712- return ERR_PTR(-EFAULT);
50713+ return (const char __force_user *)ERR_PTR(-EFAULT);
50714
50715 return native;
50716 }
50717@@ -431,7 +469,7 @@ static int count(struct user_arg_ptr argv, int max)
50718 if (!p)
50719 break;
50720
50721- if (IS_ERR(p))
50722+ if (IS_ERR((const char __force_kernel *)p))
50723 return -EFAULT;
50724
50725 if (i >= max)
50726@@ -466,7 +504,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
50727
50728 ret = -EFAULT;
50729 str = get_user_arg_ptr(argv, argc);
50730- if (IS_ERR(str))
50731+ if (IS_ERR((const char __force_kernel *)str))
50732 goto out;
50733
50734 len = strnlen_user(str, MAX_ARG_STRLEN);
50735@@ -548,7 +586,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
50736 int r;
50737 mm_segment_t oldfs = get_fs();
50738 struct user_arg_ptr argv = {
50739- .ptr.native = (const char __user *const __user *)__argv,
50740+ .ptr.native = (const char __force_user * const __force_user *)__argv,
50741 };
50742
50743 set_fs(KERNEL_DS);
50744@@ -583,7 +621,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50745 unsigned long new_end = old_end - shift;
50746 struct mmu_gather tlb;
50747
50748- BUG_ON(new_start > new_end);
50749+ if (new_start >= new_end || new_start < mmap_min_addr)
50750+ return -ENOMEM;
50751
50752 /*
50753 * ensure there are no vmas between where we want to go
50754@@ -592,6 +631,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
50755 if (vma != find_vma(mm, new_start))
50756 return -EFAULT;
50757
50758+#ifdef CONFIG_PAX_SEGMEXEC
50759+ BUG_ON(pax_find_mirror_vma(vma));
50760+#endif
50761+
50762 /*
50763 * cover the whole range: [new_start, old_end)
50764 */
50765@@ -672,10 +715,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50766 stack_top = arch_align_stack(stack_top);
50767 stack_top = PAGE_ALIGN(stack_top);
50768
50769- if (unlikely(stack_top < mmap_min_addr) ||
50770- unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
50771- return -ENOMEM;
50772-
50773 stack_shift = vma->vm_end - stack_top;
50774
50775 bprm->p -= stack_shift;
50776@@ -687,8 +726,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
50777 bprm->exec -= stack_shift;
50778
50779 down_write(&mm->mmap_sem);
50780+
50781+ /* Move stack pages down in memory. */
50782+ if (stack_shift) {
50783+ ret = shift_arg_pages(vma, stack_shift);
50784+ if (ret)
50785+ goto out_unlock;
50786+ }
50787+
50788 vm_flags = VM_STACK_FLAGS;
50789
50790+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50791+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
50792+ vm_flags &= ~VM_EXEC;
50793+
50794+#ifdef CONFIG_PAX_MPROTECT
50795+ if (mm->pax_flags & MF_PAX_MPROTECT)
50796+ vm_flags &= ~VM_MAYEXEC;
50797+#endif
50798+
50799+ }
50800+#endif
50801+
50802 /*
50803 * Adjust stack execute permissions; explicitly enable for
50804 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
50805@@ -707,13 +766,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
50806 goto out_unlock;
50807 BUG_ON(prev != vma);
50808
50809- /* Move stack pages down in memory. */
50810- if (stack_shift) {
50811- ret = shift_arg_pages(vma, stack_shift);
50812- if (ret)
50813- goto out_unlock;
50814- }
50815-
50816 /* mprotect_fixup is overkill to remove the temporary stack flags */
50817 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
50818
50819@@ -737,6 +789,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
50820 #endif
50821 current->mm->start_stack = bprm->p;
50822 ret = expand_stack(vma, stack_base);
50823+
50824+#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
50825+ if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
50826+ unsigned long size;
50827+ vm_flags_t vm_flags;
50828+
50829+ size = STACK_TOP - vma->vm_end;
50830+ vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
50831+
50832+ ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
50833+
50834+#ifdef CONFIG_X86
50835+ if (!ret) {
50836+ size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
50837+ ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
50838+ }
50839+#endif
50840+
50841+ }
50842+#endif
50843+
50844 if (ret)
50845 ret = -EFAULT;
50846
50847@@ -772,6 +845,8 @@ struct file *open_exec(const char *name)
50848
50849 fsnotify_open(file);
50850
50851+ trace_open_exec(name);
50852+
50853 err = deny_write_access(file);
50854 if (err)
50855 goto exit;
50856@@ -795,7 +870,7 @@ int kernel_read(struct file *file, loff_t offset,
50857 old_fs = get_fs();
50858 set_fs(get_ds());
50859 /* The cast to a user pointer is valid due to the set_fs() */
50860- result = vfs_read(file, (void __user *)addr, count, &pos);
50861+ result = vfs_read(file, (void __force_user *)addr, count, &pos);
50862 set_fs(old_fs);
50863 return result;
50864 }
50865@@ -1136,13 +1211,6 @@ void setup_new_exec(struct linux_binprm * bprm)
50866 set_dumpable(current->mm, suid_dumpable);
50867 }
50868
50869- /*
50870- * Flush performance counters when crossing a
50871- * security domain:
50872- */
50873- if (!get_dumpable(current->mm))
50874- perf_event_exit_task(current);
50875-
50876 /* An exec changes our domain. We are no longer part of the thread
50877 group */
50878
50879@@ -1206,6 +1274,15 @@ void install_exec_creds(struct linux_binprm *bprm)
50880
50881 commit_creds(bprm->cred);
50882 bprm->cred = NULL;
50883+
50884+ /*
50885+ * Disable monitoring for regular users
50886+ * when executing setuid binaries. Must
50887+ * wait until new credentials are committed
50888+ * by commit_creds() above
50889+ */
50890+ if (get_dumpable(current->mm) != SUID_DUMP_USER)
50891+ perf_event_exit_task(current);
50892 /*
50893 * cred_guard_mutex must be held at least to this point to prevent
50894 * ptrace_attach() from altering our determination of the task's
50895@@ -1250,7 +1327,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
50896 }
50897 rcu_read_unlock();
50898
50899- if (p->fs->users > n_fs) {
50900+ if (atomic_read(&p->fs->users) > n_fs) {
50901 bprm->unsafe |= LSM_UNSAFE_SHARE;
50902 } else {
50903 res = -EAGAIN;
50904@@ -1450,6 +1527,31 @@ int search_binary_handler(struct linux_binprm *bprm)
50905
50906 EXPORT_SYMBOL(search_binary_handler);
50907
50908+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50909+static DEFINE_PER_CPU(u64, exec_counter);
50910+static int __init init_exec_counters(void)
50911+{
50912+ unsigned int cpu;
50913+
50914+ for_each_possible_cpu(cpu) {
50915+ per_cpu(exec_counter, cpu) = (u64)cpu;
50916+ }
50917+
50918+ return 0;
50919+}
50920+early_initcall(init_exec_counters);
50921+static inline void increment_exec_counter(void)
50922+{
50923+ BUILD_BUG_ON(NR_CPUS > (1 << 16));
50924+ current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
50925+}
50926+#else
50927+static inline void increment_exec_counter(void) {}
50928+#endif
50929+
50930+extern void gr_handle_exec_args(struct linux_binprm *bprm,
50931+ struct user_arg_ptr argv);
50932+
50933 /*
50934 * sys_execve() executes a new program.
50935 */
50936@@ -1457,6 +1559,11 @@ static int do_execve_common(const char *filename,
50937 struct user_arg_ptr argv,
50938 struct user_arg_ptr envp)
50939 {
50940+#ifdef CONFIG_GRKERNSEC
50941+ struct file *old_exec_file;
50942+ struct acl_subject_label *old_acl;
50943+ struct rlimit old_rlim[RLIM_NLIMITS];
50944+#endif
50945 struct linux_binprm *bprm;
50946 struct file *file;
50947 struct files_struct *displaced;
50948@@ -1464,6 +1571,8 @@ static int do_execve_common(const char *filename,
50949 int retval;
50950 const struct cred *cred = current_cred();
50951
50952+ gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&cred->user->processes), 1);
50953+
50954 /*
50955 * We move the actual failure in case of RLIMIT_NPROC excess from
50956 * set*uid() to execve() because too many poorly written programs
50957@@ -1504,12 +1613,27 @@ static int do_execve_common(const char *filename,
50958 if (IS_ERR(file))
50959 goto out_unmark;
50960
50961+ if (gr_ptrace_readexec(file, bprm->unsafe)) {
50962+ retval = -EPERM;
50963+ goto out_file;
50964+ }
50965+
50966 sched_exec();
50967
50968 bprm->file = file;
50969 bprm->filename = filename;
50970 bprm->interp = filename;
50971
50972+ if (gr_process_user_ban()) {
50973+ retval = -EPERM;
50974+ goto out_file;
50975+ }
50976+
50977+ if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
50978+ retval = -EACCES;
50979+ goto out_file;
50980+ }
50981+
50982 retval = bprm_mm_init(bprm);
50983 if (retval)
50984 goto out_file;
50985@@ -1526,24 +1650,65 @@ static int do_execve_common(const char *filename,
50986 if (retval < 0)
50987 goto out;
50988
50989+#ifdef CONFIG_GRKERNSEC
50990+ old_acl = current->acl;
50991+ memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
50992+ old_exec_file = current->exec_file;
50993+ get_file(file);
50994+ current->exec_file = file;
50995+#endif
50996+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50997+ /* limit suid stack to 8MB
50998+ * we saved the old limits above and will restore them if this exec fails
50999+ */
51000+ if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
51001+ (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
51002+ current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
51003+#endif
51004+
51005+ if (!gr_tpe_allow(file)) {
51006+ retval = -EACCES;
51007+ goto out_fail;
51008+ }
51009+
51010+ if (gr_check_crash_exec(file)) {
51011+ retval = -EACCES;
51012+ goto out_fail;
51013+ }
51014+
51015+ retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
51016+ bprm->unsafe);
51017+ if (retval < 0)
51018+ goto out_fail;
51019+
51020 retval = copy_strings_kernel(1, &bprm->filename, bprm);
51021 if (retval < 0)
51022- goto out;
51023+ goto out_fail;
51024
51025 bprm->exec = bprm->p;
51026 retval = copy_strings(bprm->envc, envp, bprm);
51027 if (retval < 0)
51028- goto out;
51029+ goto out_fail;
51030
51031 retval = copy_strings(bprm->argc, argv, bprm);
51032 if (retval < 0)
51033- goto out;
51034+ goto out_fail;
51035+
51036+ gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
51037+
51038+ gr_handle_exec_args(bprm, argv);
51039
51040 retval = search_binary_handler(bprm);
51041 if (retval < 0)
51042- goto out;
51043+ goto out_fail;
51044+#ifdef CONFIG_GRKERNSEC
51045+ if (old_exec_file)
51046+ fput(old_exec_file);
51047+#endif
51048
51049 /* execve succeeded */
51050+
51051+ increment_exec_counter();
51052 current->fs->in_exec = 0;
51053 current->in_execve = 0;
51054 acct_update_integrals(current);
51055@@ -1552,6 +1717,14 @@ static int do_execve_common(const char *filename,
51056 put_files_struct(displaced);
51057 return retval;
51058
51059+out_fail:
51060+#ifdef CONFIG_GRKERNSEC
51061+ current->acl = old_acl;
51062+ memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
51063+ fput(current->exec_file);
51064+ current->exec_file = old_exec_file;
51065+#endif
51066+
51067 out:
51068 if (bprm->mm) {
51069 acct_arg_size(bprm, 0);
51070@@ -1700,3 +1873,283 @@ asmlinkage long compat_sys_execve(const char __user * filename,
51071 return error;
51072 }
51073 #endif
51074+
51075+int pax_check_flags(unsigned long *flags)
51076+{
51077+ int retval = 0;
51078+
51079+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
51080+ if (*flags & MF_PAX_SEGMEXEC)
51081+ {
51082+ *flags &= ~MF_PAX_SEGMEXEC;
51083+ retval = -EINVAL;
51084+ }
51085+#endif
51086+
51087+ if ((*flags & MF_PAX_PAGEEXEC)
51088+
51089+#ifdef CONFIG_PAX_PAGEEXEC
51090+ && (*flags & MF_PAX_SEGMEXEC)
51091+#endif
51092+
51093+ )
51094+ {
51095+ *flags &= ~MF_PAX_PAGEEXEC;
51096+ retval = -EINVAL;
51097+ }
51098+
51099+ if ((*flags & MF_PAX_MPROTECT)
51100+
51101+#ifdef CONFIG_PAX_MPROTECT
51102+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51103+#endif
51104+
51105+ )
51106+ {
51107+ *flags &= ~MF_PAX_MPROTECT;
51108+ retval = -EINVAL;
51109+ }
51110+
51111+ if ((*flags & MF_PAX_EMUTRAMP)
51112+
51113+#ifdef CONFIG_PAX_EMUTRAMP
51114+ && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
51115+#endif
51116+
51117+ )
51118+ {
51119+ *flags &= ~MF_PAX_EMUTRAMP;
51120+ retval = -EINVAL;
51121+ }
51122+
51123+ return retval;
51124+}
51125+
51126+EXPORT_SYMBOL(pax_check_flags);
51127+
51128+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
51129+void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
51130+{
51131+ struct task_struct *tsk = current;
51132+ struct mm_struct *mm = current->mm;
51133+ char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
51134+ char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
51135+ char *path_exec = NULL;
51136+ char *path_fault = NULL;
51137+ unsigned long start = 0UL, end = 0UL, offset = 0UL;
51138+ siginfo_t info = { };
51139+
51140+ if (buffer_exec && buffer_fault) {
51141+ struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
51142+
51143+ down_read(&mm->mmap_sem);
51144+ vma = mm->mmap;
51145+ while (vma && (!vma_exec || !vma_fault)) {
51146+ if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
51147+ vma_exec = vma;
51148+ if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
51149+ vma_fault = vma;
51150+ vma = vma->vm_next;
51151+ }
51152+ if (vma_exec) {
51153+ path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
51154+ if (IS_ERR(path_exec))
51155+ path_exec = "<path too long>";
51156+ else {
51157+ path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
51158+ if (path_exec) {
51159+ *path_exec = 0;
51160+ path_exec = buffer_exec;
51161+ } else
51162+ path_exec = "<path too long>";
51163+ }
51164+ }
51165+ if (vma_fault) {
51166+ start = vma_fault->vm_start;
51167+ end = vma_fault->vm_end;
51168+ offset = vma_fault->vm_pgoff << PAGE_SHIFT;
51169+ if (vma_fault->vm_file) {
51170+ path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
51171+ if (IS_ERR(path_fault))
51172+ path_fault = "<path too long>";
51173+ else {
51174+ path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
51175+ if (path_fault) {
51176+ *path_fault = 0;
51177+ path_fault = buffer_fault;
51178+ } else
51179+ path_fault = "<path too long>";
51180+ }
51181+ } else
51182+ path_fault = "<anonymous mapping>";
51183+ }
51184+ up_read(&mm->mmap_sem);
51185+ }
51186+ if (tsk->signal->curr_ip)
51187+ printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
51188+ else
51189+ printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
51190+ 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),
51191+ from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
51192+ free_page((unsigned long)buffer_exec);
51193+ free_page((unsigned long)buffer_fault);
51194+ pax_report_insns(regs, pc, sp);
51195+ info.si_signo = SIGKILL;
51196+ info.si_errno = 0;
51197+ info.si_code = SI_KERNEL;
51198+ info.si_pid = 0;
51199+ info.si_uid = 0;
51200+ do_coredump(&info);
51201+}
51202+#endif
51203+
51204+#ifdef CONFIG_PAX_REFCOUNT
51205+void pax_report_refcount_overflow(struct pt_regs *regs)
51206+{
51207+ if (current->signal->curr_ip)
51208+ printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
51209+ &current->signal->curr_ip, current->comm, task_pid_nr(current),
51210+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51211+ else
51212+ printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
51213+ from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
51214+ print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
51215+ show_regs(regs);
51216+ force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
51217+}
51218+#endif
51219+
51220+#ifdef CONFIG_PAX_USERCOPY
51221+/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
51222+static noinline int check_stack_object(const void *obj, unsigned long len)
51223+{
51224+ const void * const stack = task_stack_page(current);
51225+ const void * const stackend = stack + THREAD_SIZE;
51226+
51227+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51228+ const void *frame = NULL;
51229+ const void *oldframe;
51230+#endif
51231+
51232+ if (obj + len < obj)
51233+ return -1;
51234+
51235+ if (obj + len <= stack || stackend <= obj)
51236+ return 0;
51237+
51238+ if (obj < stack || stackend < obj + len)
51239+ return -1;
51240+
51241+#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
51242+ oldframe = __builtin_frame_address(1);
51243+ if (oldframe)
51244+ frame = __builtin_frame_address(2);
51245+ /*
51246+ low ----------------------------------------------> high
51247+ [saved bp][saved ip][args][local vars][saved bp][saved ip]
51248+ ^----------------^
51249+ allow copies only within here
51250+ */
51251+ while (stack <= frame && frame < stackend) {
51252+ /* if obj + len extends past the last frame, this
51253+ check won't pass and the next frame will be 0,
51254+ causing us to bail out and correctly report
51255+ the copy as invalid
51256+ */
51257+ if (obj + len <= frame)
51258+ return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
51259+ oldframe = frame;
51260+ frame = *(const void * const *)frame;
51261+ }
51262+ return -1;
51263+#else
51264+ return 1;
51265+#endif
51266+}
51267+
51268+static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
51269+{
51270+ if (current->signal->curr_ip)
51271+ printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51272+ &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51273+ else
51274+ printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
51275+ to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
51276+ dump_stack();
51277+ gr_handle_kernel_exploit();
51278+ do_group_exit(SIGKILL);
51279+}
51280+#endif
51281+
51282+#ifdef CONFIG_PAX_USERCOPY
51283+static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
51284+{
51285+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
51286+ unsigned long textlow = ktla_ktva((unsigned long)_stext);
51287+#ifdef CONFIG_MODULES
51288+ unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
51289+#else
51290+ unsigned long texthigh = ktla_ktva((unsigned long)_etext);
51291+#endif
51292+
51293+#else
51294+ unsigned long textlow = (unsigned long)_stext;
51295+ unsigned long texthigh = (unsigned long)_etext;
51296+#endif
51297+
51298+ if (high <= textlow || low > texthigh)
51299+ return false;
51300+ else
51301+ return true;
51302+}
51303+#endif
51304+
51305+void __check_object_size(const void *ptr, unsigned long n, bool to_user)
51306+{
51307+
51308+#ifdef CONFIG_PAX_USERCOPY
51309+ const char *type;
51310+
51311+ if (!n)
51312+ return;
51313+
51314+ type = check_heap_object(ptr, n);
51315+ if (!type) {
51316+ int ret = check_stack_object(ptr, n);
51317+ if (ret == 1 || ret == 2)
51318+ return;
51319+ if (ret == 0) {
51320+ if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
51321+ type = "<kernel text>";
51322+ else
51323+ return;
51324+ } else
51325+ type = "<process stack>";
51326+ }
51327+
51328+ pax_report_usercopy(ptr, n, to_user, type);
51329+#endif
51330+
51331+}
51332+EXPORT_SYMBOL(__check_object_size);
51333+
51334+#ifdef CONFIG_PAX_MEMORY_STACKLEAK
51335+void pax_track_stack(void)
51336+{
51337+ unsigned long sp = (unsigned long)&sp;
51338+ if (sp < current_thread_info()->lowest_stack &&
51339+ sp > (unsigned long)task_stack_page(current))
51340+ current_thread_info()->lowest_stack = sp;
51341+}
51342+EXPORT_SYMBOL(pax_track_stack);
51343+#endif
51344+
51345+#ifdef CONFIG_PAX_SIZE_OVERFLOW
51346+void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
51347+{
51348+ printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
51349+ dump_stack();
51350+ do_group_exit(SIGKILL);
51351+}
51352+EXPORT_SYMBOL(report_size_overflow);
51353+#endif
51354diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
51355index 9f9992b..8b59411 100644
51356--- a/fs/ext2/balloc.c
51357+++ b/fs/ext2/balloc.c
51358@@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
51359
51360 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51361 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51362- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51363+ if (free_blocks < root_blocks + 1 &&
51364 !uid_eq(sbi->s_resuid, current_fsuid()) &&
51365 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51366- !in_group_p (sbi->s_resgid))) {
51367+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51368 return 0;
51369 }
51370 return 1;
51371diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
51372index 22548f5..41521d8 100644
51373--- a/fs/ext3/balloc.c
51374+++ b/fs/ext3/balloc.c
51375@@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
51376
51377 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
51378 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
51379- if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
51380+ if (free_blocks < root_blocks + 1 &&
51381 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
51382 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
51383- !in_group_p (sbi->s_resgid))) {
51384+ !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
51385 return 0;
51386 }
51387 return 1;
51388diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
51389index 92e68b3..115d987 100644
51390--- a/fs/ext4/balloc.c
51391+++ b/fs/ext4/balloc.c
51392@@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
51393 /* Hm, nope. Are (enough) root reserved clusters available? */
51394 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
51395 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
51396- capable(CAP_SYS_RESOURCE) ||
51397- (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
51398+ (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
51399+ capable_nolog(CAP_SYS_RESOURCE)) {
51400
51401 if (free_clusters >= (nclusters + dirty_clusters))
51402 return 1;
51403diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
51404index 3b83cd6..0f34dcd 100644
51405--- a/fs/ext4/ext4.h
51406+++ b/fs/ext4/ext4.h
51407@@ -1254,19 +1254,19 @@ struct ext4_sb_info {
51408 unsigned long s_mb_last_start;
51409
51410 /* stats for buddy allocator */
51411- atomic_t s_bal_reqs; /* number of reqs with len > 1 */
51412- atomic_t s_bal_success; /* we found long enough chunks */
51413- atomic_t s_bal_allocated; /* in blocks */
51414- atomic_t s_bal_ex_scanned; /* total extents scanned */
51415- atomic_t s_bal_goals; /* goal hits */
51416- atomic_t s_bal_breaks; /* too long searches */
51417- atomic_t s_bal_2orders; /* 2^order hits */
51418+ atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
51419+ atomic_unchecked_t s_bal_success; /* we found long enough chunks */
51420+ atomic_unchecked_t s_bal_allocated; /* in blocks */
51421+ atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
51422+ atomic_unchecked_t s_bal_goals; /* goal hits */
51423+ atomic_unchecked_t s_bal_breaks; /* too long searches */
51424+ atomic_unchecked_t s_bal_2orders; /* 2^order hits */
51425 spinlock_t s_bal_lock;
51426 unsigned long s_mb_buddies_generated;
51427 unsigned long long s_mb_generation_time;
51428- atomic_t s_mb_lost_chunks;
51429- atomic_t s_mb_preallocated;
51430- atomic_t s_mb_discarded;
51431+ atomic_unchecked_t s_mb_lost_chunks;
51432+ atomic_unchecked_t s_mb_preallocated;
51433+ atomic_unchecked_t s_mb_discarded;
51434 atomic_t s_lock_busy;
51435
51436 /* locality groups */
51437diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
51438index f3190ab..84ffb21 100644
51439--- a/fs/ext4/mballoc.c
51440+++ b/fs/ext4/mballoc.c
51441@@ -1754,7 +1754,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
51442 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
51443
51444 if (EXT4_SB(sb)->s_mb_stats)
51445- atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
51446+ atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
51447
51448 break;
51449 }
51450@@ -2059,7 +2059,7 @@ repeat:
51451 ac->ac_status = AC_STATUS_CONTINUE;
51452 ac->ac_flags |= EXT4_MB_HINT_FIRST;
51453 cr = 3;
51454- atomic_inc(&sbi->s_mb_lost_chunks);
51455+ atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
51456 goto repeat;
51457 }
51458 }
51459@@ -2567,25 +2567,25 @@ int ext4_mb_release(struct super_block *sb)
51460 if (sbi->s_mb_stats) {
51461 ext4_msg(sb, KERN_INFO,
51462 "mballoc: %u blocks %u reqs (%u success)",
51463- atomic_read(&sbi->s_bal_allocated),
51464- atomic_read(&sbi->s_bal_reqs),
51465- atomic_read(&sbi->s_bal_success));
51466+ atomic_read_unchecked(&sbi->s_bal_allocated),
51467+ atomic_read_unchecked(&sbi->s_bal_reqs),
51468+ atomic_read_unchecked(&sbi->s_bal_success));
51469 ext4_msg(sb, KERN_INFO,
51470 "mballoc: %u extents scanned, %u goal hits, "
51471 "%u 2^N hits, %u breaks, %u lost",
51472- atomic_read(&sbi->s_bal_ex_scanned),
51473- atomic_read(&sbi->s_bal_goals),
51474- atomic_read(&sbi->s_bal_2orders),
51475- atomic_read(&sbi->s_bal_breaks),
51476- atomic_read(&sbi->s_mb_lost_chunks));
51477+ atomic_read_unchecked(&sbi->s_bal_ex_scanned),
51478+ atomic_read_unchecked(&sbi->s_bal_goals),
51479+ atomic_read_unchecked(&sbi->s_bal_2orders),
51480+ atomic_read_unchecked(&sbi->s_bal_breaks),
51481+ atomic_read_unchecked(&sbi->s_mb_lost_chunks));
51482 ext4_msg(sb, KERN_INFO,
51483 "mballoc: %lu generated and it took %Lu",
51484 sbi->s_mb_buddies_generated,
51485 sbi->s_mb_generation_time);
51486 ext4_msg(sb, KERN_INFO,
51487 "mballoc: %u preallocated, %u discarded",
51488- atomic_read(&sbi->s_mb_preallocated),
51489- atomic_read(&sbi->s_mb_discarded));
51490+ atomic_read_unchecked(&sbi->s_mb_preallocated),
51491+ atomic_read_unchecked(&sbi->s_mb_discarded));
51492 }
51493
51494 free_percpu(sbi->s_locality_groups);
51495@@ -3039,16 +3039,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
51496 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
51497
51498 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
51499- atomic_inc(&sbi->s_bal_reqs);
51500- atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51501+ atomic_inc_unchecked(&sbi->s_bal_reqs);
51502+ atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
51503 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
51504- atomic_inc(&sbi->s_bal_success);
51505- atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
51506+ atomic_inc_unchecked(&sbi->s_bal_success);
51507+ atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
51508 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
51509 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
51510- atomic_inc(&sbi->s_bal_goals);
51511+ atomic_inc_unchecked(&sbi->s_bal_goals);
51512 if (ac->ac_found > sbi->s_mb_max_to_scan)
51513- atomic_inc(&sbi->s_bal_breaks);
51514+ atomic_inc_unchecked(&sbi->s_bal_breaks);
51515 }
51516
51517 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
51518@@ -3448,7 +3448,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
51519 trace_ext4_mb_new_inode_pa(ac, pa);
51520
51521 ext4_mb_use_inode_pa(ac, pa);
51522- atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
51523+ atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
51524
51525 ei = EXT4_I(ac->ac_inode);
51526 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51527@@ -3508,7 +3508,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
51528 trace_ext4_mb_new_group_pa(ac, pa);
51529
51530 ext4_mb_use_group_pa(ac, pa);
51531- atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51532+ atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
51533
51534 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
51535 lg = ac->ac_lg;
51536@@ -3597,7 +3597,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
51537 * from the bitmap and continue.
51538 */
51539 }
51540- atomic_add(free, &sbi->s_mb_discarded);
51541+ atomic_add_unchecked(free, &sbi->s_mb_discarded);
51542
51543 return err;
51544 }
51545@@ -3615,7 +3615,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
51546 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
51547 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
51548 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
51549- atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51550+ atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
51551 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
51552
51553 return 0;
51554diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
51555index b3b1f7d..cff51d5 100644
51556--- a/fs/ext4/mmp.c
51557+++ b/fs/ext4/mmp.c
51558@@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
51559 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
51560 const char *function, unsigned int line, const char *msg)
51561 {
51562- __ext4_warning(sb, function, line, msg);
51563+ __ext4_warning(sb, function, line, "%s", msg);
51564 __ext4_warning(sb, function, line,
51565 "MMP failure info: last update time: %llu, last update "
51566 "node: %s, last update device: %s\n",
51567diff --git a/fs/ext4/resize.c b/fs/ext4/resize.c
51568index 3beae6a..8cc5637 100644
51569--- a/fs/ext4/resize.c
51570+++ b/fs/ext4/resize.c
51571@@ -79,12 +79,20 @@ static int verify_group_input(struct super_block *sb,
51572 ext4_fsblk_t end = start + input->blocks_count;
51573 ext4_group_t group = input->group;
51574 ext4_fsblk_t itend = input->inode_table + sbi->s_itb_per_group;
51575- unsigned overhead = ext4_group_overhead_blocks(sb, group);
51576- ext4_fsblk_t metaend = start + overhead;
51577+ unsigned overhead;
51578+ ext4_fsblk_t metaend;
51579 struct buffer_head *bh = NULL;
51580 ext4_grpblk_t free_blocks_count, offset;
51581 int err = -EINVAL;
51582
51583+ if (group != sbi->s_groups_count) {
51584+ ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51585+ input->group, sbi->s_groups_count);
51586+ return -EINVAL;
51587+ }
51588+
51589+ overhead = ext4_group_overhead_blocks(sb, group);
51590+ metaend = start + overhead;
51591 input->free_blocks_count = free_blocks_count =
51592 input->blocks_count - 2 - overhead - sbi->s_itb_per_group;
51593
51594@@ -96,10 +104,7 @@ static int verify_group_input(struct super_block *sb,
51595 free_blocks_count, input->reserved_blocks);
51596
51597 ext4_get_group_no_and_offset(sb, start, NULL, &offset);
51598- if (group != sbi->s_groups_count)
51599- ext4_warning(sb, "Cannot add at group %u (only %u groups)",
51600- input->group, sbi->s_groups_count);
51601- else if (offset != 0)
51602+ if (offset != 0)
51603 ext4_warning(sb, "Last group not full");
51604 else if (input->reserved_blocks > input->blocks_count / 5)
51605 ext4_warning(sb, "Reserved blocks too high (%u)",
51606diff --git a/fs/ext4/super.c b/fs/ext4/super.c
51607index febbe0e..d0cdc02 100644
51608--- a/fs/ext4/super.c
51609+++ b/fs/ext4/super.c
51610@@ -1238,7 +1238,7 @@ static ext4_fsblk_t get_sb_block(void **data)
51611 }
51612
51613 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
51614-static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51615+static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
51616 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
51617
51618 #ifdef CONFIG_QUOTA
51619@@ -2380,7 +2380,7 @@ struct ext4_attr {
51620 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
51621 const char *, size_t);
51622 int offset;
51623-};
51624+} __do_const;
51625
51626 static int parse_strtoul(const char *buf,
51627 unsigned long max, unsigned long *value)
51628diff --git a/fs/fcntl.c b/fs/fcntl.c
51629index 6599222..e7bf0de 100644
51630--- a/fs/fcntl.c
51631+++ b/fs/fcntl.c
51632@@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
51633 if (err)
51634 return err;
51635
51636+ if (gr_handle_chroot_fowner(pid, type))
51637+ return -ENOENT;
51638+ if (gr_check_protected_task_fowner(pid, type))
51639+ return -EACCES;
51640+
51641 f_modown(filp, pid, type, force);
51642 return 0;
51643 }
51644diff --git a/fs/fhandle.c b/fs/fhandle.c
51645index 999ff5c..41f4109 100644
51646--- a/fs/fhandle.c
51647+++ b/fs/fhandle.c
51648@@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
51649 } else
51650 retval = 0;
51651 /* copy the mount id */
51652- if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
51653- sizeof(*mnt_id)) ||
51654+ if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
51655 copy_to_user(ufh, handle,
51656 sizeof(struct file_handle) + handle_bytes))
51657 retval = -EFAULT;
51658diff --git a/fs/fifo.c b/fs/fifo.c
51659index cf6f434..3d7942c 100644
51660--- a/fs/fifo.c
51661+++ b/fs/fifo.c
51662@@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
51663 */
51664 filp->f_op = &read_pipefifo_fops;
51665 pipe->r_counter++;
51666- if (pipe->readers++ == 0)
51667+ if (atomic_inc_return(&pipe->readers) == 1)
51668 wake_up_partner(inode);
51669
51670- if (!pipe->writers) {
51671+ if (!atomic_read(&pipe->writers)) {
51672 if ((filp->f_flags & O_NONBLOCK)) {
51673 /* suppress POLLHUP until we have
51674 * seen a writer */
51675@@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
51676 * errno=ENXIO when there is no process reading the FIFO.
51677 */
51678 ret = -ENXIO;
51679- if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
51680+ if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
51681 goto err;
51682
51683 filp->f_op = &write_pipefifo_fops;
51684 pipe->w_counter++;
51685- if (!pipe->writers++)
51686+ if (atomic_inc_return(&pipe->writers) == 1)
51687 wake_up_partner(inode);
51688
51689- if (!pipe->readers) {
51690+ if (!atomic_read(&pipe->readers)) {
51691 if (wait_for_partner(inode, &pipe->r_counter))
51692 goto err_wr;
51693 }
51694@@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
51695 */
51696 filp->f_op = &rdwr_pipefifo_fops;
51697
51698- pipe->readers++;
51699- pipe->writers++;
51700+ atomic_inc(&pipe->readers);
51701+ atomic_inc(&pipe->writers);
51702 pipe->r_counter++;
51703 pipe->w_counter++;
51704- if (pipe->readers == 1 || pipe->writers == 1)
51705+ if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
51706 wake_up_partner(inode);
51707 break;
51708
51709@@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
51710 return 0;
51711
51712 err_rd:
51713- if (!--pipe->readers)
51714+ if (atomic_dec_and_test(&pipe->readers))
51715 wake_up_interruptible(&pipe->wait);
51716 ret = -ERESTARTSYS;
51717 goto err;
51718
51719 err_wr:
51720- if (!--pipe->writers)
51721+ if (atomic_dec_and_test(&pipe->writers))
51722 wake_up_interruptible(&pipe->wait);
51723 ret = -ERESTARTSYS;
51724 goto err;
51725
51726 err:
51727- if (!pipe->readers && !pipe->writers)
51728+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
51729 free_pipe_info(inode);
51730
51731 err_nocleanup:
51732diff --git a/fs/file.c b/fs/file.c
51733index 3906d95..5fe379b 100644
51734--- a/fs/file.c
51735+++ b/fs/file.c
51736@@ -16,6 +16,7 @@
51737 #include <linux/slab.h>
51738 #include <linux/vmalloc.h>
51739 #include <linux/file.h>
51740+#include <linux/security.h>
51741 #include <linux/fdtable.h>
51742 #include <linux/bitops.h>
51743 #include <linux/interrupt.h>
51744@@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
51745 if (!file)
51746 return __close_fd(files, fd);
51747
51748+ gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
51749 if (fd >= rlimit(RLIMIT_NOFILE))
51750 return -EBADF;
51751
51752@@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
51753 if (unlikely(oldfd == newfd))
51754 return -EINVAL;
51755
51756+ gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
51757 if (newfd >= rlimit(RLIMIT_NOFILE))
51758 return -EBADF;
51759
51760@@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
51761 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
51762 {
51763 int err;
51764+ gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
51765 if (from >= rlimit(RLIMIT_NOFILE))
51766 return -EINVAL;
51767 err = alloc_fd(from, flags);
51768diff --git a/fs/filesystems.c b/fs/filesystems.c
51769index 92567d9..fcd8cbf 100644
51770--- a/fs/filesystems.c
51771+++ b/fs/filesystems.c
51772@@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
51773 int len = dot ? dot - name : strlen(name);
51774
51775 fs = __get_fs_type(name, len);
51776+#ifdef CONFIG_GRKERNSEC_MODHARDEN
51777+ if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
51778+#else
51779 if (!fs && (request_module("fs-%.*s", len, name) == 0))
51780+#endif
51781 fs = __get_fs_type(name, len);
51782
51783 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
51784diff --git a/fs/fs_struct.c b/fs/fs_struct.c
51785index d8ac61d..79a36f0 100644
51786--- a/fs/fs_struct.c
51787+++ b/fs/fs_struct.c
51788@@ -4,6 +4,7 @@
51789 #include <linux/path.h>
51790 #include <linux/slab.h>
51791 #include <linux/fs_struct.h>
51792+#include <linux/grsecurity.h>
51793 #include "internal.h"
51794
51795 /*
51796@@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
51797 write_seqcount_begin(&fs->seq);
51798 old_root = fs->root;
51799 fs->root = *path;
51800+ gr_set_chroot_entries(current, path);
51801 write_seqcount_end(&fs->seq);
51802 spin_unlock(&fs->lock);
51803 if (old_root.dentry)
51804@@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
51805 int hits = 0;
51806 spin_lock(&fs->lock);
51807 write_seqcount_begin(&fs->seq);
51808+ /* this root replacement is only done by pivot_root,
51809+ leave grsec's chroot tagging alone for this task
51810+ so that a pivoted root isn't treated as a chroot
51811+ */
51812 hits += replace_path(&fs->root, old_root, new_root);
51813 hits += replace_path(&fs->pwd, old_root, new_root);
51814 write_seqcount_end(&fs->seq);
51815@@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
51816 task_lock(tsk);
51817 spin_lock(&fs->lock);
51818 tsk->fs = NULL;
51819- kill = !--fs->users;
51820+ gr_clear_chroot_entries(tsk);
51821+ kill = !atomic_dec_return(&fs->users);
51822 spin_unlock(&fs->lock);
51823 task_unlock(tsk);
51824 if (kill)
51825@@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51826 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
51827 /* We don't need to lock fs - think why ;-) */
51828 if (fs) {
51829- fs->users = 1;
51830+ atomic_set(&fs->users, 1);
51831 fs->in_exec = 0;
51832 spin_lock_init(&fs->lock);
51833 seqcount_init(&fs->seq);
51834@@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
51835 spin_lock(&old->lock);
51836 fs->root = old->root;
51837 path_get(&fs->root);
51838+ /* instead of calling gr_set_chroot_entries here,
51839+ we call it from every caller of this function
51840+ */
51841 fs->pwd = old->pwd;
51842 path_get(&fs->pwd);
51843 spin_unlock(&old->lock);
51844@@ -139,8 +149,9 @@ int unshare_fs_struct(void)
51845
51846 task_lock(current);
51847 spin_lock(&fs->lock);
51848- kill = !--fs->users;
51849+ kill = !atomic_dec_return(&fs->users);
51850 current->fs = new_fs;
51851+ gr_set_chroot_entries(current, &new_fs->root);
51852 spin_unlock(&fs->lock);
51853 task_unlock(current);
51854
51855@@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
51856
51857 int current_umask(void)
51858 {
51859- return current->fs->umask;
51860+ return current->fs->umask | gr_acl_umask();
51861 }
51862 EXPORT_SYMBOL(current_umask);
51863
51864 /* to be mentioned only in INIT_TASK */
51865 struct fs_struct init_fs = {
51866- .users = 1,
51867+ .users = ATOMIC_INIT(1),
51868 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
51869 .seq = SEQCNT_ZERO,
51870 .umask = 0022,
51871diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
51872index e2cba1f..17a25bb 100644
51873--- a/fs/fscache/cookie.c
51874+++ b/fs/fscache/cookie.c
51875@@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
51876 parent ? (char *) parent->def->name : "<no-parent>",
51877 def->name, netfs_data);
51878
51879- fscache_stat(&fscache_n_acquires);
51880+ fscache_stat_unchecked(&fscache_n_acquires);
51881
51882 /* if there's no parent cookie, then we don't create one here either */
51883 if (!parent) {
51884- fscache_stat(&fscache_n_acquires_null);
51885+ fscache_stat_unchecked(&fscache_n_acquires_null);
51886 _leave(" [no parent]");
51887 return NULL;
51888 }
51889@@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
51890 /* allocate and initialise a cookie */
51891 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
51892 if (!cookie) {
51893- fscache_stat(&fscache_n_acquires_oom);
51894+ fscache_stat_unchecked(&fscache_n_acquires_oom);
51895 _leave(" [ENOMEM]");
51896 return NULL;
51897 }
51898@@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51899
51900 switch (cookie->def->type) {
51901 case FSCACHE_COOKIE_TYPE_INDEX:
51902- fscache_stat(&fscache_n_cookie_index);
51903+ fscache_stat_unchecked(&fscache_n_cookie_index);
51904 break;
51905 case FSCACHE_COOKIE_TYPE_DATAFILE:
51906- fscache_stat(&fscache_n_cookie_data);
51907+ fscache_stat_unchecked(&fscache_n_cookie_data);
51908 break;
51909 default:
51910- fscache_stat(&fscache_n_cookie_special);
51911+ fscache_stat_unchecked(&fscache_n_cookie_special);
51912 break;
51913 }
51914
51915@@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
51916 if (fscache_acquire_non_index_cookie(cookie) < 0) {
51917 atomic_dec(&parent->n_children);
51918 __fscache_cookie_put(cookie);
51919- fscache_stat(&fscache_n_acquires_nobufs);
51920+ fscache_stat_unchecked(&fscache_n_acquires_nobufs);
51921 _leave(" = NULL");
51922 return NULL;
51923 }
51924 }
51925
51926- fscache_stat(&fscache_n_acquires_ok);
51927+ fscache_stat_unchecked(&fscache_n_acquires_ok);
51928 _leave(" = %p", cookie);
51929 return cookie;
51930 }
51931@@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
51932 cache = fscache_select_cache_for_object(cookie->parent);
51933 if (!cache) {
51934 up_read(&fscache_addremove_sem);
51935- fscache_stat(&fscache_n_acquires_no_cache);
51936+ fscache_stat_unchecked(&fscache_n_acquires_no_cache);
51937 _leave(" = -ENOMEDIUM [no cache]");
51938 return -ENOMEDIUM;
51939 }
51940@@ -255,12 +255,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
51941 object = cache->ops->alloc_object(cache, cookie);
51942 fscache_stat_d(&fscache_n_cop_alloc_object);
51943 if (IS_ERR(object)) {
51944- fscache_stat(&fscache_n_object_no_alloc);
51945+ fscache_stat_unchecked(&fscache_n_object_no_alloc);
51946 ret = PTR_ERR(object);
51947 goto error;
51948 }
51949
51950- fscache_stat(&fscache_n_object_alloc);
51951+ fscache_stat_unchecked(&fscache_n_object_alloc);
51952
51953 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
51954
51955@@ -376,7 +376,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
51956
51957 _enter("{%s}", cookie->def->name);
51958
51959- fscache_stat(&fscache_n_invalidates);
51960+ fscache_stat_unchecked(&fscache_n_invalidates);
51961
51962 /* Only permit invalidation of data files. Invalidating an index will
51963 * require the caller to release all its attachments to the tree rooted
51964@@ -434,10 +434,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
51965 {
51966 struct fscache_object *object;
51967
51968- fscache_stat(&fscache_n_updates);
51969+ fscache_stat_unchecked(&fscache_n_updates);
51970
51971 if (!cookie) {
51972- fscache_stat(&fscache_n_updates_null);
51973+ fscache_stat_unchecked(&fscache_n_updates_null);
51974 _leave(" [no cookie]");
51975 return;
51976 }
51977@@ -471,12 +471,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51978 struct fscache_object *object;
51979 unsigned long event;
51980
51981- fscache_stat(&fscache_n_relinquishes);
51982+ fscache_stat_unchecked(&fscache_n_relinquishes);
51983 if (retire)
51984- fscache_stat(&fscache_n_relinquishes_retire);
51985+ fscache_stat_unchecked(&fscache_n_relinquishes_retire);
51986
51987 if (!cookie) {
51988- fscache_stat(&fscache_n_relinquishes_null);
51989+ fscache_stat_unchecked(&fscache_n_relinquishes_null);
51990 _leave(" [no cookie]");
51991 return;
51992 }
51993@@ -492,7 +492,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
51994
51995 /* wait for the cookie to finish being instantiated (or to fail) */
51996 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
51997- fscache_stat(&fscache_n_relinquishes_waitcrt);
51998+ fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
51999 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
52000 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
52001 }
52002diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
52003index ee38fef..0a326d4 100644
52004--- a/fs/fscache/internal.h
52005+++ b/fs/fscache/internal.h
52006@@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
52007 * stats.c
52008 */
52009 #ifdef CONFIG_FSCACHE_STATS
52010-extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52011-extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52012+extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
52013+extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
52014
52015-extern atomic_t fscache_n_op_pend;
52016-extern atomic_t fscache_n_op_run;
52017-extern atomic_t fscache_n_op_enqueue;
52018-extern atomic_t fscache_n_op_deferred_release;
52019-extern atomic_t fscache_n_op_release;
52020-extern atomic_t fscache_n_op_gc;
52021-extern atomic_t fscache_n_op_cancelled;
52022-extern atomic_t fscache_n_op_rejected;
52023+extern atomic_unchecked_t fscache_n_op_pend;
52024+extern atomic_unchecked_t fscache_n_op_run;
52025+extern atomic_unchecked_t fscache_n_op_enqueue;
52026+extern atomic_unchecked_t fscache_n_op_deferred_release;
52027+extern atomic_unchecked_t fscache_n_op_release;
52028+extern atomic_unchecked_t fscache_n_op_gc;
52029+extern atomic_unchecked_t fscache_n_op_cancelled;
52030+extern atomic_unchecked_t fscache_n_op_rejected;
52031
52032-extern atomic_t fscache_n_attr_changed;
52033-extern atomic_t fscache_n_attr_changed_ok;
52034-extern atomic_t fscache_n_attr_changed_nobufs;
52035-extern atomic_t fscache_n_attr_changed_nomem;
52036-extern atomic_t fscache_n_attr_changed_calls;
52037+extern atomic_unchecked_t fscache_n_attr_changed;
52038+extern atomic_unchecked_t fscache_n_attr_changed_ok;
52039+extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
52040+extern atomic_unchecked_t fscache_n_attr_changed_nomem;
52041+extern atomic_unchecked_t fscache_n_attr_changed_calls;
52042
52043-extern atomic_t fscache_n_allocs;
52044-extern atomic_t fscache_n_allocs_ok;
52045-extern atomic_t fscache_n_allocs_wait;
52046-extern atomic_t fscache_n_allocs_nobufs;
52047-extern atomic_t fscache_n_allocs_intr;
52048-extern atomic_t fscache_n_allocs_object_dead;
52049-extern atomic_t fscache_n_alloc_ops;
52050-extern atomic_t fscache_n_alloc_op_waits;
52051+extern atomic_unchecked_t fscache_n_allocs;
52052+extern atomic_unchecked_t fscache_n_allocs_ok;
52053+extern atomic_unchecked_t fscache_n_allocs_wait;
52054+extern atomic_unchecked_t fscache_n_allocs_nobufs;
52055+extern atomic_unchecked_t fscache_n_allocs_intr;
52056+extern atomic_unchecked_t fscache_n_allocs_object_dead;
52057+extern atomic_unchecked_t fscache_n_alloc_ops;
52058+extern atomic_unchecked_t fscache_n_alloc_op_waits;
52059
52060-extern atomic_t fscache_n_retrievals;
52061-extern atomic_t fscache_n_retrievals_ok;
52062-extern atomic_t fscache_n_retrievals_wait;
52063-extern atomic_t fscache_n_retrievals_nodata;
52064-extern atomic_t fscache_n_retrievals_nobufs;
52065-extern atomic_t fscache_n_retrievals_intr;
52066-extern atomic_t fscache_n_retrievals_nomem;
52067-extern atomic_t fscache_n_retrievals_object_dead;
52068-extern atomic_t fscache_n_retrieval_ops;
52069-extern atomic_t fscache_n_retrieval_op_waits;
52070+extern atomic_unchecked_t fscache_n_retrievals;
52071+extern atomic_unchecked_t fscache_n_retrievals_ok;
52072+extern atomic_unchecked_t fscache_n_retrievals_wait;
52073+extern atomic_unchecked_t fscache_n_retrievals_nodata;
52074+extern atomic_unchecked_t fscache_n_retrievals_nobufs;
52075+extern atomic_unchecked_t fscache_n_retrievals_intr;
52076+extern atomic_unchecked_t fscache_n_retrievals_nomem;
52077+extern atomic_unchecked_t fscache_n_retrievals_object_dead;
52078+extern atomic_unchecked_t fscache_n_retrieval_ops;
52079+extern atomic_unchecked_t fscache_n_retrieval_op_waits;
52080
52081-extern atomic_t fscache_n_stores;
52082-extern atomic_t fscache_n_stores_ok;
52083-extern atomic_t fscache_n_stores_again;
52084-extern atomic_t fscache_n_stores_nobufs;
52085-extern atomic_t fscache_n_stores_oom;
52086-extern atomic_t fscache_n_store_ops;
52087-extern atomic_t fscache_n_store_calls;
52088-extern atomic_t fscache_n_store_pages;
52089-extern atomic_t fscache_n_store_radix_deletes;
52090-extern atomic_t fscache_n_store_pages_over_limit;
52091+extern atomic_unchecked_t fscache_n_stores;
52092+extern atomic_unchecked_t fscache_n_stores_ok;
52093+extern atomic_unchecked_t fscache_n_stores_again;
52094+extern atomic_unchecked_t fscache_n_stores_nobufs;
52095+extern atomic_unchecked_t fscache_n_stores_oom;
52096+extern atomic_unchecked_t fscache_n_store_ops;
52097+extern atomic_unchecked_t fscache_n_store_calls;
52098+extern atomic_unchecked_t fscache_n_store_pages;
52099+extern atomic_unchecked_t fscache_n_store_radix_deletes;
52100+extern atomic_unchecked_t fscache_n_store_pages_over_limit;
52101
52102-extern atomic_t fscache_n_store_vmscan_not_storing;
52103-extern atomic_t fscache_n_store_vmscan_gone;
52104-extern atomic_t fscache_n_store_vmscan_busy;
52105-extern atomic_t fscache_n_store_vmscan_cancelled;
52106-extern atomic_t fscache_n_store_vmscan_wait;
52107+extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52108+extern atomic_unchecked_t fscache_n_store_vmscan_gone;
52109+extern atomic_unchecked_t fscache_n_store_vmscan_busy;
52110+extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52111+extern atomic_unchecked_t fscache_n_store_vmscan_wait;
52112
52113-extern atomic_t fscache_n_marks;
52114-extern atomic_t fscache_n_uncaches;
52115+extern atomic_unchecked_t fscache_n_marks;
52116+extern atomic_unchecked_t fscache_n_uncaches;
52117
52118-extern atomic_t fscache_n_acquires;
52119-extern atomic_t fscache_n_acquires_null;
52120-extern atomic_t fscache_n_acquires_no_cache;
52121-extern atomic_t fscache_n_acquires_ok;
52122-extern atomic_t fscache_n_acquires_nobufs;
52123-extern atomic_t fscache_n_acquires_oom;
52124+extern atomic_unchecked_t fscache_n_acquires;
52125+extern atomic_unchecked_t fscache_n_acquires_null;
52126+extern atomic_unchecked_t fscache_n_acquires_no_cache;
52127+extern atomic_unchecked_t fscache_n_acquires_ok;
52128+extern atomic_unchecked_t fscache_n_acquires_nobufs;
52129+extern atomic_unchecked_t fscache_n_acquires_oom;
52130
52131-extern atomic_t fscache_n_invalidates;
52132-extern atomic_t fscache_n_invalidates_run;
52133+extern atomic_unchecked_t fscache_n_invalidates;
52134+extern atomic_unchecked_t fscache_n_invalidates_run;
52135
52136-extern atomic_t fscache_n_updates;
52137-extern atomic_t fscache_n_updates_null;
52138-extern atomic_t fscache_n_updates_run;
52139+extern atomic_unchecked_t fscache_n_updates;
52140+extern atomic_unchecked_t fscache_n_updates_null;
52141+extern atomic_unchecked_t fscache_n_updates_run;
52142
52143-extern atomic_t fscache_n_relinquishes;
52144-extern atomic_t fscache_n_relinquishes_null;
52145-extern atomic_t fscache_n_relinquishes_waitcrt;
52146-extern atomic_t fscache_n_relinquishes_retire;
52147+extern atomic_unchecked_t fscache_n_relinquishes;
52148+extern atomic_unchecked_t fscache_n_relinquishes_null;
52149+extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
52150+extern atomic_unchecked_t fscache_n_relinquishes_retire;
52151
52152-extern atomic_t fscache_n_cookie_index;
52153-extern atomic_t fscache_n_cookie_data;
52154-extern atomic_t fscache_n_cookie_special;
52155+extern atomic_unchecked_t fscache_n_cookie_index;
52156+extern atomic_unchecked_t fscache_n_cookie_data;
52157+extern atomic_unchecked_t fscache_n_cookie_special;
52158
52159-extern atomic_t fscache_n_object_alloc;
52160-extern atomic_t fscache_n_object_no_alloc;
52161-extern atomic_t fscache_n_object_lookups;
52162-extern atomic_t fscache_n_object_lookups_negative;
52163-extern atomic_t fscache_n_object_lookups_positive;
52164-extern atomic_t fscache_n_object_lookups_timed_out;
52165-extern atomic_t fscache_n_object_created;
52166-extern atomic_t fscache_n_object_avail;
52167-extern atomic_t fscache_n_object_dead;
52168+extern atomic_unchecked_t fscache_n_object_alloc;
52169+extern atomic_unchecked_t fscache_n_object_no_alloc;
52170+extern atomic_unchecked_t fscache_n_object_lookups;
52171+extern atomic_unchecked_t fscache_n_object_lookups_negative;
52172+extern atomic_unchecked_t fscache_n_object_lookups_positive;
52173+extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
52174+extern atomic_unchecked_t fscache_n_object_created;
52175+extern atomic_unchecked_t fscache_n_object_avail;
52176+extern atomic_unchecked_t fscache_n_object_dead;
52177
52178-extern atomic_t fscache_n_checkaux_none;
52179-extern atomic_t fscache_n_checkaux_okay;
52180-extern atomic_t fscache_n_checkaux_update;
52181-extern atomic_t fscache_n_checkaux_obsolete;
52182+extern atomic_unchecked_t fscache_n_checkaux_none;
52183+extern atomic_unchecked_t fscache_n_checkaux_okay;
52184+extern atomic_unchecked_t fscache_n_checkaux_update;
52185+extern atomic_unchecked_t fscache_n_checkaux_obsolete;
52186
52187 extern atomic_t fscache_n_cop_alloc_object;
52188 extern atomic_t fscache_n_cop_lookup_object;
52189@@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
52190 atomic_inc(stat);
52191 }
52192
52193+static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
52194+{
52195+ atomic_inc_unchecked(stat);
52196+}
52197+
52198 static inline void fscache_stat_d(atomic_t *stat)
52199 {
52200 atomic_dec(stat);
52201@@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
52202
52203 #define __fscache_stat(stat) (NULL)
52204 #define fscache_stat(stat) do {} while (0)
52205+#define fscache_stat_unchecked(stat) do {} while (0)
52206 #define fscache_stat_d(stat) do {} while (0)
52207 #endif
52208
52209diff --git a/fs/fscache/object.c b/fs/fscache/object.c
52210index 50d41c1..10ee117 100644
52211--- a/fs/fscache/object.c
52212+++ b/fs/fscache/object.c
52213@@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52214 /* Invalidate an object on disk */
52215 case FSCACHE_OBJECT_INVALIDATING:
52216 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
52217- fscache_stat(&fscache_n_invalidates_run);
52218+ fscache_stat_unchecked(&fscache_n_invalidates_run);
52219 fscache_stat(&fscache_n_cop_invalidate_object);
52220 fscache_invalidate_object(object);
52221 fscache_stat_d(&fscache_n_cop_invalidate_object);
52222@@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52223 /* update the object metadata on disk */
52224 case FSCACHE_OBJECT_UPDATING:
52225 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
52226- fscache_stat(&fscache_n_updates_run);
52227+ fscache_stat_unchecked(&fscache_n_updates_run);
52228 fscache_stat(&fscache_n_cop_update_object);
52229 object->cache->ops->update_object(object);
52230 fscache_stat_d(&fscache_n_cop_update_object);
52231@@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52232 spin_lock(&object->lock);
52233 object->state = FSCACHE_OBJECT_DEAD;
52234 spin_unlock(&object->lock);
52235- fscache_stat(&fscache_n_object_dead);
52236+ fscache_stat_unchecked(&fscache_n_object_dead);
52237 goto terminal_transit;
52238
52239 /* handle the parent cache of this object being withdrawn from
52240@@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
52241 spin_lock(&object->lock);
52242 object->state = FSCACHE_OBJECT_DEAD;
52243 spin_unlock(&object->lock);
52244- fscache_stat(&fscache_n_object_dead);
52245+ fscache_stat_unchecked(&fscache_n_object_dead);
52246 goto terminal_transit;
52247
52248 /* complain about the object being woken up once it is
52249@@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52250 parent->cookie->def->name, cookie->def->name,
52251 object->cache->tag->name);
52252
52253- fscache_stat(&fscache_n_object_lookups);
52254+ fscache_stat_unchecked(&fscache_n_object_lookups);
52255 fscache_stat(&fscache_n_cop_lookup_object);
52256 ret = object->cache->ops->lookup_object(object);
52257 fscache_stat_d(&fscache_n_cop_lookup_object);
52258@@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
52259 if (ret == -ETIMEDOUT) {
52260 /* probably stuck behind another object, so move this one to
52261 * the back of the queue */
52262- fscache_stat(&fscache_n_object_lookups_timed_out);
52263+ fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
52264 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52265 }
52266
52267@@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
52268
52269 spin_lock(&object->lock);
52270 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52271- fscache_stat(&fscache_n_object_lookups_negative);
52272+ fscache_stat_unchecked(&fscache_n_object_lookups_negative);
52273
52274 /* transit here to allow write requests to begin stacking up
52275 * and read requests to begin returning ENODATA */
52276@@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
52277 * result, in which case there may be data available */
52278 spin_lock(&object->lock);
52279 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
52280- fscache_stat(&fscache_n_object_lookups_positive);
52281+ fscache_stat_unchecked(&fscache_n_object_lookups_positive);
52282
52283 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
52284
52285@@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
52286 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
52287 } else {
52288 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
52289- fscache_stat(&fscache_n_object_created);
52290+ fscache_stat_unchecked(&fscache_n_object_created);
52291
52292 object->state = FSCACHE_OBJECT_AVAILABLE;
52293 spin_unlock(&object->lock);
52294@@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
52295 fscache_enqueue_dependents(object);
52296
52297 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
52298- fscache_stat(&fscache_n_object_avail);
52299+ fscache_stat_unchecked(&fscache_n_object_avail);
52300
52301 _leave("");
52302 }
52303@@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52304 enum fscache_checkaux result;
52305
52306 if (!object->cookie->def->check_aux) {
52307- fscache_stat(&fscache_n_checkaux_none);
52308+ fscache_stat_unchecked(&fscache_n_checkaux_none);
52309 return FSCACHE_CHECKAUX_OKAY;
52310 }
52311
52312@@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
52313 switch (result) {
52314 /* entry okay as is */
52315 case FSCACHE_CHECKAUX_OKAY:
52316- fscache_stat(&fscache_n_checkaux_okay);
52317+ fscache_stat_unchecked(&fscache_n_checkaux_okay);
52318 break;
52319
52320 /* entry requires update */
52321 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
52322- fscache_stat(&fscache_n_checkaux_update);
52323+ fscache_stat_unchecked(&fscache_n_checkaux_update);
52324 break;
52325
52326 /* entry requires deletion */
52327 case FSCACHE_CHECKAUX_OBSOLETE:
52328- fscache_stat(&fscache_n_checkaux_obsolete);
52329+ fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
52330 break;
52331
52332 default:
52333diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
52334index 762a9ec..2023284 100644
52335--- a/fs/fscache/operation.c
52336+++ b/fs/fscache/operation.c
52337@@ -17,7 +17,7 @@
52338 #include <linux/slab.h>
52339 #include "internal.h"
52340
52341-atomic_t fscache_op_debug_id;
52342+atomic_unchecked_t fscache_op_debug_id;
52343 EXPORT_SYMBOL(fscache_op_debug_id);
52344
52345 /**
52346@@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
52347 ASSERTCMP(atomic_read(&op->usage), >, 0);
52348 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
52349
52350- fscache_stat(&fscache_n_op_enqueue);
52351+ fscache_stat_unchecked(&fscache_n_op_enqueue);
52352 switch (op->flags & FSCACHE_OP_TYPE) {
52353 case FSCACHE_OP_ASYNC:
52354 _debug("queue async");
52355@@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
52356 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
52357 if (op->processor)
52358 fscache_enqueue_operation(op);
52359- fscache_stat(&fscache_n_op_run);
52360+ fscache_stat_unchecked(&fscache_n_op_run);
52361 }
52362
52363 /*
52364@@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52365 if (object->n_in_progress > 0) {
52366 atomic_inc(&op->usage);
52367 list_add_tail(&op->pend_link, &object->pending_ops);
52368- fscache_stat(&fscache_n_op_pend);
52369+ fscache_stat_unchecked(&fscache_n_op_pend);
52370 } else if (!list_empty(&object->pending_ops)) {
52371 atomic_inc(&op->usage);
52372 list_add_tail(&op->pend_link, &object->pending_ops);
52373- fscache_stat(&fscache_n_op_pend);
52374+ fscache_stat_unchecked(&fscache_n_op_pend);
52375 fscache_start_operations(object);
52376 } else {
52377 ASSERTCMP(object->n_in_progress, ==, 0);
52378@@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
52379 object->n_exclusive++; /* reads and writes must wait */
52380 atomic_inc(&op->usage);
52381 list_add_tail(&op->pend_link, &object->pending_ops);
52382- fscache_stat(&fscache_n_op_pend);
52383+ fscache_stat_unchecked(&fscache_n_op_pend);
52384 ret = 0;
52385 } else {
52386 /* If we're in any other state, there must have been an I/O
52387@@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
52388 if (object->n_exclusive > 0) {
52389 atomic_inc(&op->usage);
52390 list_add_tail(&op->pend_link, &object->pending_ops);
52391- fscache_stat(&fscache_n_op_pend);
52392+ fscache_stat_unchecked(&fscache_n_op_pend);
52393 } else if (!list_empty(&object->pending_ops)) {
52394 atomic_inc(&op->usage);
52395 list_add_tail(&op->pend_link, &object->pending_ops);
52396- fscache_stat(&fscache_n_op_pend);
52397+ fscache_stat_unchecked(&fscache_n_op_pend);
52398 fscache_start_operations(object);
52399 } else {
52400 ASSERTCMP(object->n_exclusive, ==, 0);
52401@@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
52402 object->n_ops++;
52403 atomic_inc(&op->usage);
52404 list_add_tail(&op->pend_link, &object->pending_ops);
52405- fscache_stat(&fscache_n_op_pend);
52406+ fscache_stat_unchecked(&fscache_n_op_pend);
52407 ret = 0;
52408 } else if (object->state == FSCACHE_OBJECT_DYING ||
52409 object->state == FSCACHE_OBJECT_LC_DYING ||
52410 object->state == FSCACHE_OBJECT_WITHDRAWING) {
52411- fscache_stat(&fscache_n_op_rejected);
52412+ fscache_stat_unchecked(&fscache_n_op_rejected);
52413 op->state = FSCACHE_OP_ST_CANCELLED;
52414 ret = -ENOBUFS;
52415 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
52416@@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
52417 ret = -EBUSY;
52418 if (op->state == FSCACHE_OP_ST_PENDING) {
52419 ASSERT(!list_empty(&op->pend_link));
52420- fscache_stat(&fscache_n_op_cancelled);
52421+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52422 list_del_init(&op->pend_link);
52423 if (do_cancel)
52424 do_cancel(op);
52425@@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
52426 while (!list_empty(&object->pending_ops)) {
52427 op = list_entry(object->pending_ops.next,
52428 struct fscache_operation, pend_link);
52429- fscache_stat(&fscache_n_op_cancelled);
52430+ fscache_stat_unchecked(&fscache_n_op_cancelled);
52431 list_del_init(&op->pend_link);
52432
52433 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
52434@@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
52435 op->state, ==, FSCACHE_OP_ST_CANCELLED);
52436 op->state = FSCACHE_OP_ST_DEAD;
52437
52438- fscache_stat(&fscache_n_op_release);
52439+ fscache_stat_unchecked(&fscache_n_op_release);
52440
52441 if (op->release) {
52442 op->release(op);
52443@@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
52444 * lock, and defer it otherwise */
52445 if (!spin_trylock(&object->lock)) {
52446 _debug("defer put");
52447- fscache_stat(&fscache_n_op_deferred_release);
52448+ fscache_stat_unchecked(&fscache_n_op_deferred_release);
52449
52450 cache = object->cache;
52451 spin_lock(&cache->op_gc_list_lock);
52452@@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
52453
52454 _debug("GC DEFERRED REL OBJ%x OP%x",
52455 object->debug_id, op->debug_id);
52456- fscache_stat(&fscache_n_op_gc);
52457+ fscache_stat_unchecked(&fscache_n_op_gc);
52458
52459 ASSERTCMP(atomic_read(&op->usage), ==, 0);
52460 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
52461diff --git a/fs/fscache/page.c b/fs/fscache/page.c
52462index ff000e5..c44ec6d 100644
52463--- a/fs/fscache/page.c
52464+++ b/fs/fscache/page.c
52465@@ -61,7 +61,7 @@ try_again:
52466 val = radix_tree_lookup(&cookie->stores, page->index);
52467 if (!val) {
52468 rcu_read_unlock();
52469- fscache_stat(&fscache_n_store_vmscan_not_storing);
52470+ fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
52471 __fscache_uncache_page(cookie, page);
52472 return true;
52473 }
52474@@ -91,11 +91,11 @@ try_again:
52475 spin_unlock(&cookie->stores_lock);
52476
52477 if (xpage) {
52478- fscache_stat(&fscache_n_store_vmscan_cancelled);
52479- fscache_stat(&fscache_n_store_radix_deletes);
52480+ fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
52481+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52482 ASSERTCMP(xpage, ==, page);
52483 } else {
52484- fscache_stat(&fscache_n_store_vmscan_gone);
52485+ fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
52486 }
52487
52488 wake_up_bit(&cookie->flags, 0);
52489@@ -110,11 +110,11 @@ page_busy:
52490 * sleeping on memory allocation, so we may need to impose a timeout
52491 * too. */
52492 if (!(gfp & __GFP_WAIT)) {
52493- fscache_stat(&fscache_n_store_vmscan_busy);
52494+ fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
52495 return false;
52496 }
52497
52498- fscache_stat(&fscache_n_store_vmscan_wait);
52499+ fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
52500 __fscache_wait_on_page_write(cookie, page);
52501 gfp &= ~__GFP_WAIT;
52502 goto try_again;
52503@@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
52504 FSCACHE_COOKIE_STORING_TAG);
52505 if (!radix_tree_tag_get(&cookie->stores, page->index,
52506 FSCACHE_COOKIE_PENDING_TAG)) {
52507- fscache_stat(&fscache_n_store_radix_deletes);
52508+ fscache_stat_unchecked(&fscache_n_store_radix_deletes);
52509 xpage = radix_tree_delete(&cookie->stores, page->index);
52510 }
52511 spin_unlock(&cookie->stores_lock);
52512@@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
52513
52514 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
52515
52516- fscache_stat(&fscache_n_attr_changed_calls);
52517+ fscache_stat_unchecked(&fscache_n_attr_changed_calls);
52518
52519 if (fscache_object_is_active(object)) {
52520 fscache_stat(&fscache_n_cop_attr_changed);
52521@@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52522
52523 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52524
52525- fscache_stat(&fscache_n_attr_changed);
52526+ fscache_stat_unchecked(&fscache_n_attr_changed);
52527
52528 op = kzalloc(sizeof(*op), GFP_KERNEL);
52529 if (!op) {
52530- fscache_stat(&fscache_n_attr_changed_nomem);
52531+ fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
52532 _leave(" = -ENOMEM");
52533 return -ENOMEM;
52534 }
52535@@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52536 if (fscache_submit_exclusive_op(object, op) < 0)
52537 goto nobufs;
52538 spin_unlock(&cookie->lock);
52539- fscache_stat(&fscache_n_attr_changed_ok);
52540+ fscache_stat_unchecked(&fscache_n_attr_changed_ok);
52541 fscache_put_operation(op);
52542 _leave(" = 0");
52543 return 0;
52544@@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
52545 nobufs:
52546 spin_unlock(&cookie->lock);
52547 kfree(op);
52548- fscache_stat(&fscache_n_attr_changed_nobufs);
52549+ fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
52550 _leave(" = %d", -ENOBUFS);
52551 return -ENOBUFS;
52552 }
52553@@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
52554 /* allocate a retrieval operation and attempt to submit it */
52555 op = kzalloc(sizeof(*op), GFP_NOIO);
52556 if (!op) {
52557- fscache_stat(&fscache_n_retrievals_nomem);
52558+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52559 return NULL;
52560 }
52561
52562@@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
52563 return 0;
52564 }
52565
52566- fscache_stat(&fscache_n_retrievals_wait);
52567+ fscache_stat_unchecked(&fscache_n_retrievals_wait);
52568
52569 jif = jiffies;
52570 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
52571 fscache_wait_bit_interruptible,
52572 TASK_INTERRUPTIBLE) != 0) {
52573- fscache_stat(&fscache_n_retrievals_intr);
52574+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52575 _leave(" = -ERESTARTSYS");
52576 return -ERESTARTSYS;
52577 }
52578@@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
52579 */
52580 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52581 struct fscache_retrieval *op,
52582- atomic_t *stat_op_waits,
52583- atomic_t *stat_object_dead)
52584+ atomic_unchecked_t *stat_op_waits,
52585+ atomic_unchecked_t *stat_object_dead)
52586 {
52587 int ret;
52588
52589@@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52590 goto check_if_dead;
52591
52592 _debug(">>> WT");
52593- fscache_stat(stat_op_waits);
52594+ fscache_stat_unchecked(stat_op_waits);
52595 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
52596 fscache_wait_bit_interruptible,
52597 TASK_INTERRUPTIBLE) != 0) {
52598@@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
52599
52600 check_if_dead:
52601 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
52602- fscache_stat(stat_object_dead);
52603+ fscache_stat_unchecked(stat_object_dead);
52604 _leave(" = -ENOBUFS [cancelled]");
52605 return -ENOBUFS;
52606 }
52607 if (unlikely(fscache_object_is_dead(object))) {
52608 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
52609 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
52610- fscache_stat(stat_object_dead);
52611+ fscache_stat_unchecked(stat_object_dead);
52612 return -ENOBUFS;
52613 }
52614 return 0;
52615@@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52616
52617 _enter("%p,%p,,,", cookie, page);
52618
52619- fscache_stat(&fscache_n_retrievals);
52620+ fscache_stat_unchecked(&fscache_n_retrievals);
52621
52622 if (hlist_empty(&cookie->backing_objects))
52623 goto nobufs;
52624@@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52625 goto nobufs_unlock_dec;
52626 spin_unlock(&cookie->lock);
52627
52628- fscache_stat(&fscache_n_retrieval_ops);
52629+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52630
52631 /* pin the netfs read context in case we need to do the actual netfs
52632 * read because we've encountered a cache read failure */
52633@@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
52634
52635 error:
52636 if (ret == -ENOMEM)
52637- fscache_stat(&fscache_n_retrievals_nomem);
52638+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52639 else if (ret == -ERESTARTSYS)
52640- fscache_stat(&fscache_n_retrievals_intr);
52641+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52642 else if (ret == -ENODATA)
52643- fscache_stat(&fscache_n_retrievals_nodata);
52644+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52645 else if (ret < 0)
52646- fscache_stat(&fscache_n_retrievals_nobufs);
52647+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52648 else
52649- fscache_stat(&fscache_n_retrievals_ok);
52650+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52651
52652 fscache_put_retrieval(op);
52653 _leave(" = %d", ret);
52654@@ -467,7 +467,7 @@ nobufs_unlock:
52655 spin_unlock(&cookie->lock);
52656 kfree(op);
52657 nobufs:
52658- fscache_stat(&fscache_n_retrievals_nobufs);
52659+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52660 _leave(" = -ENOBUFS");
52661 return -ENOBUFS;
52662 }
52663@@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52664
52665 _enter("%p,,%d,,,", cookie, *nr_pages);
52666
52667- fscache_stat(&fscache_n_retrievals);
52668+ fscache_stat_unchecked(&fscache_n_retrievals);
52669
52670 if (hlist_empty(&cookie->backing_objects))
52671 goto nobufs;
52672@@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52673 goto nobufs_unlock_dec;
52674 spin_unlock(&cookie->lock);
52675
52676- fscache_stat(&fscache_n_retrieval_ops);
52677+ fscache_stat_unchecked(&fscache_n_retrieval_ops);
52678
52679 /* pin the netfs read context in case we need to do the actual netfs
52680 * read because we've encountered a cache read failure */
52681@@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
52682
52683 error:
52684 if (ret == -ENOMEM)
52685- fscache_stat(&fscache_n_retrievals_nomem);
52686+ fscache_stat_unchecked(&fscache_n_retrievals_nomem);
52687 else if (ret == -ERESTARTSYS)
52688- fscache_stat(&fscache_n_retrievals_intr);
52689+ fscache_stat_unchecked(&fscache_n_retrievals_intr);
52690 else if (ret == -ENODATA)
52691- fscache_stat(&fscache_n_retrievals_nodata);
52692+ fscache_stat_unchecked(&fscache_n_retrievals_nodata);
52693 else if (ret < 0)
52694- fscache_stat(&fscache_n_retrievals_nobufs);
52695+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52696 else
52697- fscache_stat(&fscache_n_retrievals_ok);
52698+ fscache_stat_unchecked(&fscache_n_retrievals_ok);
52699
52700 fscache_put_retrieval(op);
52701 _leave(" = %d", ret);
52702@@ -591,7 +591,7 @@ nobufs_unlock:
52703 spin_unlock(&cookie->lock);
52704 kfree(op);
52705 nobufs:
52706- fscache_stat(&fscache_n_retrievals_nobufs);
52707+ fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
52708 _leave(" = -ENOBUFS");
52709 return -ENOBUFS;
52710 }
52711@@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52712
52713 _enter("%p,%p,,,", cookie, page);
52714
52715- fscache_stat(&fscache_n_allocs);
52716+ fscache_stat_unchecked(&fscache_n_allocs);
52717
52718 if (hlist_empty(&cookie->backing_objects))
52719 goto nobufs;
52720@@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52721 goto nobufs_unlock;
52722 spin_unlock(&cookie->lock);
52723
52724- fscache_stat(&fscache_n_alloc_ops);
52725+ fscache_stat_unchecked(&fscache_n_alloc_ops);
52726
52727 ret = fscache_wait_for_retrieval_activation(
52728 object, op,
52729@@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
52730
52731 error:
52732 if (ret == -ERESTARTSYS)
52733- fscache_stat(&fscache_n_allocs_intr);
52734+ fscache_stat_unchecked(&fscache_n_allocs_intr);
52735 else if (ret < 0)
52736- fscache_stat(&fscache_n_allocs_nobufs);
52737+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52738 else
52739- fscache_stat(&fscache_n_allocs_ok);
52740+ fscache_stat_unchecked(&fscache_n_allocs_ok);
52741
52742 fscache_put_retrieval(op);
52743 _leave(" = %d", ret);
52744@@ -677,7 +677,7 @@ nobufs_unlock:
52745 spin_unlock(&cookie->lock);
52746 kfree(op);
52747 nobufs:
52748- fscache_stat(&fscache_n_allocs_nobufs);
52749+ fscache_stat_unchecked(&fscache_n_allocs_nobufs);
52750 _leave(" = -ENOBUFS");
52751 return -ENOBUFS;
52752 }
52753@@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52754
52755 spin_lock(&cookie->stores_lock);
52756
52757- fscache_stat(&fscache_n_store_calls);
52758+ fscache_stat_unchecked(&fscache_n_store_calls);
52759
52760 /* find a page to store */
52761 page = NULL;
52762@@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52763 page = results[0];
52764 _debug("gang %d [%lx]", n, page->index);
52765 if (page->index > op->store_limit) {
52766- fscache_stat(&fscache_n_store_pages_over_limit);
52767+ fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
52768 goto superseded;
52769 }
52770
52771@@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
52772 spin_unlock(&cookie->stores_lock);
52773 spin_unlock(&object->lock);
52774
52775- fscache_stat(&fscache_n_store_pages);
52776+ fscache_stat_unchecked(&fscache_n_store_pages);
52777 fscache_stat(&fscache_n_cop_write_page);
52778 ret = object->cache->ops->write_page(op, page);
52779 fscache_stat_d(&fscache_n_cop_write_page);
52780@@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52781 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52782 ASSERT(PageFsCache(page));
52783
52784- fscache_stat(&fscache_n_stores);
52785+ fscache_stat_unchecked(&fscache_n_stores);
52786
52787 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
52788 _leave(" = -ENOBUFS [invalidating]");
52789@@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52790 spin_unlock(&cookie->stores_lock);
52791 spin_unlock(&object->lock);
52792
52793- op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
52794+ op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
52795 op->store_limit = object->store_limit;
52796
52797 if (fscache_submit_op(object, &op->op) < 0)
52798@@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52799
52800 spin_unlock(&cookie->lock);
52801 radix_tree_preload_end();
52802- fscache_stat(&fscache_n_store_ops);
52803- fscache_stat(&fscache_n_stores_ok);
52804+ fscache_stat_unchecked(&fscache_n_store_ops);
52805+ fscache_stat_unchecked(&fscache_n_stores_ok);
52806
52807 /* the work queue now carries its own ref on the object */
52808 fscache_put_operation(&op->op);
52809@@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
52810 return 0;
52811
52812 already_queued:
52813- fscache_stat(&fscache_n_stores_again);
52814+ fscache_stat_unchecked(&fscache_n_stores_again);
52815 already_pending:
52816 spin_unlock(&cookie->stores_lock);
52817 spin_unlock(&object->lock);
52818 spin_unlock(&cookie->lock);
52819 radix_tree_preload_end();
52820 kfree(op);
52821- fscache_stat(&fscache_n_stores_ok);
52822+ fscache_stat_unchecked(&fscache_n_stores_ok);
52823 _leave(" = 0");
52824 return 0;
52825
52826@@ -959,14 +959,14 @@ nobufs:
52827 spin_unlock(&cookie->lock);
52828 radix_tree_preload_end();
52829 kfree(op);
52830- fscache_stat(&fscache_n_stores_nobufs);
52831+ fscache_stat_unchecked(&fscache_n_stores_nobufs);
52832 _leave(" = -ENOBUFS");
52833 return -ENOBUFS;
52834
52835 nomem_free:
52836 kfree(op);
52837 nomem:
52838- fscache_stat(&fscache_n_stores_oom);
52839+ fscache_stat_unchecked(&fscache_n_stores_oom);
52840 _leave(" = -ENOMEM");
52841 return -ENOMEM;
52842 }
52843@@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
52844 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
52845 ASSERTCMP(page, !=, NULL);
52846
52847- fscache_stat(&fscache_n_uncaches);
52848+ fscache_stat_unchecked(&fscache_n_uncaches);
52849
52850 /* cache withdrawal may beat us to it */
52851 if (!PageFsCache(page))
52852@@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
52853 struct fscache_cookie *cookie = op->op.object->cookie;
52854
52855 #ifdef CONFIG_FSCACHE_STATS
52856- atomic_inc(&fscache_n_marks);
52857+ atomic_inc_unchecked(&fscache_n_marks);
52858 #endif
52859
52860 _debug("- mark %p{%lx}", page, page->index);
52861diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
52862index 40d13c7..ddf52b9 100644
52863--- a/fs/fscache/stats.c
52864+++ b/fs/fscache/stats.c
52865@@ -18,99 +18,99 @@
52866 /*
52867 * operation counters
52868 */
52869-atomic_t fscache_n_op_pend;
52870-atomic_t fscache_n_op_run;
52871-atomic_t fscache_n_op_enqueue;
52872-atomic_t fscache_n_op_requeue;
52873-atomic_t fscache_n_op_deferred_release;
52874-atomic_t fscache_n_op_release;
52875-atomic_t fscache_n_op_gc;
52876-atomic_t fscache_n_op_cancelled;
52877-atomic_t fscache_n_op_rejected;
52878+atomic_unchecked_t fscache_n_op_pend;
52879+atomic_unchecked_t fscache_n_op_run;
52880+atomic_unchecked_t fscache_n_op_enqueue;
52881+atomic_unchecked_t fscache_n_op_requeue;
52882+atomic_unchecked_t fscache_n_op_deferred_release;
52883+atomic_unchecked_t fscache_n_op_release;
52884+atomic_unchecked_t fscache_n_op_gc;
52885+atomic_unchecked_t fscache_n_op_cancelled;
52886+atomic_unchecked_t fscache_n_op_rejected;
52887
52888-atomic_t fscache_n_attr_changed;
52889-atomic_t fscache_n_attr_changed_ok;
52890-atomic_t fscache_n_attr_changed_nobufs;
52891-atomic_t fscache_n_attr_changed_nomem;
52892-atomic_t fscache_n_attr_changed_calls;
52893+atomic_unchecked_t fscache_n_attr_changed;
52894+atomic_unchecked_t fscache_n_attr_changed_ok;
52895+atomic_unchecked_t fscache_n_attr_changed_nobufs;
52896+atomic_unchecked_t fscache_n_attr_changed_nomem;
52897+atomic_unchecked_t fscache_n_attr_changed_calls;
52898
52899-atomic_t fscache_n_allocs;
52900-atomic_t fscache_n_allocs_ok;
52901-atomic_t fscache_n_allocs_wait;
52902-atomic_t fscache_n_allocs_nobufs;
52903-atomic_t fscache_n_allocs_intr;
52904-atomic_t fscache_n_allocs_object_dead;
52905-atomic_t fscache_n_alloc_ops;
52906-atomic_t fscache_n_alloc_op_waits;
52907+atomic_unchecked_t fscache_n_allocs;
52908+atomic_unchecked_t fscache_n_allocs_ok;
52909+atomic_unchecked_t fscache_n_allocs_wait;
52910+atomic_unchecked_t fscache_n_allocs_nobufs;
52911+atomic_unchecked_t fscache_n_allocs_intr;
52912+atomic_unchecked_t fscache_n_allocs_object_dead;
52913+atomic_unchecked_t fscache_n_alloc_ops;
52914+atomic_unchecked_t fscache_n_alloc_op_waits;
52915
52916-atomic_t fscache_n_retrievals;
52917-atomic_t fscache_n_retrievals_ok;
52918-atomic_t fscache_n_retrievals_wait;
52919-atomic_t fscache_n_retrievals_nodata;
52920-atomic_t fscache_n_retrievals_nobufs;
52921-atomic_t fscache_n_retrievals_intr;
52922-atomic_t fscache_n_retrievals_nomem;
52923-atomic_t fscache_n_retrievals_object_dead;
52924-atomic_t fscache_n_retrieval_ops;
52925-atomic_t fscache_n_retrieval_op_waits;
52926+atomic_unchecked_t fscache_n_retrievals;
52927+atomic_unchecked_t fscache_n_retrievals_ok;
52928+atomic_unchecked_t fscache_n_retrievals_wait;
52929+atomic_unchecked_t fscache_n_retrievals_nodata;
52930+atomic_unchecked_t fscache_n_retrievals_nobufs;
52931+atomic_unchecked_t fscache_n_retrievals_intr;
52932+atomic_unchecked_t fscache_n_retrievals_nomem;
52933+atomic_unchecked_t fscache_n_retrievals_object_dead;
52934+atomic_unchecked_t fscache_n_retrieval_ops;
52935+atomic_unchecked_t fscache_n_retrieval_op_waits;
52936
52937-atomic_t fscache_n_stores;
52938-atomic_t fscache_n_stores_ok;
52939-atomic_t fscache_n_stores_again;
52940-atomic_t fscache_n_stores_nobufs;
52941-atomic_t fscache_n_stores_oom;
52942-atomic_t fscache_n_store_ops;
52943-atomic_t fscache_n_store_calls;
52944-atomic_t fscache_n_store_pages;
52945-atomic_t fscache_n_store_radix_deletes;
52946-atomic_t fscache_n_store_pages_over_limit;
52947+atomic_unchecked_t fscache_n_stores;
52948+atomic_unchecked_t fscache_n_stores_ok;
52949+atomic_unchecked_t fscache_n_stores_again;
52950+atomic_unchecked_t fscache_n_stores_nobufs;
52951+atomic_unchecked_t fscache_n_stores_oom;
52952+atomic_unchecked_t fscache_n_store_ops;
52953+atomic_unchecked_t fscache_n_store_calls;
52954+atomic_unchecked_t fscache_n_store_pages;
52955+atomic_unchecked_t fscache_n_store_radix_deletes;
52956+atomic_unchecked_t fscache_n_store_pages_over_limit;
52957
52958-atomic_t fscache_n_store_vmscan_not_storing;
52959-atomic_t fscache_n_store_vmscan_gone;
52960-atomic_t fscache_n_store_vmscan_busy;
52961-atomic_t fscache_n_store_vmscan_cancelled;
52962-atomic_t fscache_n_store_vmscan_wait;
52963+atomic_unchecked_t fscache_n_store_vmscan_not_storing;
52964+atomic_unchecked_t fscache_n_store_vmscan_gone;
52965+atomic_unchecked_t fscache_n_store_vmscan_busy;
52966+atomic_unchecked_t fscache_n_store_vmscan_cancelled;
52967+atomic_unchecked_t fscache_n_store_vmscan_wait;
52968
52969-atomic_t fscache_n_marks;
52970-atomic_t fscache_n_uncaches;
52971+atomic_unchecked_t fscache_n_marks;
52972+atomic_unchecked_t fscache_n_uncaches;
52973
52974-atomic_t fscache_n_acquires;
52975-atomic_t fscache_n_acquires_null;
52976-atomic_t fscache_n_acquires_no_cache;
52977-atomic_t fscache_n_acquires_ok;
52978-atomic_t fscache_n_acquires_nobufs;
52979-atomic_t fscache_n_acquires_oom;
52980+atomic_unchecked_t fscache_n_acquires;
52981+atomic_unchecked_t fscache_n_acquires_null;
52982+atomic_unchecked_t fscache_n_acquires_no_cache;
52983+atomic_unchecked_t fscache_n_acquires_ok;
52984+atomic_unchecked_t fscache_n_acquires_nobufs;
52985+atomic_unchecked_t fscache_n_acquires_oom;
52986
52987-atomic_t fscache_n_invalidates;
52988-atomic_t fscache_n_invalidates_run;
52989+atomic_unchecked_t fscache_n_invalidates;
52990+atomic_unchecked_t fscache_n_invalidates_run;
52991
52992-atomic_t fscache_n_updates;
52993-atomic_t fscache_n_updates_null;
52994-atomic_t fscache_n_updates_run;
52995+atomic_unchecked_t fscache_n_updates;
52996+atomic_unchecked_t fscache_n_updates_null;
52997+atomic_unchecked_t fscache_n_updates_run;
52998
52999-atomic_t fscache_n_relinquishes;
53000-atomic_t fscache_n_relinquishes_null;
53001-atomic_t fscache_n_relinquishes_waitcrt;
53002-atomic_t fscache_n_relinquishes_retire;
53003+atomic_unchecked_t fscache_n_relinquishes;
53004+atomic_unchecked_t fscache_n_relinquishes_null;
53005+atomic_unchecked_t fscache_n_relinquishes_waitcrt;
53006+atomic_unchecked_t fscache_n_relinquishes_retire;
53007
53008-atomic_t fscache_n_cookie_index;
53009-atomic_t fscache_n_cookie_data;
53010-atomic_t fscache_n_cookie_special;
53011+atomic_unchecked_t fscache_n_cookie_index;
53012+atomic_unchecked_t fscache_n_cookie_data;
53013+atomic_unchecked_t fscache_n_cookie_special;
53014
53015-atomic_t fscache_n_object_alloc;
53016-atomic_t fscache_n_object_no_alloc;
53017-atomic_t fscache_n_object_lookups;
53018-atomic_t fscache_n_object_lookups_negative;
53019-atomic_t fscache_n_object_lookups_positive;
53020-atomic_t fscache_n_object_lookups_timed_out;
53021-atomic_t fscache_n_object_created;
53022-atomic_t fscache_n_object_avail;
53023-atomic_t fscache_n_object_dead;
53024+atomic_unchecked_t fscache_n_object_alloc;
53025+atomic_unchecked_t fscache_n_object_no_alloc;
53026+atomic_unchecked_t fscache_n_object_lookups;
53027+atomic_unchecked_t fscache_n_object_lookups_negative;
53028+atomic_unchecked_t fscache_n_object_lookups_positive;
53029+atomic_unchecked_t fscache_n_object_lookups_timed_out;
53030+atomic_unchecked_t fscache_n_object_created;
53031+atomic_unchecked_t fscache_n_object_avail;
53032+atomic_unchecked_t fscache_n_object_dead;
53033
53034-atomic_t fscache_n_checkaux_none;
53035-atomic_t fscache_n_checkaux_okay;
53036-atomic_t fscache_n_checkaux_update;
53037-atomic_t fscache_n_checkaux_obsolete;
53038+atomic_unchecked_t fscache_n_checkaux_none;
53039+atomic_unchecked_t fscache_n_checkaux_okay;
53040+atomic_unchecked_t fscache_n_checkaux_update;
53041+atomic_unchecked_t fscache_n_checkaux_obsolete;
53042
53043 atomic_t fscache_n_cop_alloc_object;
53044 atomic_t fscache_n_cop_lookup_object;
53045@@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
53046 seq_puts(m, "FS-Cache statistics\n");
53047
53048 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
53049- atomic_read(&fscache_n_cookie_index),
53050- atomic_read(&fscache_n_cookie_data),
53051- atomic_read(&fscache_n_cookie_special));
53052+ atomic_read_unchecked(&fscache_n_cookie_index),
53053+ atomic_read_unchecked(&fscache_n_cookie_data),
53054+ atomic_read_unchecked(&fscache_n_cookie_special));
53055
53056 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
53057- atomic_read(&fscache_n_object_alloc),
53058- atomic_read(&fscache_n_object_no_alloc),
53059- atomic_read(&fscache_n_object_avail),
53060- atomic_read(&fscache_n_object_dead));
53061+ atomic_read_unchecked(&fscache_n_object_alloc),
53062+ atomic_read_unchecked(&fscache_n_object_no_alloc),
53063+ atomic_read_unchecked(&fscache_n_object_avail),
53064+ atomic_read_unchecked(&fscache_n_object_dead));
53065 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
53066- atomic_read(&fscache_n_checkaux_none),
53067- atomic_read(&fscache_n_checkaux_okay),
53068- atomic_read(&fscache_n_checkaux_update),
53069- atomic_read(&fscache_n_checkaux_obsolete));
53070+ atomic_read_unchecked(&fscache_n_checkaux_none),
53071+ atomic_read_unchecked(&fscache_n_checkaux_okay),
53072+ atomic_read_unchecked(&fscache_n_checkaux_update),
53073+ atomic_read_unchecked(&fscache_n_checkaux_obsolete));
53074
53075 seq_printf(m, "Pages : mrk=%u unc=%u\n",
53076- atomic_read(&fscache_n_marks),
53077- atomic_read(&fscache_n_uncaches));
53078+ atomic_read_unchecked(&fscache_n_marks),
53079+ atomic_read_unchecked(&fscache_n_uncaches));
53080
53081 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
53082 " oom=%u\n",
53083- atomic_read(&fscache_n_acquires),
53084- atomic_read(&fscache_n_acquires_null),
53085- atomic_read(&fscache_n_acquires_no_cache),
53086- atomic_read(&fscache_n_acquires_ok),
53087- atomic_read(&fscache_n_acquires_nobufs),
53088- atomic_read(&fscache_n_acquires_oom));
53089+ atomic_read_unchecked(&fscache_n_acquires),
53090+ atomic_read_unchecked(&fscache_n_acquires_null),
53091+ atomic_read_unchecked(&fscache_n_acquires_no_cache),
53092+ atomic_read_unchecked(&fscache_n_acquires_ok),
53093+ atomic_read_unchecked(&fscache_n_acquires_nobufs),
53094+ atomic_read_unchecked(&fscache_n_acquires_oom));
53095
53096 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
53097- atomic_read(&fscache_n_object_lookups),
53098- atomic_read(&fscache_n_object_lookups_negative),
53099- atomic_read(&fscache_n_object_lookups_positive),
53100- atomic_read(&fscache_n_object_created),
53101- atomic_read(&fscache_n_object_lookups_timed_out));
53102+ atomic_read_unchecked(&fscache_n_object_lookups),
53103+ atomic_read_unchecked(&fscache_n_object_lookups_negative),
53104+ atomic_read_unchecked(&fscache_n_object_lookups_positive),
53105+ atomic_read_unchecked(&fscache_n_object_created),
53106+ atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
53107
53108 seq_printf(m, "Invals : n=%u run=%u\n",
53109- atomic_read(&fscache_n_invalidates),
53110- atomic_read(&fscache_n_invalidates_run));
53111+ atomic_read_unchecked(&fscache_n_invalidates),
53112+ atomic_read_unchecked(&fscache_n_invalidates_run));
53113
53114 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
53115- atomic_read(&fscache_n_updates),
53116- atomic_read(&fscache_n_updates_null),
53117- atomic_read(&fscache_n_updates_run));
53118+ atomic_read_unchecked(&fscache_n_updates),
53119+ atomic_read_unchecked(&fscache_n_updates_null),
53120+ atomic_read_unchecked(&fscache_n_updates_run));
53121
53122 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
53123- atomic_read(&fscache_n_relinquishes),
53124- atomic_read(&fscache_n_relinquishes_null),
53125- atomic_read(&fscache_n_relinquishes_waitcrt),
53126- atomic_read(&fscache_n_relinquishes_retire));
53127+ atomic_read_unchecked(&fscache_n_relinquishes),
53128+ atomic_read_unchecked(&fscache_n_relinquishes_null),
53129+ atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
53130+ atomic_read_unchecked(&fscache_n_relinquishes_retire));
53131
53132 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
53133- atomic_read(&fscache_n_attr_changed),
53134- atomic_read(&fscache_n_attr_changed_ok),
53135- atomic_read(&fscache_n_attr_changed_nobufs),
53136- atomic_read(&fscache_n_attr_changed_nomem),
53137- atomic_read(&fscache_n_attr_changed_calls));
53138+ atomic_read_unchecked(&fscache_n_attr_changed),
53139+ atomic_read_unchecked(&fscache_n_attr_changed_ok),
53140+ atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
53141+ atomic_read_unchecked(&fscache_n_attr_changed_nomem),
53142+ atomic_read_unchecked(&fscache_n_attr_changed_calls));
53143
53144 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
53145- atomic_read(&fscache_n_allocs),
53146- atomic_read(&fscache_n_allocs_ok),
53147- atomic_read(&fscache_n_allocs_wait),
53148- atomic_read(&fscache_n_allocs_nobufs),
53149- atomic_read(&fscache_n_allocs_intr));
53150+ atomic_read_unchecked(&fscache_n_allocs),
53151+ atomic_read_unchecked(&fscache_n_allocs_ok),
53152+ atomic_read_unchecked(&fscache_n_allocs_wait),
53153+ atomic_read_unchecked(&fscache_n_allocs_nobufs),
53154+ atomic_read_unchecked(&fscache_n_allocs_intr));
53155 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
53156- atomic_read(&fscache_n_alloc_ops),
53157- atomic_read(&fscache_n_alloc_op_waits),
53158- atomic_read(&fscache_n_allocs_object_dead));
53159+ atomic_read_unchecked(&fscache_n_alloc_ops),
53160+ atomic_read_unchecked(&fscache_n_alloc_op_waits),
53161+ atomic_read_unchecked(&fscache_n_allocs_object_dead));
53162
53163 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
53164 " int=%u oom=%u\n",
53165- atomic_read(&fscache_n_retrievals),
53166- atomic_read(&fscache_n_retrievals_ok),
53167- atomic_read(&fscache_n_retrievals_wait),
53168- atomic_read(&fscache_n_retrievals_nodata),
53169- atomic_read(&fscache_n_retrievals_nobufs),
53170- atomic_read(&fscache_n_retrievals_intr),
53171- atomic_read(&fscache_n_retrievals_nomem));
53172+ atomic_read_unchecked(&fscache_n_retrievals),
53173+ atomic_read_unchecked(&fscache_n_retrievals_ok),
53174+ atomic_read_unchecked(&fscache_n_retrievals_wait),
53175+ atomic_read_unchecked(&fscache_n_retrievals_nodata),
53176+ atomic_read_unchecked(&fscache_n_retrievals_nobufs),
53177+ atomic_read_unchecked(&fscache_n_retrievals_intr),
53178+ atomic_read_unchecked(&fscache_n_retrievals_nomem));
53179 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
53180- atomic_read(&fscache_n_retrieval_ops),
53181- atomic_read(&fscache_n_retrieval_op_waits),
53182- atomic_read(&fscache_n_retrievals_object_dead));
53183+ atomic_read_unchecked(&fscache_n_retrieval_ops),
53184+ atomic_read_unchecked(&fscache_n_retrieval_op_waits),
53185+ atomic_read_unchecked(&fscache_n_retrievals_object_dead));
53186
53187 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
53188- atomic_read(&fscache_n_stores),
53189- atomic_read(&fscache_n_stores_ok),
53190- atomic_read(&fscache_n_stores_again),
53191- atomic_read(&fscache_n_stores_nobufs),
53192- atomic_read(&fscache_n_stores_oom));
53193+ atomic_read_unchecked(&fscache_n_stores),
53194+ atomic_read_unchecked(&fscache_n_stores_ok),
53195+ atomic_read_unchecked(&fscache_n_stores_again),
53196+ atomic_read_unchecked(&fscache_n_stores_nobufs),
53197+ atomic_read_unchecked(&fscache_n_stores_oom));
53198 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
53199- atomic_read(&fscache_n_store_ops),
53200- atomic_read(&fscache_n_store_calls),
53201- atomic_read(&fscache_n_store_pages),
53202- atomic_read(&fscache_n_store_radix_deletes),
53203- atomic_read(&fscache_n_store_pages_over_limit));
53204+ atomic_read_unchecked(&fscache_n_store_ops),
53205+ atomic_read_unchecked(&fscache_n_store_calls),
53206+ atomic_read_unchecked(&fscache_n_store_pages),
53207+ atomic_read_unchecked(&fscache_n_store_radix_deletes),
53208+ atomic_read_unchecked(&fscache_n_store_pages_over_limit));
53209
53210 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
53211- atomic_read(&fscache_n_store_vmscan_not_storing),
53212- atomic_read(&fscache_n_store_vmscan_gone),
53213- atomic_read(&fscache_n_store_vmscan_busy),
53214- atomic_read(&fscache_n_store_vmscan_cancelled),
53215- atomic_read(&fscache_n_store_vmscan_wait));
53216+ atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
53217+ atomic_read_unchecked(&fscache_n_store_vmscan_gone),
53218+ atomic_read_unchecked(&fscache_n_store_vmscan_busy),
53219+ atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
53220+ atomic_read_unchecked(&fscache_n_store_vmscan_wait));
53221
53222 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
53223- atomic_read(&fscache_n_op_pend),
53224- atomic_read(&fscache_n_op_run),
53225- atomic_read(&fscache_n_op_enqueue),
53226- atomic_read(&fscache_n_op_cancelled),
53227- atomic_read(&fscache_n_op_rejected));
53228+ atomic_read_unchecked(&fscache_n_op_pend),
53229+ atomic_read_unchecked(&fscache_n_op_run),
53230+ atomic_read_unchecked(&fscache_n_op_enqueue),
53231+ atomic_read_unchecked(&fscache_n_op_cancelled),
53232+ atomic_read_unchecked(&fscache_n_op_rejected));
53233 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
53234- atomic_read(&fscache_n_op_deferred_release),
53235- atomic_read(&fscache_n_op_release),
53236- atomic_read(&fscache_n_op_gc));
53237+ atomic_read_unchecked(&fscache_n_op_deferred_release),
53238+ atomic_read_unchecked(&fscache_n_op_release),
53239+ atomic_read_unchecked(&fscache_n_op_gc));
53240
53241 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
53242 atomic_read(&fscache_n_cop_alloc_object),
53243diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
53244index 6f96a8d..6019bb9 100644
53245--- a/fs/fuse/cuse.c
53246+++ b/fs/fuse/cuse.c
53247@@ -597,10 +597,12 @@ static int __init cuse_init(void)
53248 INIT_LIST_HEAD(&cuse_conntbl[i]);
53249
53250 /* inherit and extend fuse_dev_operations */
53251- cuse_channel_fops = fuse_dev_operations;
53252- cuse_channel_fops.owner = THIS_MODULE;
53253- cuse_channel_fops.open = cuse_channel_open;
53254- cuse_channel_fops.release = cuse_channel_release;
53255+ pax_open_kernel();
53256+ memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
53257+ *(void **)&cuse_channel_fops.owner = THIS_MODULE;
53258+ *(void **)&cuse_channel_fops.open = cuse_channel_open;
53259+ *(void **)&cuse_channel_fops.release = cuse_channel_release;
53260+ pax_close_kernel();
53261
53262 cuse_class = class_create(THIS_MODULE, "cuse");
53263 if (IS_ERR(cuse_class))
53264diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
53265index 11dfa0c..6f64416 100644
53266--- a/fs/fuse/dev.c
53267+++ b/fs/fuse/dev.c
53268@@ -1294,7 +1294,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
53269 ret = 0;
53270 pipe_lock(pipe);
53271
53272- if (!pipe->readers) {
53273+ if (!atomic_read(&pipe->readers)) {
53274 send_sig(SIGPIPE, current, 0);
53275 if (!ret)
53276 ret = -EPIPE;
53277diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
53278index 185c479..51b9986 100644
53279--- a/fs/fuse/dir.c
53280+++ b/fs/fuse/dir.c
53281@@ -1415,7 +1415,7 @@ static char *read_link(struct dentry *dentry)
53282 return link;
53283 }
53284
53285-static void free_link(char *link)
53286+static void free_link(const char *link)
53287 {
53288 if (!IS_ERR(link))
53289 free_page((unsigned long) link);
53290diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
53291index cc00bd1..3edb692 100644
53292--- a/fs/gfs2/inode.c
53293+++ b/fs/gfs2/inode.c
53294@@ -1500,7 +1500,7 @@ out:
53295
53296 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
53297 {
53298- char *s = nd_get_link(nd);
53299+ const char *s = nd_get_link(nd);
53300 if (!IS_ERR(s))
53301 kfree(s);
53302 }
53303diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
53304index a3f868a..bb308ae 100644
53305--- a/fs/hugetlbfs/inode.c
53306+++ b/fs/hugetlbfs/inode.c
53307@@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53308 struct mm_struct *mm = current->mm;
53309 struct vm_area_struct *vma;
53310 struct hstate *h = hstate_file(file);
53311+ unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
53312 struct vm_unmapped_area_info info;
53313
53314 if (len & ~huge_page_mask(h))
53315@@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
53316 return addr;
53317 }
53318
53319+#ifdef CONFIG_PAX_RANDMMAP
53320+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
53321+#endif
53322+
53323 if (addr) {
53324 addr = ALIGN(addr, huge_page_size(h));
53325 vma = find_vma(mm, addr);
53326- if (TASK_SIZE - len >= addr &&
53327- (!vma || addr + len <= vma->vm_start))
53328+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
53329 return addr;
53330 }
53331
53332 info.flags = 0;
53333 info.length = len;
53334 info.low_limit = TASK_UNMAPPED_BASE;
53335+
53336+#ifdef CONFIG_PAX_RANDMMAP
53337+ if (mm->pax_flags & MF_PAX_RANDMMAP)
53338+ info.low_limit += mm->delta_mmap;
53339+#endif
53340+
53341 info.high_limit = TASK_SIZE;
53342 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
53343 info.align_offset = 0;
53344@@ -898,7 +908,7 @@ static struct file_system_type hugetlbfs_fs_type = {
53345 };
53346 MODULE_ALIAS_FS("hugetlbfs");
53347
53348-static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53349+struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
53350
53351 static int can_do_hugetlb_shm(void)
53352 {
53353diff --git a/fs/inode.c b/fs/inode.c
53354index a898b3d..9b5a214 100644
53355--- a/fs/inode.c
53356+++ b/fs/inode.c
53357@@ -878,8 +878,8 @@ unsigned int get_next_ino(void)
53358
53359 #ifdef CONFIG_SMP
53360 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
53361- static atomic_t shared_last_ino;
53362- int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
53363+ static atomic_unchecked_t shared_last_ino;
53364+ int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
53365
53366 res = next - LAST_INO_BATCH;
53367 }
53368diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
53369index 4a6cf28..d3a29d3 100644
53370--- a/fs/jffs2/erase.c
53371+++ b/fs/jffs2/erase.c
53372@@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
53373 struct jffs2_unknown_node marker = {
53374 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
53375 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53376- .totlen = cpu_to_je32(c->cleanmarker_size)
53377+ .totlen = cpu_to_je32(c->cleanmarker_size),
53378+ .hdr_crc = cpu_to_je32(0)
53379 };
53380
53381 jffs2_prealloc_raw_node_refs(c, jeb, 1);
53382diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
53383index a6597d6..41b30ec 100644
53384--- a/fs/jffs2/wbuf.c
53385+++ b/fs/jffs2/wbuf.c
53386@@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
53387 {
53388 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
53389 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
53390- .totlen = constant_cpu_to_je32(8)
53391+ .totlen = constant_cpu_to_je32(8),
53392+ .hdr_crc = constant_cpu_to_je32(0)
53393 };
53394
53395 /*
53396diff --git a/fs/jfs/super.c b/fs/jfs/super.c
53397index 2003e83..40db287 100644
53398--- a/fs/jfs/super.c
53399+++ b/fs/jfs/super.c
53400@@ -856,7 +856,7 @@ static int __init init_jfs_fs(void)
53401
53402 jfs_inode_cachep =
53403 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
53404- SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
53405+ SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
53406 init_once);
53407 if (jfs_inode_cachep == NULL)
53408 return -ENOMEM;
53409diff --git a/fs/libfs.c b/fs/libfs.c
53410index 916da8c..1588998 100644
53411--- a/fs/libfs.c
53412+++ b/fs/libfs.c
53413@@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53414
53415 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
53416 struct dentry *next;
53417+ char d_name[sizeof(next->d_iname)];
53418+ const unsigned char *name;
53419+
53420 next = list_entry(p, struct dentry, d_u.d_child);
53421 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
53422 if (!simple_positive(next)) {
53423@@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
53424
53425 spin_unlock(&next->d_lock);
53426 spin_unlock(&dentry->d_lock);
53427- if (filldir(dirent, next->d_name.name,
53428+ name = next->d_name.name;
53429+ if (name == next->d_iname) {
53430+ memcpy(d_name, name, next->d_name.len);
53431+ name = d_name;
53432+ }
53433+ if (filldir(dirent, name,
53434 next->d_name.len, filp->f_pos,
53435 next->d_inode->i_ino,
53436 dt_type(next->d_inode)) < 0)
53437diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
53438index 9760ecb..9b838ef 100644
53439--- a/fs/lockd/clntproc.c
53440+++ b/fs/lockd/clntproc.c
53441@@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
53442 /*
53443 * Cookie counter for NLM requests
53444 */
53445-static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
53446+static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
53447
53448 void nlmclnt_next_cookie(struct nlm_cookie *c)
53449 {
53450- u32 cookie = atomic_inc_return(&nlm_cookie);
53451+ u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
53452
53453 memcpy(c->data, &cookie, 4);
53454 c->len=4;
53455diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
53456index a2aa97d..10d6c41 100644
53457--- a/fs/lockd/svc.c
53458+++ b/fs/lockd/svc.c
53459@@ -305,7 +305,7 @@ static int lockd_start_svc(struct svc_serv *serv)
53460 svc_sock_update_bufs(serv);
53461 serv->sv_maxconn = nlm_max_connections;
53462
53463- nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, serv->sv_name);
53464+ nlmsvc_task = kthread_run(lockd, nlmsvc_rqst, "%s", serv->sv_name);
53465 if (IS_ERR(nlmsvc_task)) {
53466 error = PTR_ERR(nlmsvc_task);
53467 printk(KERN_WARNING
53468diff --git a/fs/locks.c b/fs/locks.c
53469index cb424a4..850e4dd 100644
53470--- a/fs/locks.c
53471+++ b/fs/locks.c
53472@@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
53473 return;
53474
53475 if (filp->f_op && filp->f_op->flock) {
53476- struct file_lock fl = {
53477+ struct file_lock flock = {
53478 .fl_pid = current->tgid,
53479 .fl_file = filp,
53480 .fl_flags = FL_FLOCK,
53481 .fl_type = F_UNLCK,
53482 .fl_end = OFFSET_MAX,
53483 };
53484- filp->f_op->flock(filp, F_SETLKW, &fl);
53485- if (fl.fl_ops && fl.fl_ops->fl_release_private)
53486- fl.fl_ops->fl_release_private(&fl);
53487+ filp->f_op->flock(filp, F_SETLKW, &flock);
53488+ if (flock.fl_ops && flock.fl_ops->fl_release_private)
53489+ flock.fl_ops->fl_release_private(&flock);
53490 }
53491
53492 lock_flocks();
53493diff --git a/fs/namei.c b/fs/namei.c
53494index 85e40d1..b66744e 100644
53495--- a/fs/namei.c
53496+++ b/fs/namei.c
53497@@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
53498 if (ret != -EACCES)
53499 return ret;
53500
53501+#ifdef CONFIG_GRKERNSEC
53502+ /* we'll block if we have to log due to a denied capability use */
53503+ if (mask & MAY_NOT_BLOCK)
53504+ return -ECHILD;
53505+#endif
53506+
53507 if (S_ISDIR(inode->i_mode)) {
53508 /* DACs are overridable for directories */
53509- if (inode_capable(inode, CAP_DAC_OVERRIDE))
53510- return 0;
53511 if (!(mask & MAY_WRITE))
53512- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53513+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53514+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53515 return 0;
53516+ if (inode_capable(inode, CAP_DAC_OVERRIDE))
53517+ return 0;
53518 return -EACCES;
53519 }
53520 /*
53521+ * Searching includes executable on directories, else just read.
53522+ */
53523+ mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53524+ if (mask == MAY_READ)
53525+ if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
53526+ inode_capable(inode, CAP_DAC_READ_SEARCH))
53527+ return 0;
53528+
53529+ /*
53530 * Read/write DACs are always overridable.
53531 * Executable DACs are overridable when there is
53532 * at least one exec bit set.
53533@@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
53534 if (inode_capable(inode, CAP_DAC_OVERRIDE))
53535 return 0;
53536
53537- /*
53538- * Searching includes executable on directories, else just read.
53539- */
53540- mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
53541- if (mask == MAY_READ)
53542- if (inode_capable(inode, CAP_DAC_READ_SEARCH))
53543- return 0;
53544-
53545 return -EACCES;
53546 }
53547
53548@@ -820,7 +828,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53549 {
53550 struct dentry *dentry = link->dentry;
53551 int error;
53552- char *s;
53553+ const char *s;
53554
53555 BUG_ON(nd->flags & LOOKUP_RCU);
53556
53557@@ -841,6 +849,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
53558 if (error)
53559 goto out_put_nd_path;
53560
53561+ if (gr_handle_follow_link(dentry->d_parent->d_inode,
53562+ dentry->d_inode, dentry, nd->path.mnt)) {
53563+ error = -EACCES;
53564+ goto out_put_nd_path;
53565+ }
53566+
53567 nd->last_type = LAST_BIND;
53568 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
53569 error = PTR_ERR(*p);
53570@@ -1588,6 +1602,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
53571 if (res)
53572 break;
53573 res = walk_component(nd, path, LOOKUP_FOLLOW);
53574+ if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
53575+ res = -EACCES;
53576 put_link(nd, &link, cookie);
53577 } while (res > 0);
53578
53579@@ -1686,7 +1702,7 @@ EXPORT_SYMBOL(full_name_hash);
53580 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
53581 {
53582 unsigned long a, b, adata, bdata, mask, hash, len;
53583- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53584+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
53585
53586 hash = a = 0;
53587 len = -sizeof(unsigned long);
53588@@ -1968,6 +1984,8 @@ static int path_lookupat(int dfd, const char *name,
53589 if (err)
53590 break;
53591 err = lookup_last(nd, &path);
53592+ if (!err && gr_handle_symlink_owner(&link, nd->inode))
53593+ err = -EACCES;
53594 put_link(nd, &link, cookie);
53595 }
53596 }
53597@@ -1975,6 +1993,13 @@ static int path_lookupat(int dfd, const char *name,
53598 if (!err)
53599 err = complete_walk(nd);
53600
53601+ if (!err && !(nd->flags & LOOKUP_PARENT)) {
53602+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53603+ path_put(&nd->path);
53604+ err = -ENOENT;
53605+ }
53606+ }
53607+
53608 if (!err && nd->flags & LOOKUP_DIRECTORY) {
53609 if (!nd->inode->i_op->lookup) {
53610 path_put(&nd->path);
53611@@ -2002,8 +2027,15 @@ static int filename_lookup(int dfd, struct filename *name,
53612 retval = path_lookupat(dfd, name->name,
53613 flags | LOOKUP_REVAL, nd);
53614
53615- if (likely(!retval))
53616+ if (likely(!retval)) {
53617 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
53618+ if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
53619+ if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
53620+ path_put(&nd->path);
53621+ return -ENOENT;
53622+ }
53623+ }
53624+ }
53625 return retval;
53626 }
53627
53628@@ -2381,6 +2413,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
53629 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
53630 return -EPERM;
53631
53632+ if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
53633+ return -EPERM;
53634+ if (gr_handle_rawio(inode))
53635+ return -EPERM;
53636+ if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
53637+ return -EACCES;
53638+
53639 return 0;
53640 }
53641
53642@@ -2602,7 +2641,7 @@ looked_up:
53643 * cleared otherwise prior to returning.
53644 */
53645 static int lookup_open(struct nameidata *nd, struct path *path,
53646- struct file *file,
53647+ struct path *link, struct file *file,
53648 const struct open_flags *op,
53649 bool got_write, int *opened)
53650 {
53651@@ -2637,6 +2676,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53652 /* Negative dentry, just create the file */
53653 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
53654 umode_t mode = op->mode;
53655+
53656+ if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
53657+ error = -EACCES;
53658+ goto out_dput;
53659+ }
53660+
53661+ if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
53662+ error = -EACCES;
53663+ goto out_dput;
53664+ }
53665+
53666 if (!IS_POSIXACL(dir->d_inode))
53667 mode &= ~current_umask();
53668 /*
53669@@ -2658,6 +2708,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
53670 nd->flags & LOOKUP_EXCL);
53671 if (error)
53672 goto out_dput;
53673+ else
53674+ gr_handle_create(dentry, nd->path.mnt);
53675 }
53676 out_no_open:
53677 path->dentry = dentry;
53678@@ -2672,7 +2724,7 @@ out_dput:
53679 /*
53680 * Handle the last step of open()
53681 */
53682-static int do_last(struct nameidata *nd, struct path *path,
53683+static int do_last(struct nameidata *nd, struct path *path, struct path *link,
53684 struct file *file, const struct open_flags *op,
53685 int *opened, struct filename *name)
53686 {
53687@@ -2701,16 +2753,32 @@ static int do_last(struct nameidata *nd, struct path *path,
53688 error = complete_walk(nd);
53689 if (error)
53690 return error;
53691+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53692+ error = -ENOENT;
53693+ goto out;
53694+ }
53695 audit_inode(name, nd->path.dentry, 0);
53696 if (open_flag & O_CREAT) {
53697 error = -EISDIR;
53698 goto out;
53699 }
53700+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53701+ error = -EACCES;
53702+ goto out;
53703+ }
53704 goto finish_open;
53705 case LAST_BIND:
53706 error = complete_walk(nd);
53707 if (error)
53708 return error;
53709+ if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
53710+ error = -ENOENT;
53711+ goto out;
53712+ }
53713+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53714+ error = -EACCES;
53715+ goto out;
53716+ }
53717 audit_inode(name, dir, 0);
53718 goto finish_open;
53719 }
53720@@ -2759,7 +2827,7 @@ retry_lookup:
53721 */
53722 }
53723 mutex_lock(&dir->d_inode->i_mutex);
53724- error = lookup_open(nd, path, file, op, got_write, opened);
53725+ error = lookup_open(nd, path, link, file, op, got_write, opened);
53726 mutex_unlock(&dir->d_inode->i_mutex);
53727
53728 if (error <= 0) {
53729@@ -2783,11 +2851,28 @@ retry_lookup:
53730 goto finish_open_created;
53731 }
53732
53733+ if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
53734+ error = -ENOENT;
53735+ goto exit_dput;
53736+ }
53737+ if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
53738+ error = -EACCES;
53739+ goto exit_dput;
53740+ }
53741+
53742 /*
53743 * create/update audit record if it already exists.
53744 */
53745- if (path->dentry->d_inode)
53746+ if (path->dentry->d_inode) {
53747+ /* only check if O_CREAT is specified, all other checks need to go
53748+ into may_open */
53749+ if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
53750+ error = -EACCES;
53751+ goto exit_dput;
53752+ }
53753+
53754 audit_inode(name, path->dentry, 0);
53755+ }
53756
53757 /*
53758 * If atomic_open() acquired write access it is dropped now due to
53759@@ -2828,6 +2913,11 @@ finish_lookup:
53760 }
53761 }
53762 BUG_ON(inode != path->dentry->d_inode);
53763+ /* if we're resolving a symlink to another symlink */
53764+ if (link && gr_handle_symlink_owner(link, inode)) {
53765+ error = -EACCES;
53766+ goto out;
53767+ }
53768 return 1;
53769 }
53770
53771@@ -2837,7 +2927,6 @@ finish_lookup:
53772 save_parent.dentry = nd->path.dentry;
53773 save_parent.mnt = mntget(path->mnt);
53774 nd->path.dentry = path->dentry;
53775-
53776 }
53777 nd->inode = inode;
53778 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
53779@@ -2846,6 +2935,16 @@ finish_lookup:
53780 path_put(&save_parent);
53781 return error;
53782 }
53783+
53784+ if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
53785+ error = -ENOENT;
53786+ goto out;
53787+ }
53788+ if (link && gr_handle_symlink_owner(link, nd->inode)) {
53789+ error = -EACCES;
53790+ goto out;
53791+ }
53792+
53793 error = -EISDIR;
53794 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
53795 goto out;
53796@@ -2944,7 +3043,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53797 if (unlikely(error))
53798 goto out;
53799
53800- error = do_last(nd, &path, file, op, &opened, pathname);
53801+ error = do_last(nd, &path, NULL, file, op, &opened, pathname);
53802 while (unlikely(error > 0)) { /* trailing symlink */
53803 struct path link = path;
53804 void *cookie;
53805@@ -2962,7 +3061,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
53806 error = follow_link(&link, nd, &cookie);
53807 if (unlikely(error))
53808 break;
53809- error = do_last(nd, &path, file, op, &opened, pathname);
53810+ error = do_last(nd, &path, &link, file, op, &opened, pathname);
53811 put_link(nd, &link, cookie);
53812 }
53813 out:
53814@@ -3062,8 +3161,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
53815 goto unlock;
53816
53817 error = -EEXIST;
53818- if (dentry->d_inode)
53819+ if (dentry->d_inode) {
53820+ if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
53821+ error = -ENOENT;
53822+ }
53823 goto fail;
53824+ }
53825 /*
53826 * Special case - lookup gave negative, but... we had foo/bar/
53827 * From the vfs_mknod() POV we just have a negative dentry -
53828@@ -3115,6 +3218,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
53829 }
53830 EXPORT_SYMBOL(user_path_create);
53831
53832+static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
53833+{
53834+ struct filename *tmp = getname(pathname);
53835+ struct dentry *res;
53836+ if (IS_ERR(tmp))
53837+ return ERR_CAST(tmp);
53838+ res = kern_path_create(dfd, tmp->name, path, lookup_flags);
53839+ if (IS_ERR(res))
53840+ putname(tmp);
53841+ else
53842+ *to = tmp;
53843+ return res;
53844+}
53845+
53846 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
53847 {
53848 int error = may_create(dir, dentry);
53849@@ -3177,6 +3294,17 @@ retry:
53850
53851 if (!IS_POSIXACL(path.dentry->d_inode))
53852 mode &= ~current_umask();
53853+
53854+ if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
53855+ error = -EPERM;
53856+ goto out;
53857+ }
53858+
53859+ if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
53860+ error = -EACCES;
53861+ goto out;
53862+ }
53863+
53864 error = security_path_mknod(&path, dentry, mode, dev);
53865 if (error)
53866 goto out;
53867@@ -3193,6 +3321,8 @@ retry:
53868 break;
53869 }
53870 out:
53871+ if (!error)
53872+ gr_handle_create(dentry, path.mnt);
53873 done_path_create(&path, dentry);
53874 if (retry_estale(error, lookup_flags)) {
53875 lookup_flags |= LOOKUP_REVAL;
53876@@ -3245,9 +3375,16 @@ retry:
53877
53878 if (!IS_POSIXACL(path.dentry->d_inode))
53879 mode &= ~current_umask();
53880+ if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
53881+ error = -EACCES;
53882+ goto out;
53883+ }
53884 error = security_path_mkdir(&path, dentry, mode);
53885 if (!error)
53886 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
53887+ if (!error)
53888+ gr_handle_create(dentry, path.mnt);
53889+out:
53890 done_path_create(&path, dentry);
53891 if (retry_estale(error, lookup_flags)) {
53892 lookup_flags |= LOOKUP_REVAL;
53893@@ -3328,6 +3465,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
53894 struct filename *name;
53895 struct dentry *dentry;
53896 struct nameidata nd;
53897+ ino_t saved_ino = 0;
53898+ dev_t saved_dev = 0;
53899 unsigned int lookup_flags = 0;
53900 retry:
53901 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53902@@ -3360,10 +3499,21 @@ retry:
53903 error = -ENOENT;
53904 goto exit3;
53905 }
53906+
53907+ saved_ino = dentry->d_inode->i_ino;
53908+ saved_dev = gr_get_dev_from_dentry(dentry);
53909+
53910+ if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
53911+ error = -EACCES;
53912+ goto exit3;
53913+ }
53914+
53915 error = security_path_rmdir(&nd.path, dentry);
53916 if (error)
53917 goto exit3;
53918 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
53919+ if (!error && (saved_dev || saved_ino))
53920+ gr_handle_delete(saved_ino, saved_dev);
53921 exit3:
53922 dput(dentry);
53923 exit2:
53924@@ -3429,6 +3579,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
53925 struct dentry *dentry;
53926 struct nameidata nd;
53927 struct inode *inode = NULL;
53928+ ino_t saved_ino = 0;
53929+ dev_t saved_dev = 0;
53930 unsigned int lookup_flags = 0;
53931 retry:
53932 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
53933@@ -3455,10 +3607,22 @@ retry:
53934 if (!inode)
53935 goto slashes;
53936 ihold(inode);
53937+
53938+ if (inode->i_nlink <= 1) {
53939+ saved_ino = inode->i_ino;
53940+ saved_dev = gr_get_dev_from_dentry(dentry);
53941+ }
53942+ if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
53943+ error = -EACCES;
53944+ goto exit2;
53945+ }
53946+
53947 error = security_path_unlink(&nd.path, dentry);
53948 if (error)
53949 goto exit2;
53950 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
53951+ if (!error && (saved_ino || saved_dev))
53952+ gr_handle_delete(saved_ino, saved_dev);
53953 exit2:
53954 dput(dentry);
53955 }
53956@@ -3536,9 +3700,17 @@ retry:
53957 if (IS_ERR(dentry))
53958 goto out_putname;
53959
53960+ if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
53961+ error = -EACCES;
53962+ goto out;
53963+ }
53964+
53965 error = security_path_symlink(&path, dentry, from->name);
53966 if (!error)
53967 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
53968+ if (!error)
53969+ gr_handle_create(dentry, path.mnt);
53970+out:
53971 done_path_create(&path, dentry);
53972 if (retry_estale(error, lookup_flags)) {
53973 lookup_flags |= LOOKUP_REVAL;
53974@@ -3612,6 +3784,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
53975 {
53976 struct dentry *new_dentry;
53977 struct path old_path, new_path;
53978+ struct filename *to = NULL;
53979 int how = 0;
53980 int error;
53981
53982@@ -3635,7 +3808,7 @@ retry:
53983 if (error)
53984 return error;
53985
53986- new_dentry = user_path_create(newdfd, newname, &new_path,
53987+ new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
53988 (how & LOOKUP_REVAL));
53989 error = PTR_ERR(new_dentry);
53990 if (IS_ERR(new_dentry))
53991@@ -3647,11 +3820,28 @@ retry:
53992 error = may_linkat(&old_path);
53993 if (unlikely(error))
53994 goto out_dput;
53995+
53996+ if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
53997+ old_path.dentry->d_inode,
53998+ old_path.dentry->d_inode->i_mode, to)) {
53999+ error = -EACCES;
54000+ goto out_dput;
54001+ }
54002+
54003+ if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
54004+ old_path.dentry, old_path.mnt, to)) {
54005+ error = -EACCES;
54006+ goto out_dput;
54007+ }
54008+
54009 error = security_path_link(old_path.dentry, &new_path, new_dentry);
54010 if (error)
54011 goto out_dput;
54012 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
54013+ if (!error)
54014+ gr_handle_create(new_dentry, new_path.mnt);
54015 out_dput:
54016+ putname(to);
54017 done_path_create(&new_path, new_dentry);
54018 if (retry_estale(error, how)) {
54019 how |= LOOKUP_REVAL;
54020@@ -3897,12 +4087,21 @@ retry:
54021 if (new_dentry == trap)
54022 goto exit5;
54023
54024+ error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
54025+ old_dentry, old_dir->d_inode, oldnd.path.mnt,
54026+ to);
54027+ if (error)
54028+ goto exit5;
54029+
54030 error = security_path_rename(&oldnd.path, old_dentry,
54031 &newnd.path, new_dentry);
54032 if (error)
54033 goto exit5;
54034 error = vfs_rename(old_dir->d_inode, old_dentry,
54035 new_dir->d_inode, new_dentry);
54036+ if (!error)
54037+ gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
54038+ new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
54039 exit5:
54040 dput(new_dentry);
54041 exit4:
54042@@ -3934,6 +4133,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
54043
54044 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
54045 {
54046+ char tmpbuf[64];
54047+ const char *newlink;
54048 int len;
54049
54050 len = PTR_ERR(link);
54051@@ -3943,7 +4144,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
54052 len = strlen(link);
54053 if (len > (unsigned) buflen)
54054 len = buflen;
54055- if (copy_to_user(buffer, link, len))
54056+
54057+ if (len < sizeof(tmpbuf)) {
54058+ memcpy(tmpbuf, link, len);
54059+ newlink = tmpbuf;
54060+ } else
54061+ newlink = link;
54062+
54063+ if (copy_to_user(buffer, newlink, len))
54064 len = -EFAULT;
54065 out:
54066 return len;
54067diff --git a/fs/namespace.c b/fs/namespace.c
54068index e945b81..fc018e2 100644
54069--- a/fs/namespace.c
54070+++ b/fs/namespace.c
54071@@ -1219,6 +1219,9 @@ static int do_umount(struct mount *mnt, int flags)
54072 if (!(sb->s_flags & MS_RDONLY))
54073 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
54074 up_write(&sb->s_umount);
54075+
54076+ gr_log_remount(mnt->mnt_devname, retval);
54077+
54078 return retval;
54079 }
54080
54081@@ -1238,6 +1241,9 @@ static int do_umount(struct mount *mnt, int flags)
54082 br_write_unlock(&vfsmount_lock);
54083 up_write(&namespace_sem);
54084 release_mounts(&umount_list);
54085+
54086+ gr_log_unmount(mnt->mnt_devname, retval);
54087+
54088 return retval;
54089 }
54090
54091@@ -1257,7 +1263,7 @@ static inline bool may_mount(void)
54092 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
54093 */
54094
54095-SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
54096+SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
54097 {
54098 struct path path;
54099 struct mount *mnt;
54100@@ -1297,7 +1303,7 @@ out:
54101 /*
54102 * The 2.0 compatible umount. No flags.
54103 */
54104-SYSCALL_DEFINE1(oldumount, char __user *, name)
54105+SYSCALL_DEFINE1(oldumount, const char __user *, name)
54106 {
54107 return sys_umount(name, 0);
54108 }
54109@@ -2267,6 +2273,16 @@ long do_mount(const char *dev_name, const char *dir_name,
54110 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
54111 MS_STRICTATIME);
54112
54113+ if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
54114+ retval = -EPERM;
54115+ goto dput_out;
54116+ }
54117+
54118+ if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
54119+ retval = -EPERM;
54120+ goto dput_out;
54121+ }
54122+
54123 if (flags & MS_REMOUNT)
54124 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
54125 data_page);
54126@@ -2281,6 +2297,9 @@ long do_mount(const char *dev_name, const char *dir_name,
54127 dev_name, data_page);
54128 dput_out:
54129 path_put(&path);
54130+
54131+ gr_log_mount(dev_name, dir_name, retval);
54132+
54133 return retval;
54134 }
54135
54136@@ -2454,8 +2473,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
54137 }
54138 EXPORT_SYMBOL(mount_subtree);
54139
54140-SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
54141- char __user *, type, unsigned long, flags, void __user *, data)
54142+SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
54143+ const char __user *, type, unsigned long, flags, void __user *, data)
54144 {
54145 int ret;
54146 char *kernel_type;
54147@@ -2567,6 +2586,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
54148 if (error)
54149 goto out2;
54150
54151+ if (gr_handle_chroot_pivot()) {
54152+ error = -EPERM;
54153+ goto out2;
54154+ }
54155+
54156 get_fs_root(current->fs, &root);
54157 error = lock_mount(&old);
54158 if (error)
54159@@ -2815,7 +2839,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
54160 !nsown_capable(CAP_SYS_ADMIN))
54161 return -EPERM;
54162
54163- if (fs->users != 1)
54164+ if (atomic_read(&fs->users) != 1)
54165 return -EINVAL;
54166
54167 get_mnt_ns(mnt_ns);
54168diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
54169index 5088b57..eabd719 100644
54170--- a/fs/nfs/callback.c
54171+++ b/fs/nfs/callback.c
54172@@ -208,7 +208,6 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54173 struct svc_rqst *rqstp;
54174 int (*callback_svc)(void *vrqstp);
54175 struct nfs_callback_data *cb_info = &nfs_callback_info[minorversion];
54176- char svc_name[12];
54177 int ret;
54178
54179 nfs_callback_bc_serv(minorversion, xprt, serv);
54180@@ -232,10 +231,9 @@ static int nfs_callback_start_svc(int minorversion, struct rpc_xprt *xprt,
54181
54182 svc_sock_update_bufs(serv);
54183
54184- sprintf(svc_name, "nfsv4.%u-svc", minorversion);
54185 cb_info->serv = serv;
54186 cb_info->rqst = rqstp;
54187- cb_info->task = kthread_run(callback_svc, cb_info->rqst, svc_name);
54188+ cb_info->task = kthread_run(callback_svc, cb_info->rqst, "nfsv4.%u-svc", minorversion);
54189 if (IS_ERR(cb_info->task)) {
54190 ret = PTR_ERR(cb_info->task);
54191 svc_exit_thread(cb_info->rqst);
54192diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
54193index 59461c9..b17c57e 100644
54194--- a/fs/nfs/callback_xdr.c
54195+++ b/fs/nfs/callback_xdr.c
54196@@ -51,7 +51,7 @@ struct callback_op {
54197 callback_decode_arg_t decode_args;
54198 callback_encode_res_t encode_res;
54199 long res_maxsize;
54200-};
54201+} __do_const;
54202
54203 static struct callback_op callback_ops[];
54204
54205diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
54206index 1f94167..79c4ce4 100644
54207--- a/fs/nfs/inode.c
54208+++ b/fs/nfs/inode.c
54209@@ -1041,16 +1041,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
54210 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
54211 }
54212
54213-static atomic_long_t nfs_attr_generation_counter;
54214+static atomic_long_unchecked_t nfs_attr_generation_counter;
54215
54216 static unsigned long nfs_read_attr_generation_counter(void)
54217 {
54218- return atomic_long_read(&nfs_attr_generation_counter);
54219+ return atomic_long_read_unchecked(&nfs_attr_generation_counter);
54220 }
54221
54222 unsigned long nfs_inc_attr_generation_counter(void)
54223 {
54224- return atomic_long_inc_return(&nfs_attr_generation_counter);
54225+ return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
54226 }
54227
54228 void nfs_fattr_init(struct nfs_fattr *fattr)
54229diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
54230index d41a351..7899577 100644
54231--- a/fs/nfs/nfs4state.c
54232+++ b/fs/nfs/nfs4state.c
54233@@ -1182,7 +1182,7 @@ void nfs4_schedule_state_manager(struct nfs_client *clp)
54234 snprintf(buf, sizeof(buf), "%s-manager",
54235 rpc_peeraddr2str(clp->cl_rpcclient, RPC_DISPLAY_ADDR));
54236 rcu_read_unlock();
54237- task = kthread_run(nfs4_run_state_manager, clp, buf);
54238+ task = kthread_run(nfs4_run_state_manager, clp, "%s", buf);
54239 if (IS_ERR(task)) {
54240 printk(KERN_ERR "%s: kthread_run: %ld\n",
54241 __func__, PTR_ERR(task));
54242diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
54243index d401d01..10b3e62 100644
54244--- a/fs/nfsd/nfs4proc.c
54245+++ b/fs/nfsd/nfs4proc.c
54246@@ -1109,7 +1109,7 @@ struct nfsd4_operation {
54247 nfsd4op_rsize op_rsize_bop;
54248 stateid_getter op_get_currentstateid;
54249 stateid_setter op_set_currentstateid;
54250-};
54251+} __do_const;
54252
54253 static struct nfsd4_operation nfsd4_ops[];
54254
54255diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
54256index 6eb0dc5..29067a9 100644
54257--- a/fs/nfsd/nfs4xdr.c
54258+++ b/fs/nfsd/nfs4xdr.c
54259@@ -1457,7 +1457,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
54260
54261 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
54262
54263-static nfsd4_dec nfsd4_dec_ops[] = {
54264+static const nfsd4_dec nfsd4_dec_ops[] = {
54265 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54266 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54267 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54268@@ -1497,7 +1497,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
54269 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
54270 };
54271
54272-static nfsd4_dec nfsd41_dec_ops[] = {
54273+static const nfsd4_dec nfsd41_dec_ops[] = {
54274 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
54275 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
54276 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
54277@@ -1559,7 +1559,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
54278 };
54279
54280 struct nfsd4_minorversion_ops {
54281- nfsd4_dec *decoders;
54282+ const nfsd4_dec *decoders;
54283 int nops;
54284 };
54285
54286diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
54287index ca05f6d..b88c3a7 100644
54288--- a/fs/nfsd/nfscache.c
54289+++ b/fs/nfsd/nfscache.c
54290@@ -461,13 +461,16 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
54291 {
54292 struct svc_cacherep *rp = rqstp->rq_cacherep;
54293 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
54294- int len;
54295+ long len;
54296
54297 if (!rp)
54298 return;
54299
54300- len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
54301- len >>= 2;
54302+ if (statp) {
54303+ len = (char*)statp - (char*)resv->iov_base;
54304+ len = resv->iov_len - len;
54305+ len >>= 2;
54306+ }
54307
54308 /* Don't cache excessive amounts of data and XDR failures */
54309 if (!statp || len > (256 >> 2)) {
54310diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
54311index 2b2e239..c915b48 100644
54312--- a/fs/nfsd/vfs.c
54313+++ b/fs/nfsd/vfs.c
54314@@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54315 } else {
54316 oldfs = get_fs();
54317 set_fs(KERNEL_DS);
54318- host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
54319+ host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
54320 set_fs(oldfs);
54321 }
54322
54323@@ -1026,7 +1026,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
54324
54325 /* Write the data. */
54326 oldfs = get_fs(); set_fs(KERNEL_DS);
54327- host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
54328+ host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
54329 set_fs(oldfs);
54330 if (host_err < 0)
54331 goto out_nfserr;
54332@@ -1572,7 +1572,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
54333 */
54334
54335 oldfs = get_fs(); set_fs(KERNEL_DS);
54336- host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
54337+ host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
54338 set_fs(oldfs);
54339
54340 if (host_err < 0)
54341diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
54342index fea6bd5..8ee9d81 100644
54343--- a/fs/nls/nls_base.c
54344+++ b/fs/nls/nls_base.c
54345@@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
54346
54347 int register_nls(struct nls_table * nls)
54348 {
54349- struct nls_table ** tmp = &tables;
54350+ struct nls_table *tmp = tables;
54351
54352 if (nls->next)
54353 return -EBUSY;
54354
54355 spin_lock(&nls_lock);
54356- while (*tmp) {
54357- if (nls == *tmp) {
54358+ while (tmp) {
54359+ if (nls == tmp) {
54360 spin_unlock(&nls_lock);
54361 return -EBUSY;
54362 }
54363- tmp = &(*tmp)->next;
54364+ tmp = tmp->next;
54365 }
54366- nls->next = tables;
54367+ pax_open_kernel();
54368+ *(struct nls_table **)&nls->next = tables;
54369+ pax_close_kernel();
54370 tables = nls;
54371 spin_unlock(&nls_lock);
54372 return 0;
54373@@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
54374
54375 int unregister_nls(struct nls_table * nls)
54376 {
54377- struct nls_table ** tmp = &tables;
54378+ struct nls_table * const * tmp = &tables;
54379
54380 spin_lock(&nls_lock);
54381 while (*tmp) {
54382 if (nls == *tmp) {
54383- *tmp = nls->next;
54384+ pax_open_kernel();
54385+ *(struct nls_table **)tmp = nls->next;
54386+ pax_close_kernel();
54387 spin_unlock(&nls_lock);
54388 return 0;
54389 }
54390diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
54391index 7424929..35f6be5 100644
54392--- a/fs/nls/nls_euc-jp.c
54393+++ b/fs/nls/nls_euc-jp.c
54394@@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
54395 p_nls = load_nls("cp932");
54396
54397 if (p_nls) {
54398- table.charset2upper = p_nls->charset2upper;
54399- table.charset2lower = p_nls->charset2lower;
54400+ pax_open_kernel();
54401+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54402+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54403+ pax_close_kernel();
54404 return register_nls(&table);
54405 }
54406
54407diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
54408index e7bc1d7..06bd4bb 100644
54409--- a/fs/nls/nls_koi8-ru.c
54410+++ b/fs/nls/nls_koi8-ru.c
54411@@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
54412 p_nls = load_nls("koi8-u");
54413
54414 if (p_nls) {
54415- table.charset2upper = p_nls->charset2upper;
54416- table.charset2lower = p_nls->charset2lower;
54417+ pax_open_kernel();
54418+ *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
54419+ *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
54420+ pax_close_kernel();
54421 return register_nls(&table);
54422 }
54423
54424diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
54425index 5d84442..2c034ba 100644
54426--- a/fs/notify/fanotify/fanotify_user.c
54427+++ b/fs/notify/fanotify/fanotify_user.c
54428@@ -121,6 +121,7 @@ static int fill_event_metadata(struct fsnotify_group *group,
54429 metadata->event_len = FAN_EVENT_METADATA_LEN;
54430 metadata->metadata_len = FAN_EVENT_METADATA_LEN;
54431 metadata->vers = FANOTIFY_METADATA_VERSION;
54432+ metadata->reserved = 0;
54433 metadata->mask = event->mask & FAN_ALL_OUTGOING_EVENTS;
54434 metadata->pid = pid_vnr(event->tgid);
54435 if (unlikely(event->mask & FAN_Q_OVERFLOW))
54436@@ -251,8 +252,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
54437
54438 fd = fanotify_event_metadata.fd;
54439 ret = -EFAULT;
54440- if (copy_to_user(buf, &fanotify_event_metadata,
54441- fanotify_event_metadata.event_len))
54442+ if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
54443+ copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
54444 goto out_close_fd;
54445
54446 ret = prepare_for_access_response(group, event, fd);
54447diff --git a/fs/notify/notification.c b/fs/notify/notification.c
54448index 7b51b05..5ea5ef6 100644
54449--- a/fs/notify/notification.c
54450+++ b/fs/notify/notification.c
54451@@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
54452 * get set to 0 so it will never get 'freed'
54453 */
54454 static struct fsnotify_event *q_overflow_event;
54455-static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54456+static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54457
54458 /**
54459 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
54460@@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
54461 */
54462 u32 fsnotify_get_cookie(void)
54463 {
54464- return atomic_inc_return(&fsnotify_sync_cookie);
54465+ return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
54466 }
54467 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
54468
54469diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
54470index aa411c3..c260a84 100644
54471--- a/fs/ntfs/dir.c
54472+++ b/fs/ntfs/dir.c
54473@@ -1329,7 +1329,7 @@ find_next_index_buffer:
54474 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
54475 ~(s64)(ndir->itype.index.block_size - 1)));
54476 /* Bounds checks. */
54477- if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54478+ if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
54479 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
54480 "inode 0x%lx or driver bug.", vdir->i_ino);
54481 goto err_out;
54482diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
54483index 5b2d4f0..c6de396 100644
54484--- a/fs/ntfs/file.c
54485+++ b/fs/ntfs/file.c
54486@@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
54487 #endif /* NTFS_RW */
54488 };
54489
54490-const struct file_operations ntfs_empty_file_ops = {};
54491+const struct file_operations ntfs_empty_file_ops __read_only;
54492
54493-const struct inode_operations ntfs_empty_inode_ops = {};
54494+const struct inode_operations ntfs_empty_inode_ops __read_only;
54495diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
54496index aebeacd..0dcdd26 100644
54497--- a/fs/ocfs2/localalloc.c
54498+++ b/fs/ocfs2/localalloc.c
54499@@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
54500 goto bail;
54501 }
54502
54503- atomic_inc(&osb->alloc_stats.moves);
54504+ atomic_inc_unchecked(&osb->alloc_stats.moves);
54505
54506 bail:
54507 if (handle)
54508diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
54509index d355e6e..578d905 100644
54510--- a/fs/ocfs2/ocfs2.h
54511+++ b/fs/ocfs2/ocfs2.h
54512@@ -235,11 +235,11 @@ enum ocfs2_vol_state
54513
54514 struct ocfs2_alloc_stats
54515 {
54516- atomic_t moves;
54517- atomic_t local_data;
54518- atomic_t bitmap_data;
54519- atomic_t bg_allocs;
54520- atomic_t bg_extends;
54521+ atomic_unchecked_t moves;
54522+ atomic_unchecked_t local_data;
54523+ atomic_unchecked_t bitmap_data;
54524+ atomic_unchecked_t bg_allocs;
54525+ atomic_unchecked_t bg_extends;
54526 };
54527
54528 enum ocfs2_local_alloc_state
54529diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
54530index b7e74b5..19c6536 100644
54531--- a/fs/ocfs2/suballoc.c
54532+++ b/fs/ocfs2/suballoc.c
54533@@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
54534 mlog_errno(status);
54535 goto bail;
54536 }
54537- atomic_inc(&osb->alloc_stats.bg_extends);
54538+ atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
54539
54540 /* You should never ask for this much metadata */
54541 BUG_ON(bits_wanted >
54542@@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
54543 mlog_errno(status);
54544 goto bail;
54545 }
54546- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54547+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54548
54549 *suballoc_loc = res.sr_bg_blkno;
54550 *suballoc_bit_start = res.sr_bit_offset;
54551@@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
54552 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
54553 res->sr_bits);
54554
54555- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54556+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54557
54558 BUG_ON(res->sr_bits != 1);
54559
54560@@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
54561 mlog_errno(status);
54562 goto bail;
54563 }
54564- atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54565+ atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
54566
54567 BUG_ON(res.sr_bits != 1);
54568
54569@@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54570 cluster_start,
54571 num_clusters);
54572 if (!status)
54573- atomic_inc(&osb->alloc_stats.local_data);
54574+ atomic_inc_unchecked(&osb->alloc_stats.local_data);
54575 } else {
54576 if (min_clusters > (osb->bitmap_cpg - 1)) {
54577 /* The only paths asking for contiguousness
54578@@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
54579 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
54580 res.sr_bg_blkno,
54581 res.sr_bit_offset);
54582- atomic_inc(&osb->alloc_stats.bitmap_data);
54583+ atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
54584 *num_clusters = res.sr_bits;
54585 }
54586 }
54587diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
54588index 01b8516..579c4df 100644
54589--- a/fs/ocfs2/super.c
54590+++ b/fs/ocfs2/super.c
54591@@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
54592 "%10s => GlobalAllocs: %d LocalAllocs: %d "
54593 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
54594 "Stats",
54595- atomic_read(&osb->alloc_stats.bitmap_data),
54596- atomic_read(&osb->alloc_stats.local_data),
54597- atomic_read(&osb->alloc_stats.bg_allocs),
54598- atomic_read(&osb->alloc_stats.moves),
54599- atomic_read(&osb->alloc_stats.bg_extends));
54600+ atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
54601+ atomic_read_unchecked(&osb->alloc_stats.local_data),
54602+ atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
54603+ atomic_read_unchecked(&osb->alloc_stats.moves),
54604+ atomic_read_unchecked(&osb->alloc_stats.bg_extends));
54605
54606 out += snprintf(buf + out, len - out,
54607 "%10s => State: %u Descriptor: %llu Size: %u bits "
54608@@ -2122,11 +2122,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
54609 spin_lock_init(&osb->osb_xattr_lock);
54610 ocfs2_init_steal_slots(osb);
54611
54612- atomic_set(&osb->alloc_stats.moves, 0);
54613- atomic_set(&osb->alloc_stats.local_data, 0);
54614- atomic_set(&osb->alloc_stats.bitmap_data, 0);
54615- atomic_set(&osb->alloc_stats.bg_allocs, 0);
54616- atomic_set(&osb->alloc_stats.bg_extends, 0);
54617+ atomic_set_unchecked(&osb->alloc_stats.moves, 0);
54618+ atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
54619+ atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
54620+ atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
54621+ atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
54622
54623 /* Copy the blockcheck stats from the superblock probe */
54624 osb->osb_ecc_stats = *stats;
54625diff --git a/fs/open.c b/fs/open.c
54626index 6835446..eadf09f 100644
54627--- a/fs/open.c
54628+++ b/fs/open.c
54629@@ -32,6 +32,8 @@
54630 #include <linux/dnotify.h>
54631 #include <linux/compat.h>
54632
54633+#define CREATE_TRACE_POINTS
54634+#include <trace/events/fs.h>
54635 #include "internal.h"
54636
54637 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
54638@@ -102,6 +104,8 @@ long vfs_truncate(struct path *path, loff_t length)
54639 error = locks_verify_truncate(inode, NULL, length);
54640 if (!error)
54641 error = security_path_truncate(path);
54642+ if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
54643+ error = -EACCES;
54644 if (!error)
54645 error = do_truncate(path->dentry, length, 0, NULL);
54646
54647@@ -186,6 +190,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
54648 error = locks_verify_truncate(inode, f.file, length);
54649 if (!error)
54650 error = security_path_truncate(&f.file->f_path);
54651+ if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
54652+ error = -EACCES;
54653 if (!error)
54654 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
54655 sb_end_write(inode->i_sb);
54656@@ -388,6 +394,9 @@ retry:
54657 if (__mnt_is_readonly(path.mnt))
54658 res = -EROFS;
54659
54660+ if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
54661+ res = -EACCES;
54662+
54663 out_path_release:
54664 path_put(&path);
54665 if (retry_estale(res, lookup_flags)) {
54666@@ -419,6 +428,8 @@ retry:
54667 if (error)
54668 goto dput_and_out;
54669
54670+ gr_log_chdir(path.dentry, path.mnt);
54671+
54672 set_fs_pwd(current->fs, &path);
54673
54674 dput_and_out:
54675@@ -448,6 +459,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
54676 goto out_putf;
54677
54678 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
54679+
54680+ if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
54681+ error = -EPERM;
54682+
54683+ if (!error)
54684+ gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
54685+
54686 if (!error)
54687 set_fs_pwd(current->fs, &f.file->f_path);
54688 out_putf:
54689@@ -477,7 +495,13 @@ retry:
54690 if (error)
54691 goto dput_and_out;
54692
54693+ if (gr_handle_chroot_chroot(path.dentry, path.mnt))
54694+ goto dput_and_out;
54695+
54696 set_fs_root(current->fs, &path);
54697+
54698+ gr_handle_chroot_chdir(&path);
54699+
54700 error = 0;
54701 dput_and_out:
54702 path_put(&path);
54703@@ -499,6 +523,16 @@ static int chmod_common(struct path *path, umode_t mode)
54704 if (error)
54705 return error;
54706 mutex_lock(&inode->i_mutex);
54707+
54708+ if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
54709+ error = -EACCES;
54710+ goto out_unlock;
54711+ }
54712+ if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
54713+ error = -EACCES;
54714+ goto out_unlock;
54715+ }
54716+
54717 error = security_path_chmod(path, mode);
54718 if (error)
54719 goto out_unlock;
54720@@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
54721 uid = make_kuid(current_user_ns(), user);
54722 gid = make_kgid(current_user_ns(), group);
54723
54724+ if (!gr_acl_handle_chown(path->dentry, path->mnt))
54725+ return -EACCES;
54726+
54727 newattrs.ia_valid = ATTR_CTIME;
54728 if (user != (uid_t) -1) {
54729 if (!uid_valid(uid))
54730@@ -974,6 +1011,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
54731 } else {
54732 fsnotify_open(f);
54733 fd_install(fd, f);
54734+ trace_do_sys_open(tmp->name, flags, mode);
54735 }
54736 }
54737 putname(tmp);
54738diff --git a/fs/pipe.c b/fs/pipe.c
54739index 2234f3f..f9083a1 100644
54740--- a/fs/pipe.c
54741+++ b/fs/pipe.c
54742@@ -438,9 +438,9 @@ redo:
54743 }
54744 if (bufs) /* More to do? */
54745 continue;
54746- if (!pipe->writers)
54747+ if (!atomic_read(&pipe->writers))
54748 break;
54749- if (!pipe->waiting_writers) {
54750+ if (!atomic_read(&pipe->waiting_writers)) {
54751 /* syscall merging: Usually we must not sleep
54752 * if O_NONBLOCK is set, or if we got some data.
54753 * But if a writer sleeps in kernel space, then
54754@@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
54755 mutex_lock(&inode->i_mutex);
54756 pipe = inode->i_pipe;
54757
54758- if (!pipe->readers) {
54759+ if (!atomic_read(&pipe->readers)) {
54760 send_sig(SIGPIPE, current, 0);
54761 ret = -EPIPE;
54762 goto out;
54763@@ -553,7 +553,7 @@ redo1:
54764 for (;;) {
54765 int bufs;
54766
54767- if (!pipe->readers) {
54768+ if (!atomic_read(&pipe->readers)) {
54769 send_sig(SIGPIPE, current, 0);
54770 if (!ret)
54771 ret = -EPIPE;
54772@@ -644,9 +644,9 @@ redo2:
54773 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
54774 do_wakeup = 0;
54775 }
54776- pipe->waiting_writers++;
54777+ atomic_inc(&pipe->waiting_writers);
54778 pipe_wait(pipe);
54779- pipe->waiting_writers--;
54780+ atomic_dec(&pipe->waiting_writers);
54781 }
54782 out:
54783 mutex_unlock(&inode->i_mutex);
54784@@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54785 mask = 0;
54786 if (filp->f_mode & FMODE_READ) {
54787 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
54788- if (!pipe->writers && filp->f_version != pipe->w_counter)
54789+ if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
54790 mask |= POLLHUP;
54791 }
54792
54793@@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
54794 * Most Unices do not set POLLERR for FIFOs but on Linux they
54795 * behave exactly like pipes for poll().
54796 */
54797- if (!pipe->readers)
54798+ if (!atomic_read(&pipe->readers))
54799 mask |= POLLERR;
54800 }
54801
54802@@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
54803
54804 mutex_lock(&inode->i_mutex);
54805 pipe = inode->i_pipe;
54806- pipe->readers -= decr;
54807- pipe->writers -= decw;
54808+ atomic_sub(decr, &pipe->readers);
54809+ atomic_sub(decw, &pipe->writers);
54810
54811- if (!pipe->readers && !pipe->writers) {
54812+ if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
54813 free_pipe_info(inode);
54814 } else {
54815 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
54816@@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
54817
54818 if (inode->i_pipe) {
54819 ret = 0;
54820- inode->i_pipe->readers++;
54821+ atomic_inc(&inode->i_pipe->readers);
54822 }
54823
54824 mutex_unlock(&inode->i_mutex);
54825@@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
54826
54827 if (inode->i_pipe) {
54828 ret = 0;
54829- inode->i_pipe->writers++;
54830+ atomic_inc(&inode->i_pipe->writers);
54831 }
54832
54833 mutex_unlock(&inode->i_mutex);
54834@@ -871,9 +871,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
54835 if (inode->i_pipe) {
54836 ret = 0;
54837 if (filp->f_mode & FMODE_READ)
54838- inode->i_pipe->readers++;
54839+ atomic_inc(&inode->i_pipe->readers);
54840 if (filp->f_mode & FMODE_WRITE)
54841- inode->i_pipe->writers++;
54842+ atomic_inc(&inode->i_pipe->writers);
54843 }
54844
54845 mutex_unlock(&inode->i_mutex);
54846@@ -965,7 +965,7 @@ void free_pipe_info(struct inode *inode)
54847 inode->i_pipe = NULL;
54848 }
54849
54850-static struct vfsmount *pipe_mnt __read_mostly;
54851+struct vfsmount *pipe_mnt __read_mostly;
54852
54853 /*
54854 * pipefs_dname() is called from d_path().
54855@@ -995,7 +995,8 @@ static struct inode * get_pipe_inode(void)
54856 goto fail_iput;
54857 inode->i_pipe = pipe;
54858
54859- pipe->readers = pipe->writers = 1;
54860+ atomic_set(&pipe->readers, 1);
54861+ atomic_set(&pipe->writers, 1);
54862 inode->i_fop = &rdwr_pipefifo_fops;
54863
54864 /*
54865diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
54866index 15af622..0e9f4467 100644
54867--- a/fs/proc/Kconfig
54868+++ b/fs/proc/Kconfig
54869@@ -30,12 +30,12 @@ config PROC_FS
54870
54871 config PROC_KCORE
54872 bool "/proc/kcore support" if !ARM
54873- depends on PROC_FS && MMU
54874+ depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
54875
54876 config PROC_VMCORE
54877 bool "/proc/vmcore support"
54878- depends on PROC_FS && CRASH_DUMP
54879- default y
54880+ depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
54881+ default n
54882 help
54883 Exports the dump image of crashed kernel in ELF format.
54884
54885@@ -59,8 +59,8 @@ config PROC_SYSCTL
54886 limited in memory.
54887
54888 config PROC_PAGE_MONITOR
54889- default y
54890- depends on PROC_FS && MMU
54891+ default n
54892+ depends on PROC_FS && MMU && !GRKERNSEC
54893 bool "Enable /proc page monitoring" if EXPERT
54894 help
54895 Various /proc files exist to monitor process memory utilization:
54896diff --git a/fs/proc/array.c b/fs/proc/array.c
54897index cbd0f1b..adec3f0 100644
54898--- a/fs/proc/array.c
54899+++ b/fs/proc/array.c
54900@@ -60,6 +60,7 @@
54901 #include <linux/tty.h>
54902 #include <linux/string.h>
54903 #include <linux/mman.h>
54904+#include <linux/grsecurity.h>
54905 #include <linux/proc_fs.h>
54906 #include <linux/ioport.h>
54907 #include <linux/uaccess.h>
54908@@ -363,6 +364,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
54909 seq_putc(m, '\n');
54910 }
54911
54912+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54913+static inline void task_pax(struct seq_file *m, struct task_struct *p)
54914+{
54915+ if (p->mm)
54916+ seq_printf(m, "PaX:\t%c%c%c%c%c\n",
54917+ p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
54918+ p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
54919+ p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
54920+ p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
54921+ p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
54922+ else
54923+ seq_printf(m, "PaX:\t-----\n");
54924+}
54925+#endif
54926+
54927 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54928 struct pid *pid, struct task_struct *task)
54929 {
54930@@ -381,9 +397,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54931 task_cpus_allowed(m, task);
54932 cpuset_task_status_allowed(m, task);
54933 task_context_switch_counts(m, task);
54934+
54935+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
54936+ task_pax(m, task);
54937+#endif
54938+
54939+#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
54940+ task_grsec_rbac(m, task);
54941+#endif
54942+
54943 return 0;
54944 }
54945
54946+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54947+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54948+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
54949+ _mm->pax_flags & MF_PAX_SEGMEXEC))
54950+#endif
54951+
54952 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54953 struct pid *pid, struct task_struct *task, int whole)
54954 {
54955@@ -405,6 +436,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54956 char tcomm[sizeof(task->comm)];
54957 unsigned long flags;
54958
54959+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54960+ if (current->exec_id != m->exec_id) {
54961+ gr_log_badprocpid("stat");
54962+ return 0;
54963+ }
54964+#endif
54965+
54966 state = *get_task_state(task);
54967 vsize = eip = esp = 0;
54968 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
54969@@ -476,6 +514,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54970 gtime = task_gtime(task);
54971 }
54972
54973+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54974+ if (PAX_RAND_FLAGS(mm)) {
54975+ eip = 0;
54976+ esp = 0;
54977+ wchan = 0;
54978+ }
54979+#endif
54980+#ifdef CONFIG_GRKERNSEC_HIDESYM
54981+ wchan = 0;
54982+ eip =0;
54983+ esp =0;
54984+#endif
54985+
54986 /* scale priority and nice values from timeslices to -20..20 */
54987 /* to make it look like a "normal" Unix priority/nice value */
54988 priority = task_prio(task);
54989@@ -512,9 +563,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
54990 seq_put_decimal_ull(m, ' ', vsize);
54991 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
54992 seq_put_decimal_ull(m, ' ', rsslim);
54993+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54994+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
54995+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
54996+ seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
54997+#else
54998 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
54999 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
55000 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
55001+#endif
55002 seq_put_decimal_ull(m, ' ', esp);
55003 seq_put_decimal_ull(m, ' ', eip);
55004 /* The signal information here is obsolete.
55005@@ -536,7 +593,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
55006 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
55007 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
55008
55009- if (mm && permitted) {
55010+ if (mm && permitted
55011+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55012+ && !PAX_RAND_FLAGS(mm)
55013+#endif
55014+ ) {
55015 seq_put_decimal_ull(m, ' ', mm->start_data);
55016 seq_put_decimal_ull(m, ' ', mm->end_data);
55017 seq_put_decimal_ull(m, ' ', mm->start_brk);
55018@@ -574,8 +635,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55019 struct pid *pid, struct task_struct *task)
55020 {
55021 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
55022- struct mm_struct *mm = get_task_mm(task);
55023+ struct mm_struct *mm;
55024
55025+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55026+ if (current->exec_id != m->exec_id) {
55027+ gr_log_badprocpid("statm");
55028+ return 0;
55029+ }
55030+#endif
55031+ mm = get_task_mm(task);
55032 if (mm) {
55033 size = task_statm(mm, &shared, &text, &data, &resident);
55034 mmput(mm);
55035@@ -598,6 +666,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55036 return 0;
55037 }
55038
55039+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55040+int proc_pid_ipaddr(struct task_struct *task, char *buffer)
55041+{
55042+ return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
55043+}
55044+#endif
55045+
55046 #ifdef CONFIG_CHECKPOINT_RESTORE
55047 static struct pid *
55048 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
55049diff --git a/fs/proc/base.c b/fs/proc/base.c
55050index 69078c7..3e12a75 100644
55051--- a/fs/proc/base.c
55052+++ b/fs/proc/base.c
55053@@ -112,6 +112,14 @@ struct pid_entry {
55054 union proc_op op;
55055 };
55056
55057+struct getdents_callback {
55058+ struct linux_dirent __user * current_dir;
55059+ struct linux_dirent __user * previous;
55060+ struct file * file;
55061+ int count;
55062+ int error;
55063+};
55064+
55065 #define NOD(NAME, MODE, IOP, FOP, OP) { \
55066 .name = (NAME), \
55067 .len = sizeof(NAME) - 1, \
55068@@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
55069 if (!mm->arg_end)
55070 goto out_mm; /* Shh! No looking before we're done */
55071
55072+ if (gr_acl_handle_procpidmem(task))
55073+ goto out_mm;
55074+
55075 len = mm->arg_end - mm->arg_start;
55076
55077 if (len > PAGE_SIZE)
55078@@ -236,12 +247,28 @@ out:
55079 return res;
55080 }
55081
55082+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55083+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55084+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55085+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55086+#endif
55087+
55088 static int proc_pid_auxv(struct task_struct *task, char *buffer)
55089 {
55090 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
55091 int res = PTR_ERR(mm);
55092 if (mm && !IS_ERR(mm)) {
55093 unsigned int nwords = 0;
55094+
55095+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55096+ /* allow if we're currently ptracing this task */
55097+ if (PAX_RAND_FLAGS(mm) &&
55098+ (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
55099+ mmput(mm);
55100+ return 0;
55101+ }
55102+#endif
55103+
55104 do {
55105 nwords += 2;
55106 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
55107@@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
55108 }
55109
55110
55111-#ifdef CONFIG_KALLSYMS
55112+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55113 /*
55114 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
55115 * Returns the resolved symbol. If that fails, simply return the address.
55116@@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
55117 mutex_unlock(&task->signal->cred_guard_mutex);
55118 }
55119
55120-#ifdef CONFIG_STACKTRACE
55121+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55122
55123 #define MAX_STACK_TRACE_DEPTH 64
55124
55125@@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
55126 return count;
55127 }
55128
55129-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55130+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55131 static int proc_pid_syscall(struct task_struct *task, char *buffer)
55132 {
55133 long nr;
55134@@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
55135 /************************************************************************/
55136
55137 /* permission checks */
55138-static int proc_fd_access_allowed(struct inode *inode)
55139+static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
55140 {
55141 struct task_struct *task;
55142 int allowed = 0;
55143@@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
55144 */
55145 task = get_proc_task(inode);
55146 if (task) {
55147- allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55148+ if (log)
55149+ allowed = ptrace_may_access(task, PTRACE_MODE_READ);
55150+ else
55151+ allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
55152 put_task_struct(task);
55153 }
55154 return allowed;
55155@@ -556,10 +586,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
55156 struct task_struct *task,
55157 int hide_pid_min)
55158 {
55159+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55160+ return false;
55161+
55162+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55163+ rcu_read_lock();
55164+ {
55165+ const struct cred *tmpcred = current_cred();
55166+ const struct cred *cred = __task_cred(task);
55167+
55168+ if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
55169+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55170+ || in_group_p(grsec_proc_gid)
55171+#endif
55172+ ) {
55173+ rcu_read_unlock();
55174+ return true;
55175+ }
55176+ }
55177+ rcu_read_unlock();
55178+
55179+ if (!pid->hide_pid)
55180+ return false;
55181+#endif
55182+
55183 if (pid->hide_pid < hide_pid_min)
55184 return true;
55185 if (in_group_p(pid->pid_gid))
55186 return true;
55187+
55188 return ptrace_may_access(task, PTRACE_MODE_READ);
55189 }
55190
55191@@ -577,7 +632,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
55192 put_task_struct(task);
55193
55194 if (!has_perms) {
55195+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55196+ {
55197+#else
55198 if (pid->hide_pid == 2) {
55199+#endif
55200 /*
55201 * Let's make getdents(), stat(), and open()
55202 * consistent with each other. If a process
55203@@ -675,6 +734,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55204 if (!task)
55205 return -ESRCH;
55206
55207+ if (gr_acl_handle_procpidmem(task)) {
55208+ put_task_struct(task);
55209+ return -EPERM;
55210+ }
55211+
55212 mm = mm_access(task, mode);
55213 put_task_struct(task);
55214
55215@@ -690,6 +754,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
55216
55217 file->private_data = mm;
55218
55219+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55220+ file->f_version = current->exec_id;
55221+#endif
55222+
55223 return 0;
55224 }
55225
55226@@ -711,6 +779,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55227 ssize_t copied;
55228 char *page;
55229
55230+#ifdef CONFIG_GRKERNSEC
55231+ if (write)
55232+ return -EPERM;
55233+#endif
55234+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55235+ if (file->f_version != current->exec_id) {
55236+ gr_log_badprocpid("mem");
55237+ return 0;
55238+ }
55239+#endif
55240+
55241 if (!mm)
55242 return 0;
55243
55244@@ -723,7 +802,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
55245 goto free;
55246
55247 while (count > 0) {
55248- int this_len = min_t(int, count, PAGE_SIZE);
55249+ ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
55250
55251 if (write && copy_from_user(page, buf, this_len)) {
55252 copied = -EFAULT;
55253@@ -815,6 +894,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55254 if (!mm)
55255 return 0;
55256
55257+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55258+ if (file->f_version != current->exec_id) {
55259+ gr_log_badprocpid("environ");
55260+ return 0;
55261+ }
55262+#endif
55263+
55264 page = (char *)__get_free_page(GFP_TEMPORARY);
55265 if (!page)
55266 return -ENOMEM;
55267@@ -824,7 +910,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
55268 goto free;
55269 while (count > 0) {
55270 size_t this_len, max_len;
55271- int retval;
55272+ ssize_t retval;
55273
55274 if (src >= (mm->env_end - mm->env_start))
55275 break;
55276@@ -1430,7 +1516,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
55277 int error = -EACCES;
55278
55279 /* Are we allowed to snoop on the tasks file descriptors? */
55280- if (!proc_fd_access_allowed(inode))
55281+ if (!proc_fd_access_allowed(inode, 0))
55282 goto out;
55283
55284 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55285@@ -1474,8 +1560,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
55286 struct path path;
55287
55288 /* Are we allowed to snoop on the tasks file descriptors? */
55289- if (!proc_fd_access_allowed(inode))
55290- goto out;
55291+ /* logging this is needed for learning on chromium to work properly,
55292+ but we don't want to flood the logs from 'ps' which does a readlink
55293+ on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
55294+ CAP_SYS_PTRACE as it's not necessary for its basic functionality
55295+ */
55296+ if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
55297+ if (!proc_fd_access_allowed(inode,0))
55298+ goto out;
55299+ } else {
55300+ if (!proc_fd_access_allowed(inode,1))
55301+ goto out;
55302+ }
55303
55304 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
55305 if (error)
55306@@ -1525,7 +1621,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
55307 rcu_read_lock();
55308 cred = __task_cred(task);
55309 inode->i_uid = cred->euid;
55310+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55311+ inode->i_gid = grsec_proc_gid;
55312+#else
55313 inode->i_gid = cred->egid;
55314+#endif
55315 rcu_read_unlock();
55316 }
55317 security_task_to_inode(task, inode);
55318@@ -1561,10 +1661,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55319 return -ENOENT;
55320 }
55321 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55322+#ifdef CONFIG_GRKERNSEC_PROC_USER
55323+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55324+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55325+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55326+#endif
55327 task_dumpable(task)) {
55328 cred = __task_cred(task);
55329 stat->uid = cred->euid;
55330+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55331+ stat->gid = grsec_proc_gid;
55332+#else
55333 stat->gid = cred->egid;
55334+#endif
55335 }
55336 }
55337 rcu_read_unlock();
55338@@ -1602,11 +1711,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
55339
55340 if (task) {
55341 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
55342+#ifdef CONFIG_GRKERNSEC_PROC_USER
55343+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
55344+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55345+ (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
55346+#endif
55347 task_dumpable(task)) {
55348 rcu_read_lock();
55349 cred = __task_cred(task);
55350 inode->i_uid = cred->euid;
55351+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55352+ inode->i_gid = grsec_proc_gid;
55353+#else
55354 inode->i_gid = cred->egid;
55355+#endif
55356 rcu_read_unlock();
55357 } else {
55358 inode->i_uid = GLOBAL_ROOT_UID;
55359@@ -2059,6 +2177,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
55360 if (!task)
55361 goto out_no_task;
55362
55363+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55364+ goto out;
55365+
55366 /*
55367 * Yes, it does not scale. And it should not. Don't add
55368 * new entries into /proc/<tgid>/ without very good reasons.
55369@@ -2103,6 +2224,9 @@ static int proc_pident_readdir(struct file *filp,
55370 if (!task)
55371 goto out_no_task;
55372
55373+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55374+ goto out;
55375+
55376 ret = 0;
55377 i = filp->f_pos;
55378 switch (i) {
55379@@ -2516,7 +2640,7 @@ static const struct pid_entry tgid_base_stuff[] = {
55380 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
55381 #endif
55382 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55383-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55384+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55385 INF("syscall", S_IRUGO, proc_pid_syscall),
55386 #endif
55387 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55388@@ -2541,10 +2665,10 @@ static const struct pid_entry tgid_base_stuff[] = {
55389 #ifdef CONFIG_SECURITY
55390 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55391 #endif
55392-#ifdef CONFIG_KALLSYMS
55393+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55394 INF("wchan", S_IRUGO, proc_pid_wchan),
55395 #endif
55396-#ifdef CONFIG_STACKTRACE
55397+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55398 ONE("stack", S_IRUGO, proc_pid_stack),
55399 #endif
55400 #ifdef CONFIG_SCHEDSTATS
55401@@ -2578,6 +2702,9 @@ static const struct pid_entry tgid_base_stuff[] = {
55402 #ifdef CONFIG_HARDWALL
55403 INF("hardwall", S_IRUGO, proc_pid_hardwall),
55404 #endif
55405+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55406+ INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
55407+#endif
55408 #ifdef CONFIG_USER_NS
55409 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
55410 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
55411@@ -2707,7 +2834,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
55412 if (!inode)
55413 goto out;
55414
55415+#ifdef CONFIG_GRKERNSEC_PROC_USER
55416+ inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
55417+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55418+ inode->i_gid = grsec_proc_gid;
55419+ inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
55420+#else
55421 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
55422+#endif
55423 inode->i_op = &proc_tgid_base_inode_operations;
55424 inode->i_fop = &proc_tgid_base_operations;
55425 inode->i_flags|=S_IMMUTABLE;
55426@@ -2745,7 +2879,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
55427 if (!task)
55428 goto out;
55429
55430+ if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
55431+ goto out_put_task;
55432+
55433 result = proc_pid_instantiate(dir, dentry, task, NULL);
55434+out_put_task:
55435 put_task_struct(task);
55436 out:
55437 return result;
55438@@ -2808,6 +2946,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
55439 static int fake_filldir(void *buf, const char *name, int namelen,
55440 loff_t offset, u64 ino, unsigned d_type)
55441 {
55442+ struct getdents_callback * __buf = (struct getdents_callback *) buf;
55443+ __buf->error = -EINVAL;
55444 return 0;
55445 }
55446
55447@@ -2859,7 +2999,7 @@ static const struct pid_entry tid_base_stuff[] = {
55448 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
55449 #endif
55450 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
55451-#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
55452+#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
55453 INF("syscall", S_IRUGO, proc_pid_syscall),
55454 #endif
55455 INF("cmdline", S_IRUGO, proc_pid_cmdline),
55456@@ -2886,10 +3026,10 @@ static const struct pid_entry tid_base_stuff[] = {
55457 #ifdef CONFIG_SECURITY
55458 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
55459 #endif
55460-#ifdef CONFIG_KALLSYMS
55461+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55462 INF("wchan", S_IRUGO, proc_pid_wchan),
55463 #endif
55464-#ifdef CONFIG_STACKTRACE
55465+#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
55466 ONE("stack", S_IRUGO, proc_pid_stack),
55467 #endif
55468 #ifdef CONFIG_SCHEDSTATS
55469diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
55470index 82676e3..5f8518a 100644
55471--- a/fs/proc/cmdline.c
55472+++ b/fs/proc/cmdline.c
55473@@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
55474
55475 static int __init proc_cmdline_init(void)
55476 {
55477+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55478+ proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
55479+#else
55480 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
55481+#endif
55482 return 0;
55483 }
55484 module_init(proc_cmdline_init);
55485diff --git a/fs/proc/devices.c b/fs/proc/devices.c
55486index b143471..bb105e5 100644
55487--- a/fs/proc/devices.c
55488+++ b/fs/proc/devices.c
55489@@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
55490
55491 static int __init proc_devices_init(void)
55492 {
55493+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55494+ proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
55495+#else
55496 proc_create("devices", 0, NULL, &proc_devinfo_operations);
55497+#endif
55498 return 0;
55499 }
55500 module_init(proc_devices_init);
55501diff --git a/fs/proc/fd.c b/fs/proc/fd.c
55502index d7a4a28..0201742 100644
55503--- a/fs/proc/fd.c
55504+++ b/fs/proc/fd.c
55505@@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
55506 if (!task)
55507 return -ENOENT;
55508
55509- files = get_files_struct(task);
55510+ if (!gr_acl_handle_procpidmem(task))
55511+ files = get_files_struct(task);
55512 put_task_struct(task);
55513
55514 if (files) {
55515@@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
55516 */
55517 int proc_fd_permission(struct inode *inode, int mask)
55518 {
55519+ struct task_struct *task;
55520 int rv = generic_permission(inode, mask);
55521- if (rv == 0)
55522- return 0;
55523+
55524 if (task_pid(current) == proc_pid(inode))
55525 rv = 0;
55526+
55527+ task = get_proc_task(inode);
55528+ if (task == NULL)
55529+ return rv;
55530+
55531+ if (gr_acl_handle_procpidmem(task))
55532+ rv = -EACCES;
55533+
55534+ put_task_struct(task);
55535+
55536 return rv;
55537 }
55538
55539diff --git a/fs/proc/inode.c b/fs/proc/inode.c
55540index 869116c..820cb27 100644
55541--- a/fs/proc/inode.c
55542+++ b/fs/proc/inode.c
55543@@ -22,11 +22,17 @@
55544 #include <linux/seq_file.h>
55545 #include <linux/slab.h>
55546 #include <linux/mount.h>
55547+#include <linux/grsecurity.h>
55548
55549 #include <asm/uaccess.h>
55550
55551 #include "internal.h"
55552
55553+#ifdef CONFIG_PROC_SYSCTL
55554+extern const struct inode_operations proc_sys_inode_operations;
55555+extern const struct inode_operations proc_sys_dir_operations;
55556+#endif
55557+
55558 static void proc_evict_inode(struct inode *inode)
55559 {
55560 struct proc_dir_entry *de;
55561@@ -54,6 +60,13 @@ static void proc_evict_inode(struct inode *inode)
55562 ns = PROC_I(inode)->ns;
55563 if (ns_ops && ns)
55564 ns_ops->put(ns);
55565+
55566+#ifdef CONFIG_PROC_SYSCTL
55567+ if (inode->i_op == &proc_sys_inode_operations ||
55568+ inode->i_op == &proc_sys_dir_operations)
55569+ gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
55570+#endif
55571+
55572 }
55573
55574 static struct kmem_cache * proc_inode_cachep;
55575@@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
55576 if (de->mode) {
55577 inode->i_mode = de->mode;
55578 inode->i_uid = de->uid;
55579+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
55580+ inode->i_gid = grsec_proc_gid;
55581+#else
55582 inode->i_gid = de->gid;
55583+#endif
55584 }
55585 if (de->size)
55586 inode->i_size = de->size;
55587diff --git a/fs/proc/internal.h b/fs/proc/internal.h
55588index 85ff3a4..a512bd8 100644
55589--- a/fs/proc/internal.h
55590+++ b/fs/proc/internal.h
55591@@ -56,6 +56,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
55592 struct pid *pid, struct task_struct *task);
55593 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
55594 struct pid *pid, struct task_struct *task);
55595+#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
55596+extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
55597+#endif
55598 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
55599
55600 extern const struct file_operations proc_tid_children_operations;
55601diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
55602index eda6f01..006ae24 100644
55603--- a/fs/proc/kcore.c
55604+++ b/fs/proc/kcore.c
55605@@ -481,9 +481,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55606 * the addresses in the elf_phdr on our list.
55607 */
55608 start = kc_offset_to_vaddr(*fpos - elf_buflen);
55609- if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
55610+ tsz = PAGE_SIZE - (start & ~PAGE_MASK);
55611+ if (tsz > buflen)
55612 tsz = buflen;
55613-
55614+
55615 while (buflen) {
55616 struct kcore_list *m;
55617
55618@@ -512,20 +513,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55619 kfree(elf_buf);
55620 } else {
55621 if (kern_addr_valid(start)) {
55622- unsigned long n;
55623+ char *elf_buf;
55624+ mm_segment_t oldfs;
55625
55626- n = copy_to_user(buffer, (char *)start, tsz);
55627- /*
55628- * We cannot distinguish between fault on source
55629- * and fault on destination. When this happens
55630- * we clear too and hope it will trigger the
55631- * EFAULT again.
55632- */
55633- if (n) {
55634- if (clear_user(buffer + tsz - n,
55635- n))
55636+ elf_buf = kmalloc(tsz, GFP_KERNEL);
55637+ if (!elf_buf)
55638+ return -ENOMEM;
55639+ oldfs = get_fs();
55640+ set_fs(KERNEL_DS);
55641+ if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
55642+ set_fs(oldfs);
55643+ if (copy_to_user(buffer, elf_buf, tsz)) {
55644+ kfree(elf_buf);
55645 return -EFAULT;
55646+ }
55647 }
55648+ set_fs(oldfs);
55649+ kfree(elf_buf);
55650 } else {
55651 if (clear_user(buffer, tsz))
55652 return -EFAULT;
55653@@ -545,6 +549,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
55654
55655 static int open_kcore(struct inode *inode, struct file *filp)
55656 {
55657+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
55658+ return -EPERM;
55659+#endif
55660 if (!capable(CAP_SYS_RAWIO))
55661 return -EPERM;
55662 if (kcore_need_update)
55663diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
55664index 1efaaa1..834e49a 100644
55665--- a/fs/proc/meminfo.c
55666+++ b/fs/proc/meminfo.c
55667@@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
55668 vmi.used >> 10,
55669 vmi.largest_chunk >> 10
55670 #ifdef CONFIG_MEMORY_FAILURE
55671- ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55672+ ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
55673 #endif
55674 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
55675 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
55676diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
55677index ccfd99b..1b7e255 100644
55678--- a/fs/proc/nommu.c
55679+++ b/fs/proc/nommu.c
55680@@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
55681 if (len < 1)
55682 len = 1;
55683 seq_printf(m, "%*c", len, ' ');
55684- seq_path(m, &file->f_path, "");
55685+ seq_path(m, &file->f_path, "\n\\");
55686 }
55687
55688 seq_putc(m, '\n');
55689diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
55690index b4ac657..0842bd2 100644
55691--- a/fs/proc/proc_net.c
55692+++ b/fs/proc/proc_net.c
55693@@ -23,6 +23,7 @@
55694 #include <linux/nsproxy.h>
55695 #include <net/net_namespace.h>
55696 #include <linux/seq_file.h>
55697+#include <linux/grsecurity.h>
55698
55699 #include "internal.h"
55700
55701@@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
55702 struct task_struct *task;
55703 struct nsproxy *ns;
55704 struct net *net = NULL;
55705+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55706+ const struct cred *cred = current_cred();
55707+#endif
55708+
55709+#ifdef CONFIG_GRKERNSEC_PROC_USER
55710+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
55711+ return net;
55712+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55713+ if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
55714+ return net;
55715+#endif
55716
55717 rcu_read_lock();
55718 task = pid_task(proc_pid(dir), PIDTYPE_PID);
55719diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
55720index ac05f33..1e6dc7e 100644
55721--- a/fs/proc/proc_sysctl.c
55722+++ b/fs/proc/proc_sysctl.c
55723@@ -13,11 +13,15 @@
55724 #include <linux/module.h>
55725 #include "internal.h"
55726
55727+extern int gr_handle_chroot_sysctl(const int op);
55728+extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
55729+ const int op);
55730+
55731 static const struct dentry_operations proc_sys_dentry_operations;
55732 static const struct file_operations proc_sys_file_operations;
55733-static const struct inode_operations proc_sys_inode_operations;
55734+const struct inode_operations proc_sys_inode_operations;
55735 static const struct file_operations proc_sys_dir_file_operations;
55736-static const struct inode_operations proc_sys_dir_operations;
55737+const struct inode_operations proc_sys_dir_operations;
55738
55739 void proc_sys_poll_notify(struct ctl_table_poll *poll)
55740 {
55741@@ -467,6 +471,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
55742
55743 err = NULL;
55744 d_set_d_op(dentry, &proc_sys_dentry_operations);
55745+
55746+ gr_handle_proc_create(dentry, inode);
55747+
55748 d_add(dentry, inode);
55749
55750 out:
55751@@ -482,6 +489,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55752 struct inode *inode = file_inode(filp);
55753 struct ctl_table_header *head = grab_header(inode);
55754 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
55755+ int op = write ? MAY_WRITE : MAY_READ;
55756 ssize_t error;
55757 size_t res;
55758
55759@@ -493,7 +501,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55760 * and won't be until we finish.
55761 */
55762 error = -EPERM;
55763- if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
55764+ if (sysctl_perm(head, table, op))
55765 goto out;
55766
55767 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
55768@@ -501,6 +509,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
55769 if (!table->proc_handler)
55770 goto out;
55771
55772+#ifdef CONFIG_GRKERNSEC
55773+ error = -EPERM;
55774+ if (gr_handle_chroot_sysctl(op))
55775+ goto out;
55776+ dget(filp->f_path.dentry);
55777+ if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
55778+ dput(filp->f_path.dentry);
55779+ goto out;
55780+ }
55781+ dput(filp->f_path.dentry);
55782+ if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
55783+ goto out;
55784+ if (write && !capable(CAP_SYS_ADMIN))
55785+ goto out;
55786+#endif
55787+
55788 /* careful: calling conventions are nasty here */
55789 res = count;
55790 error = table->proc_handler(table, write, buf, &res, ppos);
55791@@ -598,6 +622,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
55792 return -ENOMEM;
55793 } else {
55794 d_set_d_op(child, &proc_sys_dentry_operations);
55795+
55796+ gr_handle_proc_create(child, inode);
55797+
55798 d_add(child, inode);
55799 }
55800 } else {
55801@@ -641,6 +668,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
55802 if ((*pos)++ < file->f_pos)
55803 return 0;
55804
55805+ if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
55806+ return 0;
55807+
55808 if (unlikely(S_ISLNK(table->mode)))
55809 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
55810 else
55811@@ -751,6 +781,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
55812 if (IS_ERR(head))
55813 return PTR_ERR(head);
55814
55815+ if (table && !gr_acl_handle_hidden_file(dentry, mnt))
55816+ return -ENOENT;
55817+
55818 generic_fillattr(inode, stat);
55819 if (table)
55820 stat->mode = (stat->mode & S_IFMT) | table->mode;
55821@@ -773,13 +806,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
55822 .llseek = generic_file_llseek,
55823 };
55824
55825-static const struct inode_operations proc_sys_inode_operations = {
55826+const struct inode_operations proc_sys_inode_operations = {
55827 .permission = proc_sys_permission,
55828 .setattr = proc_sys_setattr,
55829 .getattr = proc_sys_getattr,
55830 };
55831
55832-static const struct inode_operations proc_sys_dir_operations = {
55833+const struct inode_operations proc_sys_dir_operations = {
55834 .lookup = proc_sys_lookup,
55835 .permission = proc_sys_permission,
55836 .setattr = proc_sys_setattr,
55837@@ -855,7 +888,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
55838 static struct ctl_dir *new_dir(struct ctl_table_set *set,
55839 const char *name, int namelen)
55840 {
55841- struct ctl_table *table;
55842+ ctl_table_no_const *table;
55843 struct ctl_dir *new;
55844 struct ctl_node *node;
55845 char *new_name;
55846@@ -867,7 +900,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
55847 return NULL;
55848
55849 node = (struct ctl_node *)(new + 1);
55850- table = (struct ctl_table *)(node + 1);
55851+ table = (ctl_table_no_const *)(node + 1);
55852 new_name = (char *)(table + 2);
55853 memcpy(new_name, name, namelen);
55854 new_name[namelen] = '\0';
55855@@ -1036,7 +1069,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
55856 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
55857 struct ctl_table_root *link_root)
55858 {
55859- struct ctl_table *link_table, *entry, *link;
55860+ ctl_table_no_const *link_table, *link;
55861+ struct ctl_table *entry;
55862 struct ctl_table_header *links;
55863 struct ctl_node *node;
55864 char *link_name;
55865@@ -1059,7 +1093,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
55866 return NULL;
55867
55868 node = (struct ctl_node *)(links + 1);
55869- link_table = (struct ctl_table *)(node + nr_entries);
55870+ link_table = (ctl_table_no_const *)(node + nr_entries);
55871 link_name = (char *)&link_table[nr_entries + 1];
55872
55873 for (link = link_table, entry = table; entry->procname; link++, entry++) {
55874@@ -1307,8 +1341,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55875 struct ctl_table_header ***subheader, struct ctl_table_set *set,
55876 struct ctl_table *table)
55877 {
55878- struct ctl_table *ctl_table_arg = NULL;
55879- struct ctl_table *entry, *files;
55880+ ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
55881+ struct ctl_table *entry;
55882 int nr_files = 0;
55883 int nr_dirs = 0;
55884 int err = -ENOMEM;
55885@@ -1320,10 +1354,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55886 nr_files++;
55887 }
55888
55889- files = table;
55890 /* If there are mixed files and directories we need a new table */
55891 if (nr_dirs && nr_files) {
55892- struct ctl_table *new;
55893+ ctl_table_no_const *new;
55894 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
55895 GFP_KERNEL);
55896 if (!files)
55897@@ -1341,7 +1374,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
55898 /* Register everything except a directory full of subdirectories */
55899 if (nr_files || !nr_dirs) {
55900 struct ctl_table_header *header;
55901- header = __register_sysctl_table(set, path, files);
55902+ header = __register_sysctl_table(set, path, files ? files : table);
55903 if (!header) {
55904 kfree(ctl_table_arg);
55905 goto out;
55906diff --git a/fs/proc/root.c b/fs/proc/root.c
55907index 9c7fab1..ed1c8e0 100644
55908--- a/fs/proc/root.c
55909+++ b/fs/proc/root.c
55910@@ -180,7 +180,15 @@ void __init proc_root_init(void)
55911 #ifdef CONFIG_PROC_DEVICETREE
55912 proc_device_tree_init();
55913 #endif
55914+#ifdef CONFIG_GRKERNSEC_PROC_ADD
55915+#ifdef CONFIG_GRKERNSEC_PROC_USER
55916+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
55917+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55918+ proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
55919+#endif
55920+#else
55921 proc_mkdir("bus", NULL);
55922+#endif
55923 proc_sys_init();
55924 }
55925
55926diff --git a/fs/proc/self.c b/fs/proc/self.c
55927index aa5cc3b..c91a5d0 100644
55928--- a/fs/proc/self.c
55929+++ b/fs/proc/self.c
55930@@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
55931 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
55932 void *cookie)
55933 {
55934- char *s = nd_get_link(nd);
55935+ const char *s = nd_get_link(nd);
55936 if (!IS_ERR(s))
55937 kfree(s);
55938 }
55939diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
55940index 3e636d8..83e3b71 100644
55941--- a/fs/proc/task_mmu.c
55942+++ b/fs/proc/task_mmu.c
55943@@ -11,12 +11,19 @@
55944 #include <linux/rmap.h>
55945 #include <linux/swap.h>
55946 #include <linux/swapops.h>
55947+#include <linux/grsecurity.h>
55948
55949 #include <asm/elf.h>
55950 #include <asm/uaccess.h>
55951 #include <asm/tlbflush.h>
55952 #include "internal.h"
55953
55954+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55955+#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
55956+ (_mm->pax_flags & MF_PAX_RANDMMAP || \
55957+ _mm->pax_flags & MF_PAX_SEGMEXEC))
55958+#endif
55959+
55960 void task_mem(struct seq_file *m, struct mm_struct *mm)
55961 {
55962 unsigned long data, text, lib, swap;
55963@@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55964 "VmExe:\t%8lu kB\n"
55965 "VmLib:\t%8lu kB\n"
55966 "VmPTE:\t%8lu kB\n"
55967- "VmSwap:\t%8lu kB\n",
55968- hiwater_vm << (PAGE_SHIFT-10),
55969+ "VmSwap:\t%8lu kB\n"
55970+
55971+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55972+ "CsBase:\t%8lx\nCsLim:\t%8lx\n"
55973+#endif
55974+
55975+ ,hiwater_vm << (PAGE_SHIFT-10),
55976 total_vm << (PAGE_SHIFT-10),
55977 mm->locked_vm << (PAGE_SHIFT-10),
55978 mm->pinned_vm << (PAGE_SHIFT-10),
55979@@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
55980 data << (PAGE_SHIFT-10),
55981 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
55982 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
55983- swap << (PAGE_SHIFT-10));
55984+ swap << (PAGE_SHIFT-10)
55985+
55986+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55987+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55988+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
55989+ , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
55990+#else
55991+ , mm->context.user_cs_base
55992+ , mm->context.user_cs_limit
55993+#endif
55994+#endif
55995+
55996+ );
55997 }
55998
55999 unsigned long task_vsize(struct mm_struct *mm)
56000@@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56001 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
56002 }
56003
56004- /* We don't show the stack guard page in /proc/maps */
56005+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56006+ start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
56007+ end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
56008+#else
56009 start = vma->vm_start;
56010- if (stack_guard_page_start(vma, start))
56011- start += PAGE_SIZE;
56012 end = vma->vm_end;
56013- if (stack_guard_page_end(vma, end))
56014- end -= PAGE_SIZE;
56015+#endif
56016
56017 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
56018 start,
56019@@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56020 flags & VM_WRITE ? 'w' : '-',
56021 flags & VM_EXEC ? 'x' : '-',
56022 flags & VM_MAYSHARE ? 's' : 'p',
56023+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56024+ PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
56025+#else
56026 pgoff,
56027+#endif
56028 MAJOR(dev), MINOR(dev), ino, &len);
56029
56030 /*
56031@@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56032 */
56033 if (file) {
56034 pad_len_spaces(m, len);
56035- seq_path(m, &file->f_path, "\n");
56036+ seq_path(m, &file->f_path, "\n\\");
56037 goto done;
56038 }
56039
56040@@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
56041 * Thread stack in /proc/PID/task/TID/maps or
56042 * the main process stack.
56043 */
56044- if (!is_pid || (vma->vm_start <= mm->start_stack &&
56045- vma->vm_end >= mm->start_stack)) {
56046+ if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
56047+ (vma->vm_start <= mm->start_stack &&
56048+ vma->vm_end >= mm->start_stack)) {
56049 name = "[stack]";
56050 } else {
56051 /* Thread stack in /proc/PID/maps */
56052@@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
56053 struct proc_maps_private *priv = m->private;
56054 struct task_struct *task = priv->task;
56055
56056+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56057+ if (current->exec_id != m->exec_id) {
56058+ gr_log_badprocpid("maps");
56059+ return 0;
56060+ }
56061+#endif
56062+
56063 show_map_vma(m, vma, is_pid);
56064
56065 if (m->count < m->size) /* vma is copied successfully */
56066@@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56067 .private = &mss,
56068 };
56069
56070+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56071+ if (current->exec_id != m->exec_id) {
56072+ gr_log_badprocpid("smaps");
56073+ return 0;
56074+ }
56075+#endif
56076 memset(&mss, 0, sizeof mss);
56077- mss.vma = vma;
56078- /* mmap_sem is held in m_start */
56079- if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56080- walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56081-
56082+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56083+ if (!PAX_RAND_FLAGS(vma->vm_mm)) {
56084+#endif
56085+ mss.vma = vma;
56086+ /* mmap_sem is held in m_start */
56087+ if (vma->vm_mm && !is_vm_hugetlb_page(vma))
56088+ walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
56089+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56090+ }
56091+#endif
56092 show_map_vma(m, vma, is_pid);
56093
56094 seq_printf(m,
56095@@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
56096 "KernelPageSize: %8lu kB\n"
56097 "MMUPageSize: %8lu kB\n"
56098 "Locked: %8lu kB\n",
56099+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56100+ PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
56101+#else
56102 (vma->vm_end - vma->vm_start) >> 10,
56103+#endif
56104 mss.resident >> 10,
56105 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
56106 mss.shared_clean >> 10,
56107@@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56108 int n;
56109 char buffer[50];
56110
56111+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56112+ if (current->exec_id != m->exec_id) {
56113+ gr_log_badprocpid("numa_maps");
56114+ return 0;
56115+ }
56116+#endif
56117+
56118 if (!mm)
56119 return 0;
56120
56121@@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
56122 mpol_to_str(buffer, sizeof(buffer), pol);
56123 mpol_cond_put(pol);
56124
56125+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56126+ seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
56127+#else
56128 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
56129+#endif
56130
56131 if (file) {
56132 seq_printf(m, " file=");
56133- seq_path(m, &file->f_path, "\n\t= ");
56134+ seq_path(m, &file->f_path, "\n\t\\= ");
56135 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
56136 seq_printf(m, " heap");
56137 } else {
56138diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
56139index 56123a6..5a2f6ec 100644
56140--- a/fs/proc/task_nommu.c
56141+++ b/fs/proc/task_nommu.c
56142@@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
56143 else
56144 bytes += kobjsize(mm);
56145
56146- if (current->fs && current->fs->users > 1)
56147+ if (current->fs && atomic_read(&current->fs->users) > 1)
56148 sbytes += kobjsize(current->fs);
56149 else
56150 bytes += kobjsize(current->fs);
56151@@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
56152
56153 if (file) {
56154 pad_len_spaces(m, len);
56155- seq_path(m, &file->f_path, "");
56156+ seq_path(m, &file->f_path, "\n\\");
56157 } else if (mm) {
56158 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
56159
56160diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
56161index b870f74..e9048df 100644
56162--- a/fs/proc/vmcore.c
56163+++ b/fs/proc/vmcore.c
56164@@ -98,9 +98,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
56165 nr_bytes = count;
56166
56167 /* If pfn is not ram, return zeros for sparse dump files */
56168- if (pfn_is_ram(pfn) == 0)
56169- memset(buf, 0, nr_bytes);
56170- else {
56171+ if (pfn_is_ram(pfn) == 0) {
56172+ if (userbuf) {
56173+ if (clear_user((char __force_user *)buf, nr_bytes))
56174+ return -EFAULT;
56175+ } else
56176+ memset(buf, 0, nr_bytes);
56177+ } else {
56178 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
56179 offset, userbuf);
56180 if (tmp < 0)
56181@@ -185,7 +189,7 @@ static ssize_t read_vmcore(struct file *file, char __user *buffer,
56182 if (tsz > nr_bytes)
56183 tsz = nr_bytes;
56184
56185- tmp = read_from_oldmem(buffer, tsz, &start, 1);
56186+ tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, 1);
56187 if (tmp < 0)
56188 return tmp;
56189 buflen -= tsz;
56190diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
56191index b00fcc9..e0c6381 100644
56192--- a/fs/qnx6/qnx6.h
56193+++ b/fs/qnx6/qnx6.h
56194@@ -74,7 +74,7 @@ enum {
56195 BYTESEX_BE,
56196 };
56197
56198-static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56199+static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
56200 {
56201 if (sbi->s_bytesex == BYTESEX_LE)
56202 return le64_to_cpu((__force __le64)n);
56203@@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
56204 return (__force __fs64)cpu_to_be64(n);
56205 }
56206
56207-static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56208+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
56209 {
56210 if (sbi->s_bytesex == BYTESEX_LE)
56211 return le32_to_cpu((__force __le32)n);
56212diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
56213index 16e8abb..2dcf914 100644
56214--- a/fs/quota/netlink.c
56215+++ b/fs/quota/netlink.c
56216@@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
56217 void quota_send_warning(struct kqid qid, dev_t dev,
56218 const char warntype)
56219 {
56220- static atomic_t seq;
56221+ static atomic_unchecked_t seq;
56222 struct sk_buff *skb;
56223 void *msg_head;
56224 int ret;
56225@@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
56226 "VFS: Not enough memory to send quota warning.\n");
56227 return;
56228 }
56229- msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
56230+ msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
56231 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
56232 if (!msg_head) {
56233 printk(KERN_ERR
56234diff --git a/fs/read_write.c b/fs/read_write.c
56235index e6ddc8d..9155227 100644
56236--- a/fs/read_write.c
56237+++ b/fs/read_write.c
56238@@ -429,7 +429,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
56239
56240 old_fs = get_fs();
56241 set_fs(get_ds());
56242- p = (__force const char __user *)buf;
56243+ p = (const char __force_user *)buf;
56244 if (count > MAX_RW_COUNT)
56245 count = MAX_RW_COUNT;
56246 if (file->f_op->write)
56247diff --git a/fs/readdir.c b/fs/readdir.c
56248index fee38e0..12fdf47 100644
56249--- a/fs/readdir.c
56250+++ b/fs/readdir.c
56251@@ -17,6 +17,7 @@
56252 #include <linux/security.h>
56253 #include <linux/syscalls.h>
56254 #include <linux/unistd.h>
56255+#include <linux/namei.h>
56256
56257 #include <asm/uaccess.h>
56258
56259@@ -67,6 +68,7 @@ struct old_linux_dirent {
56260
56261 struct readdir_callback {
56262 struct old_linux_dirent __user * dirent;
56263+ struct file * file;
56264 int result;
56265 };
56266
56267@@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
56268 buf->result = -EOVERFLOW;
56269 return -EOVERFLOW;
56270 }
56271+
56272+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56273+ return 0;
56274+
56275 buf->result++;
56276 dirent = buf->dirent;
56277 if (!access_ok(VERIFY_WRITE, dirent,
56278@@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
56279
56280 buf.result = 0;
56281 buf.dirent = dirent;
56282+ buf.file = f.file;
56283
56284 error = vfs_readdir(f.file, fillonedir, &buf);
56285 if (buf.result)
56286@@ -139,6 +146,7 @@ struct linux_dirent {
56287 struct getdents_callback {
56288 struct linux_dirent __user * current_dir;
56289 struct linux_dirent __user * previous;
56290+ struct file * file;
56291 int count;
56292 int error;
56293 };
56294@@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
56295 buf->error = -EOVERFLOW;
56296 return -EOVERFLOW;
56297 }
56298+
56299+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56300+ return 0;
56301+
56302 dirent = buf->previous;
56303 if (dirent) {
56304 if (__put_user(offset, &dirent->d_off))
56305@@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56306 buf.previous = NULL;
56307 buf.count = count;
56308 buf.error = 0;
56309+ buf.file = f.file;
56310
56311 error = vfs_readdir(f.file, filldir, &buf);
56312 if (error >= 0)
56313@@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
56314 struct getdents_callback64 {
56315 struct linux_dirent64 __user * current_dir;
56316 struct linux_dirent64 __user * previous;
56317+ struct file *file;
56318 int count;
56319 int error;
56320 };
56321@@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
56322 buf->error = -EINVAL; /* only used if we fail.. */
56323 if (reclen > buf->count)
56324 return -EINVAL;
56325+
56326+ if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
56327+ return 0;
56328+
56329 dirent = buf->previous;
56330 if (dirent) {
56331 if (__put_user(offset, &dirent->d_off))
56332@@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56333
56334 buf.current_dir = dirent;
56335 buf.previous = NULL;
56336+ buf.file = f.file;
56337 buf.count = count;
56338 buf.error = 0;
56339
56340@@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
56341 error = buf.error;
56342 lastdirent = buf.previous;
56343 if (lastdirent) {
56344- typeof(lastdirent->d_off) d_off = f.file->f_pos;
56345+ typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
56346 if (__put_user(d_off, &lastdirent->d_off))
56347 error = -EFAULT;
56348 else
56349diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
56350index 2b7882b..1c5ef48 100644
56351--- a/fs/reiserfs/do_balan.c
56352+++ b/fs/reiserfs/do_balan.c
56353@@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
56354 return;
56355 }
56356
56357- atomic_inc(&(fs_generation(tb->tb_sb)));
56358+ atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
56359 do_balance_starts(tb);
56360
56361 /* balance leaf returns 0 except if combining L R and S into
56362diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
56363index 9cc0740a..46bf953 100644
56364--- a/fs/reiserfs/procfs.c
56365+++ b/fs/reiserfs/procfs.c
56366@@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
56367 "SMALL_TAILS " : "NO_TAILS ",
56368 replay_only(sb) ? "REPLAY_ONLY " : "",
56369 convert_reiserfs(sb) ? "CONV " : "",
56370- atomic_read(&r->s_generation_counter),
56371+ atomic_read_unchecked(&r->s_generation_counter),
56372 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
56373 SF(s_do_balance), SF(s_unneeded_left_neighbor),
56374 SF(s_good_search_by_key_reada), SF(s_bmaps),
56375diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
56376index 157e474..65a6114 100644
56377--- a/fs/reiserfs/reiserfs.h
56378+++ b/fs/reiserfs/reiserfs.h
56379@@ -453,7 +453,7 @@ struct reiserfs_sb_info {
56380 /* Comment? -Hans */
56381 wait_queue_head_t s_wait;
56382 /* To be obsoleted soon by per buffer seals.. -Hans */
56383- atomic_t s_generation_counter; // increased by one every time the
56384+ atomic_unchecked_t s_generation_counter; // increased by one every time the
56385 // tree gets re-balanced
56386 unsigned long s_properties; /* File system properties. Currently holds
56387 on-disk FS format */
56388@@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
56389 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
56390
56391 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
56392-#define get_generation(s) atomic_read (&fs_generation(s))
56393+#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
56394 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
56395 #define __fs_changed(gen,s) (gen != get_generation (s))
56396 #define fs_changed(gen,s) \
56397diff --git a/fs/select.c b/fs/select.c
56398index 8c1c96c..a0f9b6d 100644
56399--- a/fs/select.c
56400+++ b/fs/select.c
56401@@ -20,6 +20,7 @@
56402 #include <linux/export.h>
56403 #include <linux/slab.h>
56404 #include <linux/poll.h>
56405+#include <linux/security.h>
56406 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
56407 #include <linux/file.h>
56408 #include <linux/fdtable.h>
56409@@ -827,6 +828,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
56410 struct poll_list *walk = head;
56411 unsigned long todo = nfds;
56412
56413+ gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
56414 if (nfds > rlimit(RLIMIT_NOFILE))
56415 return -EINVAL;
56416
56417diff --git a/fs/seq_file.c b/fs/seq_file.c
56418index 38bb59f..a304f9d 100644
56419--- a/fs/seq_file.c
56420+++ b/fs/seq_file.c
56421@@ -10,6 +10,7 @@
56422 #include <linux/seq_file.h>
56423 #include <linux/slab.h>
56424 #include <linux/cred.h>
56425+#include <linux/sched.h>
56426
56427 #include <asm/uaccess.h>
56428 #include <asm/page.h>
56429@@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
56430 #ifdef CONFIG_USER_NS
56431 p->user_ns = file->f_cred->user_ns;
56432 #endif
56433+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
56434+ p->exec_id = current->exec_id;
56435+#endif
56436
56437 /*
56438 * Wrappers around seq_open(e.g. swaps_open) need to be
56439@@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56440 return 0;
56441 }
56442 if (!m->buf) {
56443- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56444+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56445 if (!m->buf)
56446 return -ENOMEM;
56447 }
56448@@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
56449 Eoverflow:
56450 m->op->stop(m, p);
56451 kfree(m->buf);
56452- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56453+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56454 return !m->buf ? -ENOMEM : -EAGAIN;
56455 }
56456
56457@@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56458
56459 /* grab buffer if we didn't have one */
56460 if (!m->buf) {
56461- m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
56462+ m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
56463 if (!m->buf)
56464 goto Enomem;
56465 }
56466@@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
56467 goto Fill;
56468 m->op->stop(m, p);
56469 kfree(m->buf);
56470- m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
56471+ m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
56472 if (!m->buf)
56473 goto Enomem;
56474 m->count = 0;
56475@@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
56476 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
56477 void *data)
56478 {
56479- struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
56480+ seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
56481 int res = -ENOMEM;
56482
56483 if (op) {
56484diff --git a/fs/splice.c b/fs/splice.c
56485index 29e394e..b13c247 100644
56486--- a/fs/splice.c
56487+++ b/fs/splice.c
56488@@ -195,7 +195,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56489 pipe_lock(pipe);
56490
56491 for (;;) {
56492- if (!pipe->readers) {
56493+ if (!atomic_read(&pipe->readers)) {
56494 send_sig(SIGPIPE, current, 0);
56495 if (!ret)
56496 ret = -EPIPE;
56497@@ -249,9 +249,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
56498 do_wakeup = 0;
56499 }
56500
56501- pipe->waiting_writers++;
56502+ atomic_inc(&pipe->waiting_writers);
56503 pipe_wait(pipe);
56504- pipe->waiting_writers--;
56505+ atomic_dec(&pipe->waiting_writers);
56506 }
56507
56508 pipe_unlock(pipe);
56509@@ -564,7 +564,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
56510 old_fs = get_fs();
56511 set_fs(get_ds());
56512 /* The cast to a user pointer is valid due to the set_fs() */
56513- res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
56514+ res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
56515 set_fs(old_fs);
56516
56517 return res;
56518@@ -579,7 +579,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
56519 old_fs = get_fs();
56520 set_fs(get_ds());
56521 /* The cast to a user pointer is valid due to the set_fs() */
56522- res = vfs_write(file, (__force const char __user *)buf, count, &pos);
56523+ res = vfs_write(file, (const char __force_user *)buf, count, &pos);
56524 set_fs(old_fs);
56525
56526 return res;
56527@@ -632,7 +632,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
56528 goto err;
56529
56530 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
56531- vec[i].iov_base = (void __user *) page_address(page);
56532+ vec[i].iov_base = (void __force_user *) page_address(page);
56533 vec[i].iov_len = this_len;
56534 spd.pages[i] = page;
56535 spd.nr_pages++;
56536@@ -853,10 +853,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
56537 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
56538 {
56539 while (!pipe->nrbufs) {
56540- if (!pipe->writers)
56541+ if (!atomic_read(&pipe->writers))
56542 return 0;
56543
56544- if (!pipe->waiting_writers && sd->num_spliced)
56545+ if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
56546 return 0;
56547
56548 if (sd->flags & SPLICE_F_NONBLOCK)
56549@@ -1192,7 +1192,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
56550 * out of the pipe right after the splice_to_pipe(). So set
56551 * PIPE_READERS appropriately.
56552 */
56553- pipe->readers = 1;
56554+ atomic_set(&pipe->readers, 1);
56555
56556 current->splice_pipe = pipe;
56557 }
56558@@ -1741,9 +1741,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56559 ret = -ERESTARTSYS;
56560 break;
56561 }
56562- if (!pipe->writers)
56563+ if (!atomic_read(&pipe->writers))
56564 break;
56565- if (!pipe->waiting_writers) {
56566+ if (!atomic_read(&pipe->waiting_writers)) {
56567 if (flags & SPLICE_F_NONBLOCK) {
56568 ret = -EAGAIN;
56569 break;
56570@@ -1775,7 +1775,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56571 pipe_lock(pipe);
56572
56573 while (pipe->nrbufs >= pipe->buffers) {
56574- if (!pipe->readers) {
56575+ if (!atomic_read(&pipe->readers)) {
56576 send_sig(SIGPIPE, current, 0);
56577 ret = -EPIPE;
56578 break;
56579@@ -1788,9 +1788,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
56580 ret = -ERESTARTSYS;
56581 break;
56582 }
56583- pipe->waiting_writers++;
56584+ atomic_inc(&pipe->waiting_writers);
56585 pipe_wait(pipe);
56586- pipe->waiting_writers--;
56587+ atomic_dec(&pipe->waiting_writers);
56588 }
56589
56590 pipe_unlock(pipe);
56591@@ -1826,14 +1826,14 @@ retry:
56592 pipe_double_lock(ipipe, opipe);
56593
56594 do {
56595- if (!opipe->readers) {
56596+ if (!atomic_read(&opipe->readers)) {
56597 send_sig(SIGPIPE, current, 0);
56598 if (!ret)
56599 ret = -EPIPE;
56600 break;
56601 }
56602
56603- if (!ipipe->nrbufs && !ipipe->writers)
56604+ if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
56605 break;
56606
56607 /*
56608@@ -1930,7 +1930,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56609 pipe_double_lock(ipipe, opipe);
56610
56611 do {
56612- if (!opipe->readers) {
56613+ if (!atomic_read(&opipe->readers)) {
56614 send_sig(SIGPIPE, current, 0);
56615 if (!ret)
56616 ret = -EPIPE;
56617@@ -1975,7 +1975,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
56618 * return EAGAIN if we have the potential of some data in the
56619 * future, otherwise just return 0
56620 */
56621- if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
56622+ if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
56623 ret = -EAGAIN;
56624
56625 pipe_unlock(ipipe);
56626diff --git a/fs/stat.c b/fs/stat.c
56627index 04ce1ac..a13dd1e 100644
56628--- a/fs/stat.c
56629+++ b/fs/stat.c
56630@@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
56631 stat->gid = inode->i_gid;
56632 stat->rdev = inode->i_rdev;
56633 stat->size = i_size_read(inode);
56634- stat->atime = inode->i_atime;
56635- stat->mtime = inode->i_mtime;
56636+ if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56637+ stat->atime = inode->i_ctime;
56638+ stat->mtime = inode->i_ctime;
56639+ } else {
56640+ stat->atime = inode->i_atime;
56641+ stat->mtime = inode->i_mtime;
56642+ }
56643 stat->ctime = inode->i_ctime;
56644 stat->blksize = (1 << inode->i_blkbits);
56645 stat->blocks = inode->i_blocks;
56646@@ -46,8 +51,14 @@ int vfs_getattr(struct path *path, struct kstat *stat)
56647 if (retval)
56648 return retval;
56649
56650- if (inode->i_op->getattr)
56651- return inode->i_op->getattr(path->mnt, path->dentry, stat);
56652+ if (inode->i_op->getattr) {
56653+ retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
56654+ if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
56655+ stat->atime = stat->ctime;
56656+ stat->mtime = stat->ctime;
56657+ }
56658+ return retval;
56659+ }
56660
56661 generic_fillattr(inode, stat);
56662 return 0;
56663diff --git a/fs/sysfs/bin.c b/fs/sysfs/bin.c
56664index 15c68f9..36a8b3e 100644
56665--- a/fs/sysfs/bin.c
56666+++ b/fs/sysfs/bin.c
56667@@ -235,13 +235,13 @@ static int bin_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
56668 return ret;
56669 }
56670
56671-static int bin_access(struct vm_area_struct *vma, unsigned long addr,
56672- void *buf, int len, int write)
56673+static ssize_t bin_access(struct vm_area_struct *vma, unsigned long addr,
56674+ void *buf, size_t len, int write)
56675 {
56676 struct file *file = vma->vm_file;
56677 struct bin_buffer *bb = file->private_data;
56678 struct sysfs_dirent *attr_sd = file->f_path.dentry->d_fsdata;
56679- int ret;
56680+ ssize_t ret;
56681
56682 if (!bb->vm_ops)
56683 return -EINVAL;
56684diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
56685index 6f31590..3c87c8a 100644
56686--- a/fs/sysfs/dir.c
56687+++ b/fs/sysfs/dir.c
56688@@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
56689 *
56690 * Returns 31 bit hash of ns + name (so it fits in an off_t )
56691 */
56692-static unsigned int sysfs_name_hash(const void *ns, const char *name)
56693+static unsigned int sysfs_name_hash(const void *ns, const unsigned char *name)
56694 {
56695 unsigned long hash = init_name_hash();
56696 unsigned int len = strlen(name);
56697@@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
56698 struct sysfs_dirent *sd;
56699 int rc;
56700
56701+#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
56702+ const char *parent_name = parent_sd->s_name;
56703+
56704+ mode = S_IFDIR | S_IRWXU;
56705+
56706+ if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
56707+ (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
56708+ (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
56709+ (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
56710+ mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
56711+#endif
56712+
56713 /* allocate */
56714 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
56715 if (!sd)
56716diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
56717index 602f56d..6853db8 100644
56718--- a/fs/sysfs/file.c
56719+++ b/fs/sysfs/file.c
56720@@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
56721
56722 struct sysfs_open_dirent {
56723 atomic_t refcnt;
56724- atomic_t event;
56725+ atomic_unchecked_t event;
56726 wait_queue_head_t poll;
56727 struct list_head buffers; /* goes through sysfs_buffer.list */
56728 };
56729@@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
56730 if (!sysfs_get_active(attr_sd))
56731 return -ENODEV;
56732
56733- buffer->event = atomic_read(&attr_sd->s_attr.open->event);
56734+ buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
56735 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
56736
56737 sysfs_put_active(attr_sd);
56738@@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
56739 return -ENOMEM;
56740
56741 atomic_set(&new_od->refcnt, 0);
56742- atomic_set(&new_od->event, 1);
56743+ atomic_set_unchecked(&new_od->event, 1);
56744 init_waitqueue_head(&new_od->poll);
56745 INIT_LIST_HEAD(&new_od->buffers);
56746 goto retry;
56747@@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
56748
56749 sysfs_put_active(attr_sd);
56750
56751- if (buffer->event != atomic_read(&od->event))
56752+ if (buffer->event != atomic_read_unchecked(&od->event))
56753 goto trigger;
56754
56755 return DEFAULT_POLLMASK;
56756@@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
56757
56758 od = sd->s_attr.open;
56759 if (od) {
56760- atomic_inc(&od->event);
56761+ atomic_inc_unchecked(&od->event);
56762 wake_up_interruptible(&od->poll);
56763 }
56764
56765diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
56766index 8c940df..25b733e 100644
56767--- a/fs/sysfs/symlink.c
56768+++ b/fs/sysfs/symlink.c
56769@@ -305,7 +305,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56770
56771 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
56772 {
56773- char *page = nd_get_link(nd);
56774+ const char *page = nd_get_link(nd);
56775 if (!IS_ERR(page))
56776 free_page((unsigned long)page);
56777 }
56778diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
56779index 69d4889..a810bd4 100644
56780--- a/fs/sysv/sysv.h
56781+++ b/fs/sysv/sysv.h
56782@@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
56783 #endif
56784 }
56785
56786-static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56787+static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
56788 {
56789 if (sbi->s_bytesex == BYTESEX_PDP)
56790 return PDP_swab((__force __u32)n);
56791diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c
56792index de08c92f..732cd63 100644
56793--- a/fs/ubifs/dir.c
56794+++ b/fs/ubifs/dir.c
56795@@ -364,6 +364,24 @@ static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
56796 */
56797 return 0;
56798
56799+ if (file->f_version == 0) {
56800+ /*
56801+ * The file was seek'ed, which means that @file->private_data
56802+ * is now invalid. This may also be just the first
56803+ * 'ubifs_readdir()' invocation, in which case
56804+ * @file->private_data is NULL, and the below code is
56805+ * basically a no-op.
56806+ */
56807+ kfree(file->private_data);
56808+ file->private_data = NULL;
56809+ }
56810+
56811+ /*
56812+ * 'generic_file_llseek()' unconditionally sets @file->f_version to
56813+ * zero, and we use this for detecting whether the file was seek'ed.
56814+ */
56815+ file->f_version = 1;
56816+
56817 /* File positions 0 and 1 correspond to "." and ".." */
56818 if (file->f_pos == 0) {
56819 ubifs_assert(!file->private_data);
56820@@ -438,6 +456,14 @@ static int ubifs_readdir(struct file *file, void *dirent, filldir_t filldir)
56821 file->f_pos = key_hash_flash(c, &dent->key);
56822 file->private_data = dent;
56823 cond_resched();
56824+
56825+ if (file->f_version == 0)
56826+ /*
56827+ * The file was seek'ed meanwhile, lets return and start
56828+ * reading direntries from the new position on the next
56829+ * invocation.
56830+ */
56831+ return 0;
56832 }
56833
56834 out:
56835@@ -448,15 +474,13 @@ out:
56836
56837 kfree(file->private_data);
56838 file->private_data = NULL;
56839+ /* 2 is a special value indicating that there are no more direntries */
56840 file->f_pos = 2;
56841 return 0;
56842 }
56843
56844-/* If a directory is seeked, we have to free saved readdir() state */
56845 static loff_t ubifs_dir_llseek(struct file *file, loff_t offset, int whence)
56846 {
56847- kfree(file->private_data);
56848- file->private_data = NULL;
56849 return generic_file_llseek(file, offset, whence);
56850 }
56851
56852diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
56853index e18b988..f1d4ad0f 100644
56854--- a/fs/ubifs/io.c
56855+++ b/fs/ubifs/io.c
56856@@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
56857 return err;
56858 }
56859
56860-int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56861+int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
56862 {
56863 int err;
56864
56865diff --git a/fs/udf/misc.c b/fs/udf/misc.c
56866index c175b4d..8f36a16 100644
56867--- a/fs/udf/misc.c
56868+++ b/fs/udf/misc.c
56869@@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
56870
56871 u8 udf_tag_checksum(const struct tag *t)
56872 {
56873- u8 *data = (u8 *)t;
56874+ const u8 *data = (const u8 *)t;
56875 u8 checksum = 0;
56876 int i;
56877 for (i = 0; i < sizeof(struct tag); ++i)
56878diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
56879index 8d974c4..b82f6ec 100644
56880--- a/fs/ufs/swab.h
56881+++ b/fs/ufs/swab.h
56882@@ -22,7 +22,7 @@ enum {
56883 BYTESEX_BE
56884 };
56885
56886-static inline u64
56887+static inline u64 __intentional_overflow(-1)
56888 fs64_to_cpu(struct super_block *sbp, __fs64 n)
56889 {
56890 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56891@@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
56892 return (__force __fs64)cpu_to_be64(n);
56893 }
56894
56895-static inline u32
56896+static inline u32 __intentional_overflow(-1)
56897 fs32_to_cpu(struct super_block *sbp, __fs32 n)
56898 {
56899 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
56900diff --git a/fs/utimes.c b/fs/utimes.c
56901index f4fb7ec..3fe03c0 100644
56902--- a/fs/utimes.c
56903+++ b/fs/utimes.c
56904@@ -1,6 +1,7 @@
56905 #include <linux/compiler.h>
56906 #include <linux/file.h>
56907 #include <linux/fs.h>
56908+#include <linux/security.h>
56909 #include <linux/linkage.h>
56910 #include <linux/mount.h>
56911 #include <linux/namei.h>
56912@@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
56913 goto mnt_drop_write_and_out;
56914 }
56915 }
56916+
56917+ if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
56918+ error = -EACCES;
56919+ goto mnt_drop_write_and_out;
56920+ }
56921+
56922 mutex_lock(&inode->i_mutex);
56923 error = notify_change(path->dentry, &newattrs);
56924 mutex_unlock(&inode->i_mutex);
56925diff --git a/fs/xattr.c b/fs/xattr.c
56926index 3377dff..4d074d9 100644
56927--- a/fs/xattr.c
56928+++ b/fs/xattr.c
56929@@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
56930 return rc;
56931 }
56932
56933+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56934+ssize_t
56935+pax_getxattr(struct dentry *dentry, void *value, size_t size)
56936+{
56937+ struct inode *inode = dentry->d_inode;
56938+ ssize_t error;
56939+
56940+ error = inode_permission(inode, MAY_EXEC);
56941+ if (error)
56942+ return error;
56943+
56944+ if (inode->i_op->getxattr)
56945+ error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
56946+ else
56947+ error = -EOPNOTSUPP;
56948+
56949+ return error;
56950+}
56951+EXPORT_SYMBOL(pax_getxattr);
56952+#endif
56953+
56954 ssize_t
56955 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
56956 {
56957@@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
56958 * Extended attribute SET operations
56959 */
56960 static long
56961-setxattr(struct dentry *d, const char __user *name, const void __user *value,
56962+setxattr(struct path *path, const char __user *name, const void __user *value,
56963 size_t size, int flags)
56964 {
56965 int error;
56966@@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
56967 posix_acl_fix_xattr_from_user(kvalue, size);
56968 }
56969
56970- error = vfs_setxattr(d, kname, kvalue, size, flags);
56971+ if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
56972+ error = -EACCES;
56973+ goto out;
56974+ }
56975+
56976+ error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
56977 out:
56978 if (vvalue)
56979 vfree(vvalue);
56980@@ -377,7 +403,7 @@ retry:
56981 return error;
56982 error = mnt_want_write(path.mnt);
56983 if (!error) {
56984- error = setxattr(path.dentry, name, value, size, flags);
56985+ error = setxattr(&path, name, value, size, flags);
56986 mnt_drop_write(path.mnt);
56987 }
56988 path_put(&path);
56989@@ -401,7 +427,7 @@ retry:
56990 return error;
56991 error = mnt_want_write(path.mnt);
56992 if (!error) {
56993- error = setxattr(path.dentry, name, value, size, flags);
56994+ error = setxattr(&path, name, value, size, flags);
56995 mnt_drop_write(path.mnt);
56996 }
56997 path_put(&path);
56998@@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
56999 const void __user *,value, size_t, size, int, flags)
57000 {
57001 struct fd f = fdget(fd);
57002- struct dentry *dentry;
57003 int error = -EBADF;
57004
57005 if (!f.file)
57006 return error;
57007- dentry = f.file->f_path.dentry;
57008- audit_inode(NULL, dentry, 0);
57009+ audit_inode(NULL, f.file->f_path.dentry, 0);
57010 error = mnt_want_write_file(f.file);
57011 if (!error) {
57012- error = setxattr(dentry, name, value, size, flags);
57013+ error = setxattr(&f.file->f_path, name, value, size, flags);
57014 mnt_drop_write_file(f.file);
57015 }
57016 fdput(f);
57017diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
57018index 9fbea87..6b19972 100644
57019--- a/fs/xattr_acl.c
57020+++ b/fs/xattr_acl.c
57021@@ -76,8 +76,8 @@ struct posix_acl *
57022 posix_acl_from_xattr(struct user_namespace *user_ns,
57023 const void *value, size_t size)
57024 {
57025- posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
57026- posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
57027+ const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
57028+ const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
57029 int count;
57030 struct posix_acl *acl;
57031 struct posix_acl_entry *acl_e;
57032diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
57033index b44af92..06073da 100644
57034--- a/fs/xfs/xfs_bmap.c
57035+++ b/fs/xfs/xfs_bmap.c
57036@@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
57037 int nmap,
57038 int ret_nmap);
57039 #else
57040-#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
57041+#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
57042 #endif /* DEBUG */
57043
57044 STATIC int
57045diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
57046index 1b9fc3e..e1bdde0 100644
57047--- a/fs/xfs/xfs_dir2_sf.c
57048+++ b/fs/xfs/xfs_dir2_sf.c
57049@@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
57050 }
57051
57052 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
57053- if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57054+ if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
57055+ char name[sfep->namelen];
57056+ memcpy(name, sfep->name, sfep->namelen);
57057+ if (filldir(dirent, name, sfep->namelen,
57058+ off & 0x7fffffff, ino, DT_UNKNOWN)) {
57059+ *offset = off & 0x7fffffff;
57060+ return 0;
57061+ }
57062+ } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
57063 off & 0x7fffffff, ino, DT_UNKNOWN)) {
57064 *offset = off & 0x7fffffff;
57065 return 0;
57066diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
57067index d681e34..2a3f5ab 100644
57068--- a/fs/xfs/xfs_ioctl.c
57069+++ b/fs/xfs/xfs_ioctl.c
57070@@ -127,7 +127,7 @@ xfs_find_handle(
57071 }
57072
57073 error = -EFAULT;
57074- if (copy_to_user(hreq->ohandle, &handle, hsize) ||
57075+ if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
57076 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
57077 goto out_put;
57078
57079diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
57080index ca9ecaa..60100c7 100644
57081--- a/fs/xfs/xfs_iops.c
57082+++ b/fs/xfs/xfs_iops.c
57083@@ -395,7 +395,7 @@ xfs_vn_put_link(
57084 struct nameidata *nd,
57085 void *p)
57086 {
57087- char *s = nd_get_link(nd);
57088+ const char *s = nd_get_link(nd);
57089
57090 if (!IS_ERR(s))
57091 kfree(s);
57092diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
57093new file mode 100644
57094index 0000000..4fb1dde
57095--- /dev/null
57096+++ b/grsecurity/Kconfig
57097@@ -0,0 +1,1053 @@
57098+#
57099+# grecurity configuration
57100+#
57101+menu "Memory Protections"
57102+depends on GRKERNSEC
57103+
57104+config GRKERNSEC_KMEM
57105+ bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
57106+ default y if GRKERNSEC_CONFIG_AUTO
57107+ select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
57108+ help
57109+ If you say Y here, /dev/kmem and /dev/mem won't be allowed to
57110+ be written to or read from to modify or leak the contents of the running
57111+ kernel. /dev/port will also not be allowed to be opened and support
57112+ for /dev/cpu/*/msr will be removed. If you have module
57113+ support disabled, enabling this will close up five ways that are
57114+ currently used to insert malicious code into the running kernel.
57115+
57116+ Even with all these features enabled, we still highly recommend that
57117+ you use the RBAC system, as it is still possible for an attacker to
57118+ modify the running kernel through privileged I/O granted by ioperm/iopl.
57119+
57120+ If you are not using XFree86, you may be able to stop this additional
57121+ case by enabling the 'Disable privileged I/O' option. Though nothing
57122+ legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
57123+ but only to video memory, which is the only writing we allow in this
57124+ case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
57125+ not be allowed to mprotect it with PROT_WRITE later.
57126+ Enabling this feature will prevent the "cpupower" and "powertop" tools
57127+ from working.
57128+
57129+ It is highly recommended that you say Y here if you meet all the
57130+ conditions above.
57131+
57132+config GRKERNSEC_VM86
57133+ bool "Restrict VM86 mode"
57134+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57135+ depends on X86_32
57136+
57137+ help
57138+ If you say Y here, only processes with CAP_SYS_RAWIO will be able to
57139+ make use of a special execution mode on 32bit x86 processors called
57140+ Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
57141+ video cards and will still work with this option enabled. The purpose
57142+ of the option is to prevent exploitation of emulation errors in
57143+ virtualization of vm86 mode like the one discovered in VMWare in 2009.
57144+ Nearly all users should be able to enable this option.
57145+
57146+config GRKERNSEC_IO
57147+ bool "Disable privileged I/O"
57148+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57149+ depends on X86
57150+ select RTC_CLASS
57151+ select RTC_INTF_DEV
57152+ select RTC_DRV_CMOS
57153+
57154+ help
57155+ If you say Y here, all ioperm and iopl calls will return an error.
57156+ Ioperm and iopl can be used to modify the running kernel.
57157+ Unfortunately, some programs need this access to operate properly,
57158+ the most notable of which are XFree86 and hwclock. hwclock can be
57159+ remedied by having RTC support in the kernel, so real-time
57160+ clock support is enabled if this option is enabled, to ensure
57161+ that hwclock operates correctly. XFree86 still will not
57162+ operate correctly with this option enabled, so DO NOT CHOOSE Y
57163+ IF YOU USE XFree86. If you use XFree86 and you still want to
57164+ protect your kernel against modification, use the RBAC system.
57165+
57166+config GRKERNSEC_JIT_HARDEN
57167+ bool "Harden BPF JIT against spray attacks"
57168+ default y if GRKERNSEC_CONFIG_AUTO
57169+ depends on BPF_JIT
57170+ help
57171+ If you say Y here, the native code generated by the kernel's Berkeley
57172+ Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
57173+ attacks that attempt to fit attacker-beneficial instructions in
57174+ 32bit immediate fields of JIT-generated native instructions. The
57175+ attacker will generally aim to cause an unintended instruction sequence
57176+ of JIT-generated native code to execute by jumping into the middle of
57177+ a generated instruction. This feature effectively randomizes the 32bit
57178+ immediate constants present in the generated code to thwart such attacks.
57179+
57180+ If you're using KERNEXEC, it's recommended that you enable this option
57181+ to supplement the hardening of the kernel.
57182+
57183+config GRKERNSEC_PERF_HARDEN
57184+ bool "Disable unprivileged PERF_EVENTS usage by default"
57185+ default y if GRKERNSEC_CONFIG_AUTO
57186+ depends on PERF_EVENTS
57187+ help
57188+ If you say Y here, the range of acceptable values for the
57189+ /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
57190+ default to a new value: 3. When the sysctl is set to this value, no
57191+ unprivileged use of the PERF_EVENTS syscall interface will be permitted.
57192+
57193+ Though PERF_EVENTS can be used legitimately for performance monitoring
57194+ and low-level application profiling, it is forced on regardless of
57195+ configuration, has been at fault for several vulnerabilities, and
57196+ creates new opportunities for side channels and other information leaks.
57197+
57198+ This feature puts PERF_EVENTS into a secure default state and permits
57199+ the administrator to change out of it temporarily if unprivileged
57200+ application profiling is needed.
57201+
57202+config GRKERNSEC_RAND_THREADSTACK
57203+ bool "Insert random gaps between thread stacks"
57204+ default y if GRKERNSEC_CONFIG_AUTO
57205+ depends on PAX_RANDMMAP && !PPC
57206+ help
57207+ If you say Y here, a random-sized gap will be enforced between allocated
57208+ thread stacks. Glibc's NPTL and other threading libraries that
57209+ pass MAP_STACK to the kernel for thread stack allocation are supported.
57210+ The implementation currently provides 8 bits of entropy for the gap.
57211+
57212+ Many distributions do not compile threaded remote services with the
57213+ -fstack-check argument to GCC, causing the variable-sized stack-based
57214+ allocator, alloca(), to not probe the stack on allocation. This
57215+ permits an unbounded alloca() to skip over any guard page and potentially
57216+ modify another thread's stack reliably. An enforced random gap
57217+ reduces the reliability of such an attack and increases the chance
57218+ that such a read/write to another thread's stack instead lands in
57219+ an unmapped area, causing a crash and triggering grsecurity's
57220+ anti-bruteforcing logic.
57221+
57222+config GRKERNSEC_PROC_MEMMAP
57223+ bool "Harden ASLR against information leaks and entropy reduction"
57224+ default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
57225+ depends on PAX_NOEXEC || PAX_ASLR
57226+ help
57227+ If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
57228+ give no information about the addresses of its mappings if
57229+ PaX features that rely on random addresses are enabled on the task.
57230+ In addition to sanitizing this information and disabling other
57231+ dangerous sources of information, this option causes reads of sensitive
57232+ /proc/<pid> entries where the file descriptor was opened in a different
57233+ task than the one performing the read. Such attempts are logged.
57234+ This option also limits argv/env strings for suid/sgid binaries
57235+ to 512KB to prevent a complete exhaustion of the stack entropy provided
57236+ by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
57237+ binaries to prevent alternative mmap layouts from being abused.
57238+
57239+ If you use PaX it is essential that you say Y here as it closes up
57240+ several holes that make full ASLR useless locally.
57241+
57242+config GRKERNSEC_BRUTE
57243+ bool "Deter exploit bruteforcing"
57244+ default y if GRKERNSEC_CONFIG_AUTO
57245+ help
57246+ If you say Y here, attempts to bruteforce exploits against forking
57247+ daemons such as apache or sshd, as well as against suid/sgid binaries
57248+ will be deterred. When a child of a forking daemon is killed by PaX
57249+ or crashes due to an illegal instruction or other suspicious signal,
57250+ the parent process will be delayed 30 seconds upon every subsequent
57251+ fork until the administrator is able to assess the situation and
57252+ restart the daemon.
57253+ In the suid/sgid case, the attempt is logged, the user has all their
57254+ processes terminated, and they are prevented from executing any further
57255+ processes for 15 minutes.
57256+ It is recommended that you also enable signal logging in the auditing
57257+ section so that logs are generated when a process triggers a suspicious
57258+ signal.
57259+ If the sysctl option is enabled, a sysctl option with name
57260+ "deter_bruteforce" is created.
57261+
57262+
57263+config GRKERNSEC_MODHARDEN
57264+ bool "Harden module auto-loading"
57265+ default y if GRKERNSEC_CONFIG_AUTO
57266+ depends on MODULES
57267+ help
57268+ If you say Y here, module auto-loading in response to use of some
57269+ feature implemented by an unloaded module will be restricted to
57270+ root users. Enabling this option helps defend against attacks
57271+ by unprivileged users who abuse the auto-loading behavior to
57272+ cause a vulnerable module to load that is then exploited.
57273+
57274+ If this option prevents a legitimate use of auto-loading for a
57275+ non-root user, the administrator can execute modprobe manually
57276+ with the exact name of the module mentioned in the alert log.
57277+ Alternatively, the administrator can add the module to the list
57278+ of modules loaded at boot by modifying init scripts.
57279+
57280+ Modification of init scripts will most likely be needed on
57281+ Ubuntu servers with encrypted home directory support enabled,
57282+ as the first non-root user logging in will cause the ecb(aes),
57283+ ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
57284+
57285+config GRKERNSEC_HIDESYM
57286+ bool "Hide kernel symbols"
57287+ default y if GRKERNSEC_CONFIG_AUTO
57288+ select PAX_USERCOPY_SLABS
57289+ help
57290+ If you say Y here, getting information on loaded modules, and
57291+ displaying all kernel symbols through a syscall will be restricted
57292+ to users with CAP_SYS_MODULE. For software compatibility reasons,
57293+ /proc/kallsyms will be restricted to the root user. The RBAC
57294+ system can hide that entry even from root.
57295+
57296+ This option also prevents leaking of kernel addresses through
57297+ several /proc entries.
57298+
57299+ Note that this option is only effective provided the following
57300+ conditions are met:
57301+ 1) The kernel using grsecurity is not precompiled by some distribution
57302+ 2) You have also enabled GRKERNSEC_DMESG
57303+ 3) You are using the RBAC system and hiding other files such as your
57304+ kernel image and System.map. Alternatively, enabling this option
57305+ causes the permissions on /boot, /lib/modules, and the kernel
57306+ source directory to change at compile time to prevent
57307+ reading by non-root users.
57308+ If the above conditions are met, this option will aid in providing a
57309+ useful protection against local kernel exploitation of overflows
57310+ and arbitrary read/write vulnerabilities.
57311+
57312+ It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
57313+ in addition to this feature.
57314+
57315+config GRKERNSEC_KERN_LOCKOUT
57316+ bool "Active kernel exploit response"
57317+ default y if GRKERNSEC_CONFIG_AUTO
57318+ depends on X86 || ARM || PPC || SPARC
57319+ help
57320+ If you say Y here, when a PaX alert is triggered due to suspicious
57321+ activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
57322+ or an OOPS occurs due to bad memory accesses, instead of just
57323+ terminating the offending process (and potentially allowing
57324+ a subsequent exploit from the same user), we will take one of two
57325+ actions:
57326+ If the user was root, we will panic the system
57327+ If the user was non-root, we will log the attempt, terminate
57328+ all processes owned by the user, then prevent them from creating
57329+ any new processes until the system is restarted
57330+ This deters repeated kernel exploitation/bruteforcing attempts
57331+ and is useful for later forensics.
57332+
57333+endmenu
57334+menu "Role Based Access Control Options"
57335+depends on GRKERNSEC
57336+
57337+config GRKERNSEC_RBAC_DEBUG
57338+ bool
57339+
57340+config GRKERNSEC_NO_RBAC
57341+ bool "Disable RBAC system"
57342+ help
57343+ If you say Y here, the /dev/grsec device will be removed from the kernel,
57344+ preventing the RBAC system from being enabled. You should only say Y
57345+ here if you have no intention of using the RBAC system, so as to prevent
57346+ an attacker with root access from misusing the RBAC system to hide files
57347+ and processes when loadable module support and /dev/[k]mem have been
57348+ locked down.
57349+
57350+config GRKERNSEC_ACL_HIDEKERN
57351+ bool "Hide kernel processes"
57352+ help
57353+ If you say Y here, all kernel threads will be hidden to all
57354+ processes but those whose subject has the "view hidden processes"
57355+ flag.
57356+
57357+config GRKERNSEC_ACL_MAXTRIES
57358+ int "Maximum tries before password lockout"
57359+ default 3
57360+ help
57361+ This option enforces the maximum number of times a user can attempt
57362+ to authorize themselves with the grsecurity RBAC system before being
57363+ denied the ability to attempt authorization again for a specified time.
57364+ The lower the number, the harder it will be to brute-force a password.
57365+
57366+config GRKERNSEC_ACL_TIMEOUT
57367+ int "Time to wait after max password tries, in seconds"
57368+ default 30
57369+ help
57370+ This option specifies the time the user must wait after attempting to
57371+ authorize to the RBAC system with the maximum number of invalid
57372+ passwords. The higher the number, the harder it will be to brute-force
57373+ a password.
57374+
57375+endmenu
57376+menu "Filesystem Protections"
57377+depends on GRKERNSEC
57378+
57379+config GRKERNSEC_PROC
57380+ bool "Proc restrictions"
57381+ default y if GRKERNSEC_CONFIG_AUTO
57382+ help
57383+ If you say Y here, the permissions of the /proc filesystem
57384+ will be altered to enhance system security and privacy. You MUST
57385+ choose either a user only restriction or a user and group restriction.
57386+ Depending upon the option you choose, you can either restrict users to
57387+ see only the processes they themselves run, or choose a group that can
57388+ view all processes and files normally restricted to root if you choose
57389+ the "restrict to user only" option. NOTE: If you're running identd or
57390+ ntpd as a non-root user, you will have to run it as the group you
57391+ specify here.
57392+
57393+config GRKERNSEC_PROC_USER
57394+ bool "Restrict /proc to user only"
57395+ depends on GRKERNSEC_PROC
57396+ help
57397+ If you say Y here, non-root users will only be able to view their own
57398+ processes, and restricts them from viewing network-related information,
57399+ and viewing kernel symbol and module information.
57400+
57401+config GRKERNSEC_PROC_USERGROUP
57402+ bool "Allow special group"
57403+ default y if GRKERNSEC_CONFIG_AUTO
57404+ depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
57405+ help
57406+ If you say Y here, you will be able to select a group that will be
57407+ able to view all processes and network-related information. If you've
57408+ enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
57409+ remain hidden. This option is useful if you want to run identd as
57410+ a non-root user. The group you select may also be chosen at boot time
57411+ via "grsec_proc_gid=" on the kernel commandline.
57412+
57413+config GRKERNSEC_PROC_GID
57414+ int "GID for special group"
57415+ depends on GRKERNSEC_PROC_USERGROUP
57416+ default 1001
57417+
57418+config GRKERNSEC_PROC_ADD
57419+ bool "Additional restrictions"
57420+ default y if GRKERNSEC_CONFIG_AUTO
57421+ depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
57422+ help
57423+ If you say Y here, additional restrictions will be placed on
57424+ /proc that keep normal users from viewing device information and
57425+ slabinfo information that could be useful for exploits.
57426+
57427+config GRKERNSEC_LINK
57428+ bool "Linking restrictions"
57429+ default y if GRKERNSEC_CONFIG_AUTO
57430+ help
57431+ If you say Y here, /tmp race exploits will be prevented, since users
57432+ will no longer be able to follow symlinks owned by other users in
57433+ world-writable +t directories (e.g. /tmp), unless the owner of the
57434+ symlink is the owner of the directory. users will also not be
57435+ able to hardlink to files they do not own. If the sysctl option is
57436+ enabled, a sysctl option with name "linking_restrictions" is created.
57437+
57438+config GRKERNSEC_SYMLINKOWN
57439+ bool "Kernel-enforced SymlinksIfOwnerMatch"
57440+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57441+ help
57442+ Apache's SymlinksIfOwnerMatch option has an inherent race condition
57443+ that prevents it from being used as a security feature. As Apache
57444+ verifies the symlink by performing a stat() against the target of
57445+ the symlink before it is followed, an attacker can setup a symlink
57446+ to point to a same-owned file, then replace the symlink with one
57447+ that targets another user's file just after Apache "validates" the
57448+ symlink -- a classic TOCTOU race. If you say Y here, a complete,
57449+ race-free replacement for Apache's "SymlinksIfOwnerMatch" option
57450+ will be in place for the group you specify. If the sysctl option
57451+ is enabled, a sysctl option with name "enforce_symlinksifowner" is
57452+ created.
57453+
57454+config GRKERNSEC_SYMLINKOWN_GID
57455+ int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
57456+ depends on GRKERNSEC_SYMLINKOWN
57457+ default 1006
57458+ help
57459+ Setting this GID determines what group kernel-enforced
57460+ SymlinksIfOwnerMatch will be enabled for. If the sysctl option
57461+ is enabled, a sysctl option with name "symlinkown_gid" is created.
57462+
57463+config GRKERNSEC_FIFO
57464+ bool "FIFO restrictions"
57465+ default y if GRKERNSEC_CONFIG_AUTO
57466+ help
57467+ If you say Y here, users will not be able to write to FIFOs they don't
57468+ own in world-writable +t directories (e.g. /tmp), unless the owner of
57469+ the FIFO is the same owner of the directory it's held in. If the sysctl
57470+ option is enabled, a sysctl option with name "fifo_restrictions" is
57471+ created.
57472+
57473+config GRKERNSEC_SYSFS_RESTRICT
57474+ bool "Sysfs/debugfs restriction"
57475+ default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
57476+ depends on SYSFS
57477+ help
57478+ If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
57479+ any filesystem normally mounted under it (e.g. debugfs) will be
57480+ mostly accessible only by root. These filesystems generally provide access
57481+ to hardware and debug information that isn't appropriate for unprivileged
57482+ users of the system. Sysfs and debugfs have also become a large source
57483+ of new vulnerabilities, ranging from infoleaks to local compromise.
57484+ There has been very little oversight with an eye toward security involved
57485+ in adding new exporters of information to these filesystems, so their
57486+ use is discouraged.
57487+ For reasons of compatibility, a few directories have been whitelisted
57488+ for access by non-root users:
57489+ /sys/fs/selinux
57490+ /sys/fs/fuse
57491+ /sys/devices/system/cpu
57492+
57493+config GRKERNSEC_ROFS
57494+ bool "Runtime read-only mount protection"
57495+ help
57496+ If you say Y here, a sysctl option with name "romount_protect" will
57497+ be created. By setting this option to 1 at runtime, filesystems
57498+ will be protected in the following ways:
57499+ * No new writable mounts will be allowed
57500+ * Existing read-only mounts won't be able to be remounted read/write
57501+ * Write operations will be denied on all block devices
57502+ This option acts independently of grsec_lock: once it is set to 1,
57503+ it cannot be turned off. Therefore, please be mindful of the resulting
57504+ behavior if this option is enabled in an init script on a read-only
57505+ filesystem. This feature is mainly intended for secure embedded systems.
57506+
57507+config GRKERNSEC_DEVICE_SIDECHANNEL
57508+ bool "Eliminate stat/notify-based device sidechannels"
57509+ default y if GRKERNSEC_CONFIG_AUTO
57510+ help
57511+ If you say Y here, timing analyses on block or character
57512+ devices like /dev/ptmx using stat or inotify/dnotify/fanotify
57513+ will be thwarted for unprivileged users. If a process without
57514+ CAP_MKNOD stats such a device, the last access and last modify times
57515+ will match the device's create time. No access or modify events
57516+ will be triggered through inotify/dnotify/fanotify for such devices.
57517+ This feature will prevent attacks that may at a minimum
57518+ allow an attacker to determine the administrator's password length.
57519+
57520+config GRKERNSEC_CHROOT
57521+ bool "Chroot jail restrictions"
57522+ default y if GRKERNSEC_CONFIG_AUTO
57523+ help
57524+ If you say Y here, you will be able to choose several options that will
57525+ make breaking out of a chrooted jail much more difficult. If you
57526+ encounter no software incompatibilities with the following options, it
57527+ is recommended that you enable each one.
57528+
57529+config GRKERNSEC_CHROOT_MOUNT
57530+ bool "Deny mounts"
57531+ default y if GRKERNSEC_CONFIG_AUTO
57532+ depends on GRKERNSEC_CHROOT
57533+ help
57534+ If you say Y here, processes inside a chroot will not be able to
57535+ mount or remount filesystems. If the sysctl option is enabled, a
57536+ sysctl option with name "chroot_deny_mount" is created.
57537+
57538+config GRKERNSEC_CHROOT_DOUBLE
57539+ bool "Deny double-chroots"
57540+ default y if GRKERNSEC_CONFIG_AUTO
57541+ depends on GRKERNSEC_CHROOT
57542+ help
57543+ If you say Y here, processes inside a chroot will not be able to chroot
57544+ again outside the chroot. This is a widely used method of breaking
57545+ out of a chroot jail and should not be allowed. If the sysctl
57546+ option is enabled, a sysctl option with name
57547+ "chroot_deny_chroot" is created.
57548+
57549+config GRKERNSEC_CHROOT_PIVOT
57550+ bool "Deny pivot_root in chroot"
57551+ default y if GRKERNSEC_CONFIG_AUTO
57552+ depends on GRKERNSEC_CHROOT
57553+ help
57554+ If you say Y here, processes inside a chroot will not be able to use
57555+ a function called pivot_root() that was introduced in Linux 2.3.41. It
57556+ works similar to chroot in that it changes the root filesystem. This
57557+ function could be misused in a chrooted process to attempt to break out
57558+ of the chroot, and therefore should not be allowed. If the sysctl
57559+ option is enabled, a sysctl option with name "chroot_deny_pivot" is
57560+ created.
57561+
57562+config GRKERNSEC_CHROOT_CHDIR
57563+ bool "Enforce chdir(\"/\") on all chroots"
57564+ default y if GRKERNSEC_CONFIG_AUTO
57565+ depends on GRKERNSEC_CHROOT
57566+ help
57567+ If you say Y here, the current working directory of all newly-chrooted
57568+ applications will be set to the the root directory of the chroot.
57569+ The man page on chroot(2) states:
57570+ Note that this call does not change the current working
57571+ directory, so that `.' can be outside the tree rooted at
57572+ `/'. In particular, the super-user can escape from a
57573+ `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
57574+
57575+ It is recommended that you say Y here, since it's not known to break
57576+ any software. If the sysctl option is enabled, a sysctl option with
57577+ name "chroot_enforce_chdir" is created.
57578+
57579+config GRKERNSEC_CHROOT_CHMOD
57580+ bool "Deny (f)chmod +s"
57581+ default y if GRKERNSEC_CONFIG_AUTO
57582+ depends on GRKERNSEC_CHROOT
57583+ help
57584+ If you say Y here, processes inside a chroot will not be able to chmod
57585+ or fchmod files to make them have suid or sgid bits. This protects
57586+ against another published method of breaking a chroot. If the sysctl
57587+ option is enabled, a sysctl option with name "chroot_deny_chmod" is
57588+ created.
57589+
57590+config GRKERNSEC_CHROOT_FCHDIR
57591+ bool "Deny fchdir out of chroot"
57592+ default y if GRKERNSEC_CONFIG_AUTO
57593+ depends on GRKERNSEC_CHROOT
57594+ help
57595+ If you say Y here, a well-known method of breaking chroots by fchdir'ing
57596+ to a file descriptor of the chrooting process that points to a directory
57597+ outside the filesystem will be stopped. If the sysctl option
57598+ is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
57599+
57600+config GRKERNSEC_CHROOT_MKNOD
57601+ bool "Deny mknod"
57602+ default y if GRKERNSEC_CONFIG_AUTO
57603+ depends on GRKERNSEC_CHROOT
57604+ help
57605+ If you say Y here, processes inside a chroot will not be allowed to
57606+ mknod. The problem with using mknod inside a chroot is that it
57607+ would allow an attacker to create a device entry that is the same
57608+ as one on the physical root of your system, which could range from
57609+ anything from the console device to a device for your harddrive (which
57610+ they could then use to wipe the drive or steal data). It is recommended
57611+ that you say Y here, unless you run into software incompatibilities.
57612+ If the sysctl option is enabled, a sysctl option with name
57613+ "chroot_deny_mknod" is created.
57614+
57615+config GRKERNSEC_CHROOT_SHMAT
57616+ bool "Deny shmat() out of chroot"
57617+ default y if GRKERNSEC_CONFIG_AUTO
57618+ depends on GRKERNSEC_CHROOT
57619+ help
57620+ If you say Y here, processes inside a chroot will not be able to attach
57621+ to shared memory segments that were created outside of the chroot jail.
57622+ It is recommended that you say Y here. If the sysctl option is enabled,
57623+ a sysctl option with name "chroot_deny_shmat" is created.
57624+
57625+config GRKERNSEC_CHROOT_UNIX
57626+ bool "Deny access to abstract AF_UNIX sockets out of chroot"
57627+ default y if GRKERNSEC_CONFIG_AUTO
57628+ depends on GRKERNSEC_CHROOT
57629+ help
57630+ If you say Y here, processes inside a chroot will not be able to
57631+ connect to abstract (meaning not belonging to a filesystem) Unix
57632+ domain sockets that were bound outside of a chroot. It is recommended
57633+ that you say Y here. If the sysctl option is enabled, a sysctl option
57634+ with name "chroot_deny_unix" is created.
57635+
57636+config GRKERNSEC_CHROOT_FINDTASK
57637+ bool "Protect outside processes"
57638+ default y if GRKERNSEC_CONFIG_AUTO
57639+ depends on GRKERNSEC_CHROOT
57640+ help
57641+ If you say Y here, processes inside a chroot will not be able to
57642+ kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
57643+ getsid, or view any process outside of the chroot. If the sysctl
57644+ option is enabled, a sysctl option with name "chroot_findtask" is
57645+ created.
57646+
57647+config GRKERNSEC_CHROOT_NICE
57648+ bool "Restrict priority changes"
57649+ default y if GRKERNSEC_CONFIG_AUTO
57650+ depends on GRKERNSEC_CHROOT
57651+ help
57652+ If you say Y here, processes inside a chroot will not be able to raise
57653+ the priority of processes in the chroot, or alter the priority of
57654+ processes outside the chroot. This provides more security than simply
57655+ removing CAP_SYS_NICE from the process' capability set. If the
57656+ sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
57657+ is created.
57658+
57659+config GRKERNSEC_CHROOT_SYSCTL
57660+ bool "Deny sysctl writes"
57661+ default y if GRKERNSEC_CONFIG_AUTO
57662+ depends on GRKERNSEC_CHROOT
57663+ help
57664+ If you say Y here, an attacker in a chroot will not be able to
57665+ write to sysctl entries, either by sysctl(2) or through a /proc
57666+ interface. It is strongly recommended that you say Y here. If the
57667+ sysctl option is enabled, a sysctl option with name
57668+ "chroot_deny_sysctl" is created.
57669+
57670+config GRKERNSEC_CHROOT_CAPS
57671+ bool "Capability restrictions"
57672+ default y if GRKERNSEC_CONFIG_AUTO
57673+ depends on GRKERNSEC_CHROOT
57674+ help
57675+ If you say Y here, the capabilities on all processes within a
57676+ chroot jail will be lowered to stop module insertion, raw i/o,
57677+ system and net admin tasks, rebooting the system, modifying immutable
57678+ files, modifying IPC owned by another, and changing the system time.
57679+ This is left an option because it can break some apps. Disable this
57680+ if your chrooted apps are having problems performing those kinds of
57681+ tasks. If the sysctl option is enabled, a sysctl option with
57682+ name "chroot_caps" is created.
57683+
57684+config GRKERNSEC_CHROOT_INITRD
57685+ bool "Exempt initrd tasks from restrictions"
57686+ default y if GRKERNSEC_CONFIG_AUTO
57687+ depends on GRKERNSEC_CHROOT && BLK_DEV_RAM
57688+ help
57689+ If you say Y here, tasks started prior to init will be exempted from
57690+ grsecurity's chroot restrictions. This option is mainly meant to
57691+ resolve Plymouth's performing privileged operations unnecessarily
57692+ in a chroot.
57693+
57694+endmenu
57695+menu "Kernel Auditing"
57696+depends on GRKERNSEC
57697+
57698+config GRKERNSEC_AUDIT_GROUP
57699+ bool "Single group for auditing"
57700+ help
57701+ If you say Y here, the exec and chdir logging features will only operate
57702+ on a group you specify. This option is recommended if you only want to
57703+ watch certain users instead of having a large amount of logs from the
57704+ entire system. If the sysctl option is enabled, a sysctl option with
57705+ name "audit_group" is created.
57706+
57707+config GRKERNSEC_AUDIT_GID
57708+ int "GID for auditing"
57709+ depends on GRKERNSEC_AUDIT_GROUP
57710+ default 1007
57711+
57712+config GRKERNSEC_EXECLOG
57713+ bool "Exec logging"
57714+ help
57715+ If you say Y here, all execve() calls will be logged (since the
57716+ other exec*() calls are frontends to execve(), all execution
57717+ will be logged). Useful for shell-servers that like to keep track
57718+ of their users. If the sysctl option is enabled, a sysctl option with
57719+ name "exec_logging" is created.
57720+ WARNING: This option when enabled will produce a LOT of logs, especially
57721+ on an active system.
57722+
57723+config GRKERNSEC_RESLOG
57724+ bool "Resource logging"
57725+ default y if GRKERNSEC_CONFIG_AUTO
57726+ help
57727+ If you say Y here, all attempts to overstep resource limits will
57728+ be logged with the resource name, the requested size, and the current
57729+ limit. It is highly recommended that you say Y here. If the sysctl
57730+ option is enabled, a sysctl option with name "resource_logging" is
57731+ created. If the RBAC system is enabled, the sysctl value is ignored.
57732+
57733+config GRKERNSEC_CHROOT_EXECLOG
57734+ bool "Log execs within chroot"
57735+ help
57736+ If you say Y here, all executions inside a chroot jail will be logged
57737+ to syslog. This can cause a large amount of logs if certain
57738+ applications (eg. djb's daemontools) are installed on the system, and
57739+ is therefore left as an option. If the sysctl option is enabled, a
57740+ sysctl option with name "chroot_execlog" is created.
57741+
57742+config GRKERNSEC_AUDIT_PTRACE
57743+ bool "Ptrace logging"
57744+ help
57745+ If you say Y here, all attempts to attach to a process via ptrace
57746+ will be logged. If the sysctl option is enabled, a sysctl option
57747+ with name "audit_ptrace" is created.
57748+
57749+config GRKERNSEC_AUDIT_CHDIR
57750+ bool "Chdir logging"
57751+ help
57752+ If you say Y here, all chdir() calls will be logged. If the sysctl
57753+ option is enabled, a sysctl option with name "audit_chdir" is created.
57754+
57755+config GRKERNSEC_AUDIT_MOUNT
57756+ bool "(Un)Mount logging"
57757+ help
57758+ If you say Y here, all mounts and unmounts will be logged. If the
57759+ sysctl option is enabled, a sysctl option with name "audit_mount" is
57760+ created.
57761+
57762+config GRKERNSEC_SIGNAL
57763+ bool "Signal logging"
57764+ default y if GRKERNSEC_CONFIG_AUTO
57765+ help
57766+ If you say Y here, certain important signals will be logged, such as
57767+ SIGSEGV, which will as a result inform you of when a error in a program
57768+ occurred, which in some cases could mean a possible exploit attempt.
57769+ If the sysctl option is enabled, a sysctl option with name
57770+ "signal_logging" is created.
57771+
57772+config GRKERNSEC_FORKFAIL
57773+ bool "Fork failure logging"
57774+ help
57775+ If you say Y here, all failed fork() attempts will be logged.
57776+ This could suggest a fork bomb, or someone attempting to overstep
57777+ their process limit. If the sysctl option is enabled, a sysctl option
57778+ with name "forkfail_logging" is created.
57779+
57780+config GRKERNSEC_TIME
57781+ bool "Time change logging"
57782+ default y if GRKERNSEC_CONFIG_AUTO
57783+ help
57784+ If you say Y here, any changes of the system clock will be logged.
57785+ If the sysctl option is enabled, a sysctl option with name
57786+ "timechange_logging" is created.
57787+
57788+config GRKERNSEC_PROC_IPADDR
57789+ bool "/proc/<pid>/ipaddr support"
57790+ default y if GRKERNSEC_CONFIG_AUTO
57791+ help
57792+ If you say Y here, a new entry will be added to each /proc/<pid>
57793+ directory that contains the IP address of the person using the task.
57794+ The IP is carried across local TCP and AF_UNIX stream sockets.
57795+ This information can be useful for IDS/IPSes to perform remote response
57796+ to a local attack. The entry is readable by only the owner of the
57797+ process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
57798+ the RBAC system), and thus does not create privacy concerns.
57799+
57800+config GRKERNSEC_RWXMAP_LOG
57801+ bool 'Denied RWX mmap/mprotect logging'
57802+ default y if GRKERNSEC_CONFIG_AUTO
57803+ depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
57804+ help
57805+ If you say Y here, calls to mmap() and mprotect() with explicit
57806+ usage of PROT_WRITE and PROT_EXEC together will be logged when
57807+ denied by the PAX_MPROTECT feature. If the sysctl option is
57808+ enabled, a sysctl option with name "rwxmap_logging" is created.
57809+
57810+config GRKERNSEC_AUDIT_TEXTREL
57811+ bool 'ELF text relocations logging (READ HELP)'
57812+ depends on PAX_MPROTECT
57813+ help
57814+ If you say Y here, text relocations will be logged with the filename
57815+ of the offending library or binary. The purpose of the feature is
57816+ to help Linux distribution developers get rid of libraries and
57817+ binaries that need text relocations which hinder the future progress
57818+ of PaX. Only Linux distribution developers should say Y here, and
57819+ never on a production machine, as this option creates an information
57820+ leak that could aid an attacker in defeating the randomization of
57821+ a single memory region. If the sysctl option is enabled, a sysctl
57822+ option with name "audit_textrel" is created.
57823+
57824+endmenu
57825+
57826+menu "Executable Protections"
57827+depends on GRKERNSEC
57828+
57829+config GRKERNSEC_DMESG
57830+ bool "Dmesg(8) restriction"
57831+ default y if GRKERNSEC_CONFIG_AUTO
57832+ help
57833+ If you say Y here, non-root users will not be able to use dmesg(8)
57834+ to view the contents of the kernel's circular log buffer.
57835+ The kernel's log buffer often contains kernel addresses and other
57836+ identifying information useful to an attacker in fingerprinting a
57837+ system for a targeted exploit.
57838+ If the sysctl option is enabled, a sysctl option with name "dmesg" is
57839+ created.
57840+
57841+config GRKERNSEC_HARDEN_PTRACE
57842+ bool "Deter ptrace-based process snooping"
57843+ default y if GRKERNSEC_CONFIG_AUTO
57844+ help
57845+ If you say Y here, TTY sniffers and other malicious monitoring
57846+ programs implemented through ptrace will be defeated. If you
57847+ have been using the RBAC system, this option has already been
57848+ enabled for several years for all users, with the ability to make
57849+ fine-grained exceptions.
57850+
57851+ This option only affects the ability of non-root users to ptrace
57852+ processes that are not a descendent of the ptracing process.
57853+ This means that strace ./binary and gdb ./binary will still work,
57854+ but attaching to arbitrary processes will not. If the sysctl
57855+ option is enabled, a sysctl option with name "harden_ptrace" is
57856+ created.
57857+
57858+config GRKERNSEC_PTRACE_READEXEC
57859+ bool "Require read access to ptrace sensitive binaries"
57860+ default y if GRKERNSEC_CONFIG_AUTO
57861+ help
57862+ If you say Y here, unprivileged users will not be able to ptrace unreadable
57863+ binaries. This option is useful in environments that
57864+ remove the read bits (e.g. file mode 4711) from suid binaries to
57865+ prevent infoleaking of their contents. This option adds
57866+ consistency to the use of that file mode, as the binary could normally
57867+ be read out when run without privileges while ptracing.
57868+
57869+ If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
57870+ is created.
57871+
57872+config GRKERNSEC_SETXID
57873+ bool "Enforce consistent multithreaded privileges"
57874+ default y if GRKERNSEC_CONFIG_AUTO
57875+ depends on (X86 || SPARC64 || PPC || ARM || MIPS)
57876+ help
57877+ If you say Y here, a change from a root uid to a non-root uid
57878+ in a multithreaded application will cause the resulting uids,
57879+ gids, supplementary groups, and capabilities in that thread
57880+ to be propagated to the other threads of the process. In most
57881+ cases this is unnecessary, as glibc will emulate this behavior
57882+ on behalf of the application. Other libcs do not act in the
57883+ same way, allowing the other threads of the process to continue
57884+ running with root privileges. If the sysctl option is enabled,
57885+ a sysctl option with name "consistent_setxid" is created.
57886+
57887+config GRKERNSEC_TPE
57888+ bool "Trusted Path Execution (TPE)"
57889+ default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
57890+ help
57891+ If you say Y here, you will be able to choose a gid to add to the
57892+ supplementary groups of users you want to mark as "untrusted."
57893+ These users will not be able to execute any files that are not in
57894+ root-owned directories writable only by root. If the sysctl option
57895+ is enabled, a sysctl option with name "tpe" is created.
57896+
57897+config GRKERNSEC_TPE_ALL
57898+ bool "Partially restrict all non-root users"
57899+ depends on GRKERNSEC_TPE
57900+ help
57901+ If you say Y here, all non-root users will be covered under
57902+ a weaker TPE restriction. This is separate from, and in addition to,
57903+ the main TPE options that you have selected elsewhere. Thus, if a
57904+ "trusted" GID is chosen, this restriction applies to even that GID.
57905+ Under this restriction, all non-root users will only be allowed to
57906+ execute files in directories they own that are not group or
57907+ world-writable, or in directories owned by root and writable only by
57908+ root. If the sysctl option is enabled, a sysctl option with name
57909+ "tpe_restrict_all" is created.
57910+
57911+config GRKERNSEC_TPE_INVERT
57912+ bool "Invert GID option"
57913+ depends on GRKERNSEC_TPE
57914+ help
57915+ If you say Y here, the group you specify in the TPE configuration will
57916+ decide what group TPE restrictions will be *disabled* for. This
57917+ option is useful if you want TPE restrictions to be applied to most
57918+ users on the system. If the sysctl option is enabled, a sysctl option
57919+ with name "tpe_invert" is created. Unlike other sysctl options, this
57920+ entry will default to on for backward-compatibility.
57921+
57922+config GRKERNSEC_TPE_GID
57923+ int
57924+ default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
57925+ default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
57926+
57927+config GRKERNSEC_TPE_UNTRUSTED_GID
57928+ int "GID for TPE-untrusted users"
57929+ depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
57930+ default 1005
57931+ help
57932+ Setting this GID determines what group TPE restrictions will be
57933+ *enabled* for. If the sysctl option is enabled, a sysctl option
57934+ with name "tpe_gid" is created.
57935+
57936+config GRKERNSEC_TPE_TRUSTED_GID
57937+ int "GID for TPE-trusted users"
57938+ depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
57939+ default 1005
57940+ help
57941+ Setting this GID determines what group TPE restrictions will be
57942+ *disabled* for. If the sysctl option is enabled, a sysctl option
57943+ with name "tpe_gid" is created.
57944+
57945+endmenu
57946+menu "Network Protections"
57947+depends on GRKERNSEC
57948+
57949+config GRKERNSEC_RANDNET
57950+ bool "Larger entropy pools"
57951+ default y if GRKERNSEC_CONFIG_AUTO
57952+ help
57953+ If you say Y here, the entropy pools used for many features of Linux
57954+ and grsecurity will be doubled in size. Since several grsecurity
57955+ features use additional randomness, it is recommended that you say Y
57956+ here. Saying Y here has a similar effect as modifying
57957+ /proc/sys/kernel/random/poolsize.
57958+
57959+config GRKERNSEC_BLACKHOLE
57960+ bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
57961+ default y if GRKERNSEC_CONFIG_AUTO
57962+ depends on NET
57963+ help
57964+ If you say Y here, neither TCP resets nor ICMP
57965+ destination-unreachable packets will be sent in response to packets
57966+ sent to ports for which no associated listening process exists.
57967+ This feature supports both IPV4 and IPV6 and exempts the
57968+ loopback interface from blackholing. Enabling this feature
57969+ makes a host more resilient to DoS attacks and reduces network
57970+ visibility against scanners.
57971+
57972+ The blackhole feature as-implemented is equivalent to the FreeBSD
57973+ blackhole feature, as it prevents RST responses to all packets, not
57974+ just SYNs. Under most application behavior this causes no
57975+ problems, but applications (like haproxy) may not close certain
57976+ connections in a way that cleanly terminates them on the remote
57977+ end, leaving the remote host in LAST_ACK state. Because of this
57978+ side-effect and to prevent intentional LAST_ACK DoSes, this
57979+ feature also adds automatic mitigation against such attacks.
57980+ The mitigation drastically reduces the amount of time a socket
57981+ can spend in LAST_ACK state. If you're using haproxy and not
57982+ all servers it connects to have this option enabled, consider
57983+ disabling this feature on the haproxy host.
57984+
57985+ If the sysctl option is enabled, two sysctl options with names
57986+ "ip_blackhole" and "lastack_retries" will be created.
57987+ While "ip_blackhole" takes the standard zero/non-zero on/off
57988+ toggle, "lastack_retries" uses the same kinds of values as
57989+ "tcp_retries1" and "tcp_retries2". The default value of 4
57990+ prevents a socket from lasting more than 45 seconds in LAST_ACK
57991+ state.
57992+
57993+config GRKERNSEC_NO_SIMULT_CONNECT
57994+ bool "Disable TCP Simultaneous Connect"
57995+ default y if GRKERNSEC_CONFIG_AUTO
57996+ depends on NET
57997+ help
57998+ If you say Y here, a feature by Willy Tarreau will be enabled that
57999+ removes a weakness in Linux's strict implementation of TCP that
58000+ allows two clients to connect to each other without either entering
58001+ a listening state. The weakness allows an attacker to easily prevent
58002+ a client from connecting to a known server provided the source port
58003+ for the connection is guessed correctly.
58004+
58005+ As the weakness could be used to prevent an antivirus or IPS from
58006+ fetching updates, or prevent an SSL gateway from fetching a CRL,
58007+ it should be eliminated by enabling this option. Though Linux is
58008+ one of few operating systems supporting simultaneous connect, it
58009+ has no legitimate use in practice and is rarely supported by firewalls.
58010+
58011+config GRKERNSEC_SOCKET
58012+ bool "Socket restrictions"
58013+ depends on NET
58014+ help
58015+ If you say Y here, you will be able to choose from several options.
58016+ If you assign a GID on your system and add it to the supplementary
58017+ groups of users you want to restrict socket access to, this patch
58018+ will perform up to three things, based on the option(s) you choose.
58019+
58020+config GRKERNSEC_SOCKET_ALL
58021+ bool "Deny any sockets to group"
58022+ depends on GRKERNSEC_SOCKET
58023+ help
58024+ If you say Y here, you will be able to choose a GID of whose users will
58025+ be unable to connect to other hosts from your machine or run server
58026+ applications from your machine. If the sysctl option is enabled, a
58027+ sysctl option with name "socket_all" is created.
58028+
58029+config GRKERNSEC_SOCKET_ALL_GID
58030+ int "GID to deny all sockets for"
58031+ depends on GRKERNSEC_SOCKET_ALL
58032+ default 1004
58033+ help
58034+ Here you can choose the GID to disable socket access for. Remember to
58035+ add the users you want socket access disabled for to the GID
58036+ specified here. If the sysctl option is enabled, a sysctl option
58037+ with name "socket_all_gid" is created.
58038+
58039+config GRKERNSEC_SOCKET_CLIENT
58040+ bool "Deny client sockets to group"
58041+ depends on GRKERNSEC_SOCKET
58042+ help
58043+ If you say Y here, you will be able to choose a GID of whose users will
58044+ be unable to connect to other hosts from your machine, but will be
58045+ able to run servers. If this option is enabled, all users in the group
58046+ you specify will have to use passive mode when initiating ftp transfers
58047+ from the shell on your machine. If the sysctl option is enabled, a
58048+ sysctl option with name "socket_client" is created.
58049+
58050+config GRKERNSEC_SOCKET_CLIENT_GID
58051+ int "GID to deny client sockets for"
58052+ depends on GRKERNSEC_SOCKET_CLIENT
58053+ default 1003
58054+ help
58055+ Here you can choose the GID to disable client socket access for.
58056+ Remember to add the users you want client socket access disabled for to
58057+ the GID specified here. If the sysctl option is enabled, a sysctl
58058+ option with name "socket_client_gid" is created.
58059+
58060+config GRKERNSEC_SOCKET_SERVER
58061+ bool "Deny server sockets to group"
58062+ depends on GRKERNSEC_SOCKET
58063+ help
58064+ If you say Y here, you will be able to choose a GID of whose users will
58065+ be unable to run server applications from your machine. If the sysctl
58066+ option is enabled, a sysctl option with name "socket_server" is created.
58067+
58068+config GRKERNSEC_SOCKET_SERVER_GID
58069+ int "GID to deny server sockets for"
58070+ depends on GRKERNSEC_SOCKET_SERVER
58071+ default 1002
58072+ help
58073+ Here you can choose the GID to disable server socket access for.
58074+ Remember to add the users you want server socket access disabled for to
58075+ the GID specified here. If the sysctl option is enabled, a sysctl
58076+ option with name "socket_server_gid" is created.
58077+
58078+endmenu
58079+menu "Sysctl Support"
58080+depends on GRKERNSEC && SYSCTL
58081+
58082+config GRKERNSEC_SYSCTL
58083+ bool "Sysctl support"
58084+ default y if GRKERNSEC_CONFIG_AUTO
58085+ help
58086+ If you say Y here, you will be able to change the options that
58087+ grsecurity runs with at bootup, without having to recompile your
58088+ kernel. You can echo values to files in /proc/sys/kernel/grsecurity
58089+ to enable (1) or disable (0) various features. All the sysctl entries
58090+ are mutable until the "grsec_lock" entry is set to a non-zero value.
58091+ All features enabled in the kernel configuration are disabled at boot
58092+ if you do not say Y to the "Turn on features by default" option.
58093+ All options should be set at startup, and the grsec_lock entry should
58094+ be set to a non-zero value after all the options are set.
58095+ *THIS IS EXTREMELY IMPORTANT*
58096+
58097+config GRKERNSEC_SYSCTL_DISTRO
58098+ bool "Extra sysctl support for distro makers (READ HELP)"
58099+ depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
58100+ help
58101+ If you say Y here, additional sysctl options will be created
58102+ for features that affect processes running as root. Therefore,
58103+ it is critical when using this option that the grsec_lock entry be
58104+ enabled after boot. Only distros with prebuilt kernel packages
58105+ with this option enabled that can ensure grsec_lock is enabled
58106+ after boot should use this option.
58107+ *Failure to set grsec_lock after boot makes all grsec features
58108+ this option covers useless*
58109+
58110+ Currently this option creates the following sysctl entries:
58111+ "Disable Privileged I/O": "disable_priv_io"
58112+
58113+config GRKERNSEC_SYSCTL_ON
58114+ bool "Turn on features by default"
58115+ default y if GRKERNSEC_CONFIG_AUTO
58116+ depends on GRKERNSEC_SYSCTL
58117+ help
58118+ If you say Y here, instead of having all features enabled in the
58119+ kernel configuration disabled at boot time, the features will be
58120+ enabled at boot time. It is recommended you say Y here unless
58121+ there is some reason you would want all sysctl-tunable features to
58122+ be disabled by default. As mentioned elsewhere, it is important
58123+ to enable the grsec_lock entry once you have finished modifying
58124+ the sysctl entries.
58125+
58126+endmenu
58127+menu "Logging Options"
58128+depends on GRKERNSEC
58129+
58130+config GRKERNSEC_FLOODTIME
58131+ int "Seconds in between log messages (minimum)"
58132+ default 10
58133+ help
58134+ This option allows you to enforce the number of seconds between
58135+ grsecurity log messages. The default should be suitable for most
58136+ people, however, if you choose to change it, choose a value small enough
58137+ to allow informative logs to be produced, but large enough to
58138+ prevent flooding.
58139+
58140+config GRKERNSEC_FLOODBURST
58141+ int "Number of messages in a burst (maximum)"
58142+ default 6
58143+ help
58144+ This option allows you to choose the maximum number of messages allowed
58145+ within the flood time interval you chose in a separate option. The
58146+ default should be suitable for most people, however if you find that
58147+ many of your logs are being interpreted as flooding, you may want to
58148+ raise this value.
58149+
58150+endmenu
58151diff --git a/grsecurity/Makefile b/grsecurity/Makefile
58152new file mode 100644
58153index 0000000..1b9afa9
58154--- /dev/null
58155+++ b/grsecurity/Makefile
58156@@ -0,0 +1,38 @@
58157+# grsecurity's ACL system was originally written in 2001 by Michael Dalton
58158+# during 2001-2009 it has been completely redesigned by Brad Spengler
58159+# into an RBAC system
58160+#
58161+# All code in this directory and various hooks inserted throughout the kernel
58162+# are copyright Brad Spengler - Open Source Security, Inc., and released
58163+# under the GPL v2 or higher
58164+
58165+KBUILD_CFLAGS += -Werror
58166+
58167+obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
58168+ grsec_mount.o grsec_sig.o grsec_sysctl.o \
58169+ grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
58170+
58171+obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
58172+ gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
58173+ gracl_learn.o grsec_log.o
58174+obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
58175+
58176+ifdef CONFIG_NET
58177+obj-y += grsec_sock.o
58178+obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
58179+endif
58180+
58181+ifndef CONFIG_GRKERNSEC
58182+obj-y += grsec_disabled.o
58183+endif
58184+
58185+ifdef CONFIG_GRKERNSEC_HIDESYM
58186+extra-y := grsec_hidesym.o
58187+$(obj)/grsec_hidesym.o:
58188+ @-chmod -f 500 /boot
58189+ @-chmod -f 500 /lib/modules
58190+ @-chmod -f 500 /lib64/modules
58191+ @-chmod -f 500 /lib32/modules
58192+ @-chmod -f 700 .
58193+ @echo ' grsec: protected kernel image paths'
58194+endif
58195diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
58196new file mode 100644
58197index 0000000..1248ee0
58198--- /dev/null
58199+++ b/grsecurity/gracl.c
58200@@ -0,0 +1,4073 @@
58201+#include <linux/kernel.h>
58202+#include <linux/module.h>
58203+#include <linux/sched.h>
58204+#include <linux/mm.h>
58205+#include <linux/file.h>
58206+#include <linux/fs.h>
58207+#include <linux/namei.h>
58208+#include <linux/mount.h>
58209+#include <linux/tty.h>
58210+#include <linux/proc_fs.h>
58211+#include <linux/lglock.h>
58212+#include <linux/slab.h>
58213+#include <linux/vmalloc.h>
58214+#include <linux/types.h>
58215+#include <linux/sysctl.h>
58216+#include <linux/netdevice.h>
58217+#include <linux/ptrace.h>
58218+#include <linux/gracl.h>
58219+#include <linux/gralloc.h>
58220+#include <linux/security.h>
58221+#include <linux/grinternal.h>
58222+#include <linux/pid_namespace.h>
58223+#include <linux/stop_machine.h>
58224+#include <linux/fdtable.h>
58225+#include <linux/percpu.h>
58226+#include <linux/lglock.h>
58227+#include <linux/hugetlb.h>
58228+#include <linux/posix-timers.h>
58229+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58230+#include <linux/magic.h>
58231+#include <linux/pagemap.h>
58232+#include "../fs/btrfs/async-thread.h"
58233+#include "../fs/btrfs/ctree.h"
58234+#include "../fs/btrfs/btrfs_inode.h"
58235+#endif
58236+#include "../fs/mount.h"
58237+
58238+#include <asm/uaccess.h>
58239+#include <asm/errno.h>
58240+#include <asm/mman.h>
58241+
58242+extern struct lglock vfsmount_lock;
58243+
58244+static struct acl_role_db acl_role_set;
58245+static struct name_db name_set;
58246+static struct inodev_db inodev_set;
58247+
58248+/* for keeping track of userspace pointers used for subjects, so we
58249+ can share references in the kernel as well
58250+*/
58251+
58252+static struct path real_root;
58253+
58254+static struct acl_subj_map_db subj_map_set;
58255+
58256+static struct acl_role_label *default_role;
58257+
58258+static struct acl_role_label *role_list;
58259+
58260+static u16 acl_sp_role_value;
58261+
58262+extern char *gr_shared_page[4];
58263+static DEFINE_MUTEX(gr_dev_mutex);
58264+DEFINE_RWLOCK(gr_inode_lock);
58265+
58266+struct gr_arg *gr_usermode;
58267+
58268+static unsigned int gr_status __read_only = GR_STATUS_INIT;
58269+
58270+extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
58271+extern void gr_clear_learn_entries(void);
58272+
58273+unsigned char *gr_system_salt;
58274+unsigned char *gr_system_sum;
58275+
58276+static struct sprole_pw **acl_special_roles = NULL;
58277+static __u16 num_sprole_pws = 0;
58278+
58279+static struct acl_role_label *kernel_role = NULL;
58280+
58281+static unsigned int gr_auth_attempts = 0;
58282+static unsigned long gr_auth_expires = 0UL;
58283+
58284+#ifdef CONFIG_NET
58285+extern struct vfsmount *sock_mnt;
58286+#endif
58287+
58288+extern struct vfsmount *pipe_mnt;
58289+extern struct vfsmount *shm_mnt;
58290+
58291+#ifdef CONFIG_HUGETLBFS
58292+extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
58293+#endif
58294+
58295+static struct acl_object_label *fakefs_obj_rw;
58296+static struct acl_object_label *fakefs_obj_rwx;
58297+
58298+extern int gr_init_uidset(void);
58299+extern void gr_free_uidset(void);
58300+extern void gr_remove_uid(uid_t uid);
58301+extern int gr_find_uid(uid_t uid);
58302+
58303+__inline__ int
58304+gr_acl_is_enabled(void)
58305+{
58306+ return (gr_status & GR_READY);
58307+}
58308+
58309+static inline dev_t __get_dev(const struct dentry *dentry)
58310+{
58311+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
58312+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
58313+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
58314+ else
58315+#endif
58316+ return dentry->d_sb->s_dev;
58317+}
58318+
58319+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58320+{
58321+ return __get_dev(dentry);
58322+}
58323+
58324+static char gr_task_roletype_to_char(struct task_struct *task)
58325+{
58326+ switch (task->role->roletype &
58327+ (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
58328+ GR_ROLE_SPECIAL)) {
58329+ case GR_ROLE_DEFAULT:
58330+ return 'D';
58331+ case GR_ROLE_USER:
58332+ return 'U';
58333+ case GR_ROLE_GROUP:
58334+ return 'G';
58335+ case GR_ROLE_SPECIAL:
58336+ return 'S';
58337+ }
58338+
58339+ return 'X';
58340+}
58341+
58342+char gr_roletype_to_char(void)
58343+{
58344+ return gr_task_roletype_to_char(current);
58345+}
58346+
58347+__inline__ int
58348+gr_acl_tpe_check(void)
58349+{
58350+ if (unlikely(!(gr_status & GR_READY)))
58351+ return 0;
58352+ if (current->role->roletype & GR_ROLE_TPE)
58353+ return 1;
58354+ else
58355+ return 0;
58356+}
58357+
58358+int
58359+gr_handle_rawio(const struct inode *inode)
58360+{
58361+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58362+ if (inode && S_ISBLK(inode->i_mode) &&
58363+ grsec_enable_chroot_caps && proc_is_chrooted(current) &&
58364+ !capable(CAP_SYS_RAWIO))
58365+ return 1;
58366+#endif
58367+ return 0;
58368+}
58369+
58370+static int
58371+gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
58372+{
58373+ if (likely(lena != lenb))
58374+ return 0;
58375+
58376+ return !memcmp(a, b, lena);
58377+}
58378+
58379+static int prepend(char **buffer, int *buflen, const char *str, int namelen)
58380+{
58381+ *buflen -= namelen;
58382+ if (*buflen < 0)
58383+ return -ENAMETOOLONG;
58384+ *buffer -= namelen;
58385+ memcpy(*buffer, str, namelen);
58386+ return 0;
58387+}
58388+
58389+static int prepend_name(char **buffer, int *buflen, struct qstr *name)
58390+{
58391+ return prepend(buffer, buflen, name->name, name->len);
58392+}
58393+
58394+static int prepend_path(const struct path *path, struct path *root,
58395+ char **buffer, int *buflen)
58396+{
58397+ struct dentry *dentry = path->dentry;
58398+ struct vfsmount *vfsmnt = path->mnt;
58399+ struct mount *mnt = real_mount(vfsmnt);
58400+ bool slash = false;
58401+ int error = 0;
58402+
58403+ while (dentry != root->dentry || vfsmnt != root->mnt) {
58404+ struct dentry * parent;
58405+
58406+ if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
58407+ /* Global root? */
58408+ if (!mnt_has_parent(mnt)) {
58409+ goto out;
58410+ }
58411+ dentry = mnt->mnt_mountpoint;
58412+ mnt = mnt->mnt_parent;
58413+ vfsmnt = &mnt->mnt;
58414+ continue;
58415+ }
58416+ parent = dentry->d_parent;
58417+ prefetch(parent);
58418+ spin_lock(&dentry->d_lock);
58419+ error = prepend_name(buffer, buflen, &dentry->d_name);
58420+ spin_unlock(&dentry->d_lock);
58421+ if (!error)
58422+ error = prepend(buffer, buflen, "/", 1);
58423+ if (error)
58424+ break;
58425+
58426+ slash = true;
58427+ dentry = parent;
58428+ }
58429+
58430+out:
58431+ if (!error && !slash)
58432+ error = prepend(buffer, buflen, "/", 1);
58433+
58434+ return error;
58435+}
58436+
58437+/* this must be called with vfsmount_lock and rename_lock held */
58438+
58439+static char *__our_d_path(const struct path *path, struct path *root,
58440+ char *buf, int buflen)
58441+{
58442+ char *res = buf + buflen;
58443+ int error;
58444+
58445+ prepend(&res, &buflen, "\0", 1);
58446+ error = prepend_path(path, root, &res, &buflen);
58447+ if (error)
58448+ return ERR_PTR(error);
58449+
58450+ return res;
58451+}
58452+
58453+static char *
58454+gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
58455+{
58456+ char *retval;
58457+
58458+ retval = __our_d_path(path, root, buf, buflen);
58459+ if (unlikely(IS_ERR(retval)))
58460+ retval = strcpy(buf, "<path too long>");
58461+ else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
58462+ retval[1] = '\0';
58463+
58464+ return retval;
58465+}
58466+
58467+static char *
58468+__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58469+ char *buf, int buflen)
58470+{
58471+ struct path path;
58472+ char *res;
58473+
58474+ path.dentry = (struct dentry *)dentry;
58475+ path.mnt = (struct vfsmount *)vfsmnt;
58476+
58477+ /* we can use real_root.dentry, real_root.mnt, because this is only called
58478+ by the RBAC system */
58479+ res = gen_full_path(&path, &real_root, buf, buflen);
58480+
58481+ return res;
58482+}
58483+
58484+static char *
58485+d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
58486+ char *buf, int buflen)
58487+{
58488+ char *res;
58489+ struct path path;
58490+ struct path root;
58491+ struct task_struct *reaper = init_pid_ns.child_reaper;
58492+
58493+ path.dentry = (struct dentry *)dentry;
58494+ path.mnt = (struct vfsmount *)vfsmnt;
58495+
58496+ /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
58497+ get_fs_root(reaper->fs, &root);
58498+
58499+ br_read_lock(&vfsmount_lock);
58500+ write_seqlock(&rename_lock);
58501+ res = gen_full_path(&path, &root, buf, buflen);
58502+ write_sequnlock(&rename_lock);
58503+ br_read_unlock(&vfsmount_lock);
58504+
58505+ path_put(&root);
58506+ return res;
58507+}
58508+
58509+static char *
58510+gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58511+{
58512+ char *ret;
58513+ br_read_lock(&vfsmount_lock);
58514+ write_seqlock(&rename_lock);
58515+ ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58516+ PAGE_SIZE);
58517+ write_sequnlock(&rename_lock);
58518+ br_read_unlock(&vfsmount_lock);
58519+ return ret;
58520+}
58521+
58522+static char *
58523+gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
58524+{
58525+ char *ret;
58526+ char *buf;
58527+ int buflen;
58528+
58529+ br_read_lock(&vfsmount_lock);
58530+ write_seqlock(&rename_lock);
58531+ buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
58532+ ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
58533+ buflen = (int)(ret - buf);
58534+ if (buflen >= 5)
58535+ prepend(&ret, &buflen, "/proc", 5);
58536+ else
58537+ ret = strcpy(buf, "<path too long>");
58538+ write_sequnlock(&rename_lock);
58539+ br_read_unlock(&vfsmount_lock);
58540+ return ret;
58541+}
58542+
58543+char *
58544+gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
58545+{
58546+ return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
58547+ PAGE_SIZE);
58548+}
58549+
58550+char *
58551+gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
58552+{
58553+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
58554+ PAGE_SIZE);
58555+}
58556+
58557+char *
58558+gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
58559+{
58560+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
58561+ PAGE_SIZE);
58562+}
58563+
58564+char *
58565+gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
58566+{
58567+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
58568+ PAGE_SIZE);
58569+}
58570+
58571+char *
58572+gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
58573+{
58574+ return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
58575+ PAGE_SIZE);
58576+}
58577+
58578+__inline__ __u32
58579+to_gr_audit(const __u32 reqmode)
58580+{
58581+ /* masks off auditable permission flags, then shifts them to create
58582+ auditing flags, and adds the special case of append auditing if
58583+ we're requesting write */
58584+ return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
58585+}
58586+
58587+struct acl_subject_label *
58588+lookup_subject_map(const struct acl_subject_label *userp)
58589+{
58590+ unsigned int index = gr_shash(userp, subj_map_set.s_size);
58591+ struct subject_map *match;
58592+
58593+ match = subj_map_set.s_hash[index];
58594+
58595+ while (match && match->user != userp)
58596+ match = match->next;
58597+
58598+ if (match != NULL)
58599+ return match->kernel;
58600+ else
58601+ return NULL;
58602+}
58603+
58604+static void
58605+insert_subj_map_entry(struct subject_map *subjmap)
58606+{
58607+ unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
58608+ struct subject_map **curr;
58609+
58610+ subjmap->prev = NULL;
58611+
58612+ curr = &subj_map_set.s_hash[index];
58613+ if (*curr != NULL)
58614+ (*curr)->prev = subjmap;
58615+
58616+ subjmap->next = *curr;
58617+ *curr = subjmap;
58618+
58619+ return;
58620+}
58621+
58622+static struct acl_role_label *
58623+lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
58624+ const gid_t gid)
58625+{
58626+ unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
58627+ struct acl_role_label *match;
58628+ struct role_allowed_ip *ipp;
58629+ unsigned int x;
58630+ u32 curr_ip = task->signal->curr_ip;
58631+
58632+ task->signal->saved_ip = curr_ip;
58633+
58634+ match = acl_role_set.r_hash[index];
58635+
58636+ while (match) {
58637+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
58638+ for (x = 0; x < match->domain_child_num; x++) {
58639+ if (match->domain_children[x] == uid)
58640+ goto found;
58641+ }
58642+ } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
58643+ break;
58644+ match = match->next;
58645+ }
58646+found:
58647+ if (match == NULL) {
58648+ try_group:
58649+ index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
58650+ match = acl_role_set.r_hash[index];
58651+
58652+ while (match) {
58653+ if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
58654+ for (x = 0; x < match->domain_child_num; x++) {
58655+ if (match->domain_children[x] == gid)
58656+ goto found2;
58657+ }
58658+ } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
58659+ break;
58660+ match = match->next;
58661+ }
58662+found2:
58663+ if (match == NULL)
58664+ match = default_role;
58665+ if (match->allowed_ips == NULL)
58666+ return match;
58667+ else {
58668+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58669+ if (likely
58670+ ((ntohl(curr_ip) & ipp->netmask) ==
58671+ (ntohl(ipp->addr) & ipp->netmask)))
58672+ return match;
58673+ }
58674+ match = default_role;
58675+ }
58676+ } else if (match->allowed_ips == NULL) {
58677+ return match;
58678+ } else {
58679+ for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
58680+ if (likely
58681+ ((ntohl(curr_ip) & ipp->netmask) ==
58682+ (ntohl(ipp->addr) & ipp->netmask)))
58683+ return match;
58684+ }
58685+ goto try_group;
58686+ }
58687+
58688+ return match;
58689+}
58690+
58691+struct acl_subject_label *
58692+lookup_acl_subj_label(const ino_t ino, const dev_t dev,
58693+ const struct acl_role_label *role)
58694+{
58695+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58696+ struct acl_subject_label *match;
58697+
58698+ match = role->subj_hash[index];
58699+
58700+ while (match && (match->inode != ino || match->device != dev ||
58701+ (match->mode & GR_DELETED))) {
58702+ match = match->next;
58703+ }
58704+
58705+ if (match && !(match->mode & GR_DELETED))
58706+ return match;
58707+ else
58708+ return NULL;
58709+}
58710+
58711+struct acl_subject_label *
58712+lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
58713+ const struct acl_role_label *role)
58714+{
58715+ unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
58716+ struct acl_subject_label *match;
58717+
58718+ match = role->subj_hash[index];
58719+
58720+ while (match && (match->inode != ino || match->device != dev ||
58721+ !(match->mode & GR_DELETED))) {
58722+ match = match->next;
58723+ }
58724+
58725+ if (match && (match->mode & GR_DELETED))
58726+ return match;
58727+ else
58728+ return NULL;
58729+}
58730+
58731+static struct acl_object_label *
58732+lookup_acl_obj_label(const ino_t ino, const dev_t dev,
58733+ const struct acl_subject_label *subj)
58734+{
58735+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58736+ struct acl_object_label *match;
58737+
58738+ match = subj->obj_hash[index];
58739+
58740+ while (match && (match->inode != ino || match->device != dev ||
58741+ (match->mode & GR_DELETED))) {
58742+ match = match->next;
58743+ }
58744+
58745+ if (match && !(match->mode & GR_DELETED))
58746+ return match;
58747+ else
58748+ return NULL;
58749+}
58750+
58751+static struct acl_object_label *
58752+lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
58753+ const struct acl_subject_label *subj)
58754+{
58755+ unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
58756+ struct acl_object_label *match;
58757+
58758+ match = subj->obj_hash[index];
58759+
58760+ while (match && (match->inode != ino || match->device != dev ||
58761+ !(match->mode & GR_DELETED))) {
58762+ match = match->next;
58763+ }
58764+
58765+ if (match && (match->mode & GR_DELETED))
58766+ return match;
58767+
58768+ match = subj->obj_hash[index];
58769+
58770+ while (match && (match->inode != ino || match->device != dev ||
58771+ (match->mode & GR_DELETED))) {
58772+ match = match->next;
58773+ }
58774+
58775+ if (match && !(match->mode & GR_DELETED))
58776+ return match;
58777+ else
58778+ return NULL;
58779+}
58780+
58781+static struct name_entry *
58782+lookup_name_entry(const char *name)
58783+{
58784+ unsigned int len = strlen(name);
58785+ unsigned int key = full_name_hash(name, len);
58786+ unsigned int index = key % name_set.n_size;
58787+ struct name_entry *match;
58788+
58789+ match = name_set.n_hash[index];
58790+
58791+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
58792+ match = match->next;
58793+
58794+ return match;
58795+}
58796+
58797+static struct name_entry *
58798+lookup_name_entry_create(const char *name)
58799+{
58800+ unsigned int len = strlen(name);
58801+ unsigned int key = full_name_hash(name, len);
58802+ unsigned int index = key % name_set.n_size;
58803+ struct name_entry *match;
58804+
58805+ match = name_set.n_hash[index];
58806+
58807+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58808+ !match->deleted))
58809+ match = match->next;
58810+
58811+ if (match && match->deleted)
58812+ return match;
58813+
58814+ match = name_set.n_hash[index];
58815+
58816+ while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
58817+ match->deleted))
58818+ match = match->next;
58819+
58820+ if (match && !match->deleted)
58821+ return match;
58822+ else
58823+ return NULL;
58824+}
58825+
58826+static struct inodev_entry *
58827+lookup_inodev_entry(const ino_t ino, const dev_t dev)
58828+{
58829+ unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
58830+ struct inodev_entry *match;
58831+
58832+ match = inodev_set.i_hash[index];
58833+
58834+ while (match && (match->nentry->inode != ino || match->nentry->device != dev))
58835+ match = match->next;
58836+
58837+ return match;
58838+}
58839+
58840+static void
58841+insert_inodev_entry(struct inodev_entry *entry)
58842+{
58843+ unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
58844+ inodev_set.i_size);
58845+ struct inodev_entry **curr;
58846+
58847+ entry->prev = NULL;
58848+
58849+ curr = &inodev_set.i_hash[index];
58850+ if (*curr != NULL)
58851+ (*curr)->prev = entry;
58852+
58853+ entry->next = *curr;
58854+ *curr = entry;
58855+
58856+ return;
58857+}
58858+
58859+static void
58860+__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
58861+{
58862+ unsigned int index =
58863+ gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
58864+ struct acl_role_label **curr;
58865+ struct acl_role_label *tmp, *tmp2;
58866+
58867+ curr = &acl_role_set.r_hash[index];
58868+
58869+ /* simple case, slot is empty, just set it to our role */
58870+ if (*curr == NULL) {
58871+ *curr = role;
58872+ } else {
58873+ /* example:
58874+ 1 -> 2 -> 3 (adding 2 -> 3 to here)
58875+ 2 -> 3
58876+ */
58877+ /* first check to see if we can already be reached via this slot */
58878+ tmp = *curr;
58879+ while (tmp && tmp != role)
58880+ tmp = tmp->next;
58881+ if (tmp == role) {
58882+ /* we don't need to add ourselves to this slot's chain */
58883+ return;
58884+ }
58885+ /* we need to add ourselves to this chain, two cases */
58886+ if (role->next == NULL) {
58887+ /* simple case, append the current chain to our role */
58888+ role->next = *curr;
58889+ *curr = role;
58890+ } else {
58891+ /* 1 -> 2 -> 3 -> 4
58892+ 2 -> 3 -> 4
58893+ 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
58894+ */
58895+ /* trickier case: walk our role's chain until we find
58896+ the role for the start of the current slot's chain */
58897+ tmp = role;
58898+ tmp2 = *curr;
58899+ while (tmp->next && tmp->next != tmp2)
58900+ tmp = tmp->next;
58901+ if (tmp->next == tmp2) {
58902+ /* from example above, we found 3, so just
58903+ replace this slot's chain with ours */
58904+ *curr = role;
58905+ } else {
58906+ /* we didn't find a subset of our role's chain
58907+ in the current slot's chain, so append their
58908+ chain to ours, and set us as the first role in
58909+ the slot's chain
58910+
58911+ we could fold this case with the case above,
58912+ but making it explicit for clarity
58913+ */
58914+ tmp->next = tmp2;
58915+ *curr = role;
58916+ }
58917+ }
58918+ }
58919+
58920+ return;
58921+}
58922+
58923+static void
58924+insert_acl_role_label(struct acl_role_label *role)
58925+{
58926+ int i;
58927+
58928+ if (role_list == NULL) {
58929+ role_list = role;
58930+ role->prev = NULL;
58931+ } else {
58932+ role->prev = role_list;
58933+ role_list = role;
58934+ }
58935+
58936+ /* used for hash chains */
58937+ role->next = NULL;
58938+
58939+ if (role->roletype & GR_ROLE_DOMAIN) {
58940+ for (i = 0; i < role->domain_child_num; i++)
58941+ __insert_acl_role_label(role, role->domain_children[i]);
58942+ } else
58943+ __insert_acl_role_label(role, role->uidgid);
58944+}
58945+
58946+static int
58947+insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
58948+{
58949+ struct name_entry **curr, *nentry;
58950+ struct inodev_entry *ientry;
58951+ unsigned int len = strlen(name);
58952+ unsigned int key = full_name_hash(name, len);
58953+ unsigned int index = key % name_set.n_size;
58954+
58955+ curr = &name_set.n_hash[index];
58956+
58957+ while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
58958+ curr = &((*curr)->next);
58959+
58960+ if (*curr != NULL)
58961+ return 1;
58962+
58963+ nentry = acl_alloc(sizeof (struct name_entry));
58964+ if (nentry == NULL)
58965+ return 0;
58966+ ientry = acl_alloc(sizeof (struct inodev_entry));
58967+ if (ientry == NULL)
58968+ return 0;
58969+ ientry->nentry = nentry;
58970+
58971+ nentry->key = key;
58972+ nentry->name = name;
58973+ nentry->inode = inode;
58974+ nentry->device = device;
58975+ nentry->len = len;
58976+ nentry->deleted = deleted;
58977+
58978+ nentry->prev = NULL;
58979+ curr = &name_set.n_hash[index];
58980+ if (*curr != NULL)
58981+ (*curr)->prev = nentry;
58982+ nentry->next = *curr;
58983+ *curr = nentry;
58984+
58985+ /* insert us into the table searchable by inode/dev */
58986+ insert_inodev_entry(ientry);
58987+
58988+ return 1;
58989+}
58990+
58991+static void
58992+insert_acl_obj_label(struct acl_object_label *obj,
58993+ struct acl_subject_label *subj)
58994+{
58995+ unsigned int index =
58996+ gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
58997+ struct acl_object_label **curr;
58998+
58999+
59000+ obj->prev = NULL;
59001+
59002+ curr = &subj->obj_hash[index];
59003+ if (*curr != NULL)
59004+ (*curr)->prev = obj;
59005+
59006+ obj->next = *curr;
59007+ *curr = obj;
59008+
59009+ return;
59010+}
59011+
59012+static void
59013+insert_acl_subj_label(struct acl_subject_label *obj,
59014+ struct acl_role_label *role)
59015+{
59016+ unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
59017+ struct acl_subject_label **curr;
59018+
59019+ obj->prev = NULL;
59020+
59021+ curr = &role->subj_hash[index];
59022+ if (*curr != NULL)
59023+ (*curr)->prev = obj;
59024+
59025+ obj->next = *curr;
59026+ *curr = obj;
59027+
59028+ return;
59029+}
59030+
59031+/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
59032+
59033+static void *
59034+create_table(__u32 * len, int elementsize)
59035+{
59036+ unsigned int table_sizes[] = {
59037+ 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
59038+ 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
59039+ 4194301, 8388593, 16777213, 33554393, 67108859
59040+ };
59041+ void *newtable = NULL;
59042+ unsigned int pwr = 0;
59043+
59044+ while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
59045+ table_sizes[pwr] <= *len)
59046+ pwr++;
59047+
59048+ if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
59049+ return newtable;
59050+
59051+ if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
59052+ newtable =
59053+ kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
59054+ else
59055+ newtable = vmalloc(table_sizes[pwr] * elementsize);
59056+
59057+ *len = table_sizes[pwr];
59058+
59059+ return newtable;
59060+}
59061+
59062+static int
59063+init_variables(const struct gr_arg *arg)
59064+{
59065+ struct task_struct *reaper = init_pid_ns.child_reaper;
59066+ unsigned int stacksize;
59067+
59068+ subj_map_set.s_size = arg->role_db.num_subjects;
59069+ acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
59070+ name_set.n_size = arg->role_db.num_objects;
59071+ inodev_set.i_size = arg->role_db.num_objects;
59072+
59073+ if (!subj_map_set.s_size || !acl_role_set.r_size ||
59074+ !name_set.n_size || !inodev_set.i_size)
59075+ return 1;
59076+
59077+ if (!gr_init_uidset())
59078+ return 1;
59079+
59080+ /* set up the stack that holds allocation info */
59081+
59082+ stacksize = arg->role_db.num_pointers + 5;
59083+
59084+ if (!acl_alloc_stack_init(stacksize))
59085+ return 1;
59086+
59087+ /* grab reference for the real root dentry and vfsmount */
59088+ get_fs_root(reaper->fs, &real_root);
59089+
59090+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59091+ printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
59092+#endif
59093+
59094+ fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
59095+ if (fakefs_obj_rw == NULL)
59096+ return 1;
59097+ fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
59098+
59099+ fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
59100+ if (fakefs_obj_rwx == NULL)
59101+ return 1;
59102+ fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
59103+
59104+ subj_map_set.s_hash =
59105+ (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
59106+ acl_role_set.r_hash =
59107+ (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
59108+ name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
59109+ inodev_set.i_hash =
59110+ (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
59111+
59112+ if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
59113+ !name_set.n_hash || !inodev_set.i_hash)
59114+ return 1;
59115+
59116+ memset(subj_map_set.s_hash, 0,
59117+ sizeof(struct subject_map *) * subj_map_set.s_size);
59118+ memset(acl_role_set.r_hash, 0,
59119+ sizeof (struct acl_role_label *) * acl_role_set.r_size);
59120+ memset(name_set.n_hash, 0,
59121+ sizeof (struct name_entry *) * name_set.n_size);
59122+ memset(inodev_set.i_hash, 0,
59123+ sizeof (struct inodev_entry *) * inodev_set.i_size);
59124+
59125+ return 0;
59126+}
59127+
59128+/* free information not needed after startup
59129+ currently contains user->kernel pointer mappings for subjects
59130+*/
59131+
59132+static void
59133+free_init_variables(void)
59134+{
59135+ __u32 i;
59136+
59137+ if (subj_map_set.s_hash) {
59138+ for (i = 0; i < subj_map_set.s_size; i++) {
59139+ if (subj_map_set.s_hash[i]) {
59140+ kfree(subj_map_set.s_hash[i]);
59141+ subj_map_set.s_hash[i] = NULL;
59142+ }
59143+ }
59144+
59145+ if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
59146+ PAGE_SIZE)
59147+ kfree(subj_map_set.s_hash);
59148+ else
59149+ vfree(subj_map_set.s_hash);
59150+ }
59151+
59152+ return;
59153+}
59154+
59155+static void
59156+free_variables(void)
59157+{
59158+ struct acl_subject_label *s;
59159+ struct acl_role_label *r;
59160+ struct task_struct *task, *task2;
59161+ unsigned int x;
59162+
59163+ gr_clear_learn_entries();
59164+
59165+ read_lock(&tasklist_lock);
59166+ do_each_thread(task2, task) {
59167+ task->acl_sp_role = 0;
59168+ task->acl_role_id = 0;
59169+ task->acl = NULL;
59170+ task->role = NULL;
59171+ } while_each_thread(task2, task);
59172+ read_unlock(&tasklist_lock);
59173+
59174+ /* release the reference to the real root dentry and vfsmount */
59175+ path_put(&real_root);
59176+ memset(&real_root, 0, sizeof(real_root));
59177+
59178+ /* free all object hash tables */
59179+
59180+ FOR_EACH_ROLE_START(r)
59181+ if (r->subj_hash == NULL)
59182+ goto next_role;
59183+ FOR_EACH_SUBJECT_START(r, s, x)
59184+ if (s->obj_hash == NULL)
59185+ break;
59186+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59187+ kfree(s->obj_hash);
59188+ else
59189+ vfree(s->obj_hash);
59190+ FOR_EACH_SUBJECT_END(s, x)
59191+ FOR_EACH_NESTED_SUBJECT_START(r, s)
59192+ if (s->obj_hash == NULL)
59193+ break;
59194+ if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
59195+ kfree(s->obj_hash);
59196+ else
59197+ vfree(s->obj_hash);
59198+ FOR_EACH_NESTED_SUBJECT_END(s)
59199+ if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
59200+ kfree(r->subj_hash);
59201+ else
59202+ vfree(r->subj_hash);
59203+ r->subj_hash = NULL;
59204+next_role:
59205+ FOR_EACH_ROLE_END(r)
59206+
59207+ acl_free_all();
59208+
59209+ if (acl_role_set.r_hash) {
59210+ if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
59211+ PAGE_SIZE)
59212+ kfree(acl_role_set.r_hash);
59213+ else
59214+ vfree(acl_role_set.r_hash);
59215+ }
59216+ if (name_set.n_hash) {
59217+ if ((name_set.n_size * sizeof (struct name_entry *)) <=
59218+ PAGE_SIZE)
59219+ kfree(name_set.n_hash);
59220+ else
59221+ vfree(name_set.n_hash);
59222+ }
59223+
59224+ if (inodev_set.i_hash) {
59225+ if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
59226+ PAGE_SIZE)
59227+ kfree(inodev_set.i_hash);
59228+ else
59229+ vfree(inodev_set.i_hash);
59230+ }
59231+
59232+ gr_free_uidset();
59233+
59234+ memset(&name_set, 0, sizeof (struct name_db));
59235+ memset(&inodev_set, 0, sizeof (struct inodev_db));
59236+ memset(&acl_role_set, 0, sizeof (struct acl_role_db));
59237+ memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
59238+
59239+ default_role = NULL;
59240+ kernel_role = NULL;
59241+ role_list = NULL;
59242+
59243+ return;
59244+}
59245+
59246+static __u32
59247+count_user_objs(struct acl_object_label *userp)
59248+{
59249+ struct acl_object_label o_tmp;
59250+ __u32 num = 0;
59251+
59252+ while (userp) {
59253+ if (copy_from_user(&o_tmp, userp,
59254+ sizeof (struct acl_object_label)))
59255+ break;
59256+
59257+ userp = o_tmp.prev;
59258+ num++;
59259+ }
59260+
59261+ return num;
59262+}
59263+
59264+static struct acl_subject_label *
59265+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
59266+
59267+static int
59268+copy_user_glob(struct acl_object_label *obj)
59269+{
59270+ struct acl_object_label *g_tmp, **guser;
59271+ unsigned int len;
59272+ char *tmp;
59273+
59274+ if (obj->globbed == NULL)
59275+ return 0;
59276+
59277+ guser = &obj->globbed;
59278+ while (*guser) {
59279+ g_tmp = (struct acl_object_label *)
59280+ acl_alloc(sizeof (struct acl_object_label));
59281+ if (g_tmp == NULL)
59282+ return -ENOMEM;
59283+
59284+ if (copy_from_user(g_tmp, *guser,
59285+ sizeof (struct acl_object_label)))
59286+ return -EFAULT;
59287+
59288+ len = strnlen_user(g_tmp->filename, PATH_MAX);
59289+
59290+ if (!len || len >= PATH_MAX)
59291+ return -EINVAL;
59292+
59293+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59294+ return -ENOMEM;
59295+
59296+ if (copy_from_user(tmp, g_tmp->filename, len))
59297+ return -EFAULT;
59298+ tmp[len-1] = '\0';
59299+ g_tmp->filename = tmp;
59300+
59301+ *guser = g_tmp;
59302+ guser = &(g_tmp->next);
59303+ }
59304+
59305+ return 0;
59306+}
59307+
59308+static int
59309+copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
59310+ struct acl_role_label *role)
59311+{
59312+ struct acl_object_label *o_tmp;
59313+ unsigned int len;
59314+ int ret;
59315+ char *tmp;
59316+
59317+ while (userp) {
59318+ if ((o_tmp = (struct acl_object_label *)
59319+ acl_alloc(sizeof (struct acl_object_label))) == NULL)
59320+ return -ENOMEM;
59321+
59322+ if (copy_from_user(o_tmp, userp,
59323+ sizeof (struct acl_object_label)))
59324+ return -EFAULT;
59325+
59326+ userp = o_tmp->prev;
59327+
59328+ len = strnlen_user(o_tmp->filename, PATH_MAX);
59329+
59330+ if (!len || len >= PATH_MAX)
59331+ return -EINVAL;
59332+
59333+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59334+ return -ENOMEM;
59335+
59336+ if (copy_from_user(tmp, o_tmp->filename, len))
59337+ return -EFAULT;
59338+ tmp[len-1] = '\0';
59339+ o_tmp->filename = tmp;
59340+
59341+ insert_acl_obj_label(o_tmp, subj);
59342+ if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
59343+ o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
59344+ return -ENOMEM;
59345+
59346+ ret = copy_user_glob(o_tmp);
59347+ if (ret)
59348+ return ret;
59349+
59350+ if (o_tmp->nested) {
59351+ int already_copied;
59352+
59353+ o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
59354+ if (IS_ERR(o_tmp->nested))
59355+ return PTR_ERR(o_tmp->nested);
59356+
59357+ /* insert into nested subject list if we haven't copied this one yet
59358+ to prevent duplicate entries */
59359+ if (!already_copied) {
59360+ o_tmp->nested->next = role->hash->first;
59361+ role->hash->first = o_tmp->nested;
59362+ }
59363+ }
59364+ }
59365+
59366+ return 0;
59367+}
59368+
59369+static __u32
59370+count_user_subjs(struct acl_subject_label *userp)
59371+{
59372+ struct acl_subject_label s_tmp;
59373+ __u32 num = 0;
59374+
59375+ while (userp) {
59376+ if (copy_from_user(&s_tmp, userp,
59377+ sizeof (struct acl_subject_label)))
59378+ break;
59379+
59380+ userp = s_tmp.prev;
59381+ }
59382+
59383+ return num;
59384+}
59385+
59386+static int
59387+copy_user_allowedips(struct acl_role_label *rolep)
59388+{
59389+ struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
59390+
59391+ ruserip = rolep->allowed_ips;
59392+
59393+ while (ruserip) {
59394+ rlast = rtmp;
59395+
59396+ if ((rtmp = (struct role_allowed_ip *)
59397+ acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
59398+ return -ENOMEM;
59399+
59400+ if (copy_from_user(rtmp, ruserip,
59401+ sizeof (struct role_allowed_ip)))
59402+ return -EFAULT;
59403+
59404+ ruserip = rtmp->prev;
59405+
59406+ if (!rlast) {
59407+ rtmp->prev = NULL;
59408+ rolep->allowed_ips = rtmp;
59409+ } else {
59410+ rlast->next = rtmp;
59411+ rtmp->prev = rlast;
59412+ }
59413+
59414+ if (!ruserip)
59415+ rtmp->next = NULL;
59416+ }
59417+
59418+ return 0;
59419+}
59420+
59421+static int
59422+copy_user_transitions(struct acl_role_label *rolep)
59423+{
59424+ struct role_transition *rusertp, *rtmp = NULL, *rlast;
59425+
59426+ unsigned int len;
59427+ char *tmp;
59428+
59429+ rusertp = rolep->transitions;
59430+
59431+ while (rusertp) {
59432+ rlast = rtmp;
59433+
59434+ if ((rtmp = (struct role_transition *)
59435+ acl_alloc(sizeof (struct role_transition))) == NULL)
59436+ return -ENOMEM;
59437+
59438+ if (copy_from_user(rtmp, rusertp,
59439+ sizeof (struct role_transition)))
59440+ return -EFAULT;
59441+
59442+ rusertp = rtmp->prev;
59443+
59444+ len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
59445+
59446+ if (!len || len >= GR_SPROLE_LEN)
59447+ return -EINVAL;
59448+
59449+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59450+ return -ENOMEM;
59451+
59452+ if (copy_from_user(tmp, rtmp->rolename, len))
59453+ return -EFAULT;
59454+ tmp[len-1] = '\0';
59455+ rtmp->rolename = tmp;
59456+
59457+ if (!rlast) {
59458+ rtmp->prev = NULL;
59459+ rolep->transitions = rtmp;
59460+ } else {
59461+ rlast->next = rtmp;
59462+ rtmp->prev = rlast;
59463+ }
59464+
59465+ if (!rusertp)
59466+ rtmp->next = NULL;
59467+ }
59468+
59469+ return 0;
59470+}
59471+
59472+static struct acl_subject_label *
59473+do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
59474+{
59475+ struct acl_subject_label *s_tmp = NULL, *s_tmp2;
59476+ unsigned int len;
59477+ char *tmp;
59478+ __u32 num_objs;
59479+ struct acl_ip_label **i_tmp, *i_utmp2;
59480+ struct gr_hash_struct ghash;
59481+ struct subject_map *subjmap;
59482+ unsigned int i_num;
59483+ int err;
59484+
59485+ if (already_copied != NULL)
59486+ *already_copied = 0;
59487+
59488+ s_tmp = lookup_subject_map(userp);
59489+
59490+ /* we've already copied this subject into the kernel, just return
59491+ the reference to it, and don't copy it over again
59492+ */
59493+ if (s_tmp) {
59494+ if (already_copied != NULL)
59495+ *already_copied = 1;
59496+ return(s_tmp);
59497+ }
59498+
59499+ if ((s_tmp = (struct acl_subject_label *)
59500+ acl_alloc(sizeof (struct acl_subject_label))) == NULL)
59501+ return ERR_PTR(-ENOMEM);
59502+
59503+ subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
59504+ if (subjmap == NULL)
59505+ return ERR_PTR(-ENOMEM);
59506+
59507+ subjmap->user = userp;
59508+ subjmap->kernel = s_tmp;
59509+ insert_subj_map_entry(subjmap);
59510+
59511+ if (copy_from_user(s_tmp, userp,
59512+ sizeof (struct acl_subject_label)))
59513+ return ERR_PTR(-EFAULT);
59514+
59515+ len = strnlen_user(s_tmp->filename, PATH_MAX);
59516+
59517+ if (!len || len >= PATH_MAX)
59518+ return ERR_PTR(-EINVAL);
59519+
59520+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59521+ return ERR_PTR(-ENOMEM);
59522+
59523+ if (copy_from_user(tmp, s_tmp->filename, len))
59524+ return ERR_PTR(-EFAULT);
59525+ tmp[len-1] = '\0';
59526+ s_tmp->filename = tmp;
59527+
59528+ if (!strcmp(s_tmp->filename, "/"))
59529+ role->root_label = s_tmp;
59530+
59531+ if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
59532+ return ERR_PTR(-EFAULT);
59533+
59534+ /* copy user and group transition tables */
59535+
59536+ if (s_tmp->user_trans_num) {
59537+ uid_t *uidlist;
59538+
59539+ uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
59540+ if (uidlist == NULL)
59541+ return ERR_PTR(-ENOMEM);
59542+ if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
59543+ return ERR_PTR(-EFAULT);
59544+
59545+ s_tmp->user_transitions = uidlist;
59546+ }
59547+
59548+ if (s_tmp->group_trans_num) {
59549+ gid_t *gidlist;
59550+
59551+ gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
59552+ if (gidlist == NULL)
59553+ return ERR_PTR(-ENOMEM);
59554+ if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
59555+ return ERR_PTR(-EFAULT);
59556+
59557+ s_tmp->group_transitions = gidlist;
59558+ }
59559+
59560+ /* set up object hash table */
59561+ num_objs = count_user_objs(ghash.first);
59562+
59563+ s_tmp->obj_hash_size = num_objs;
59564+ s_tmp->obj_hash =
59565+ (struct acl_object_label **)
59566+ create_table(&(s_tmp->obj_hash_size), sizeof(void *));
59567+
59568+ if (!s_tmp->obj_hash)
59569+ return ERR_PTR(-ENOMEM);
59570+
59571+ memset(s_tmp->obj_hash, 0,
59572+ s_tmp->obj_hash_size *
59573+ sizeof (struct acl_object_label *));
59574+
59575+ /* add in objects */
59576+ err = copy_user_objs(ghash.first, s_tmp, role);
59577+
59578+ if (err)
59579+ return ERR_PTR(err);
59580+
59581+ /* set pointer for parent subject */
59582+ if (s_tmp->parent_subject) {
59583+ s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
59584+
59585+ if (IS_ERR(s_tmp2))
59586+ return s_tmp2;
59587+
59588+ s_tmp->parent_subject = s_tmp2;
59589+ }
59590+
59591+ /* add in ip acls */
59592+
59593+ if (!s_tmp->ip_num) {
59594+ s_tmp->ips = NULL;
59595+ goto insert;
59596+ }
59597+
59598+ i_tmp =
59599+ (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
59600+ sizeof (struct acl_ip_label *));
59601+
59602+ if (!i_tmp)
59603+ return ERR_PTR(-ENOMEM);
59604+
59605+ for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
59606+ *(i_tmp + i_num) =
59607+ (struct acl_ip_label *)
59608+ acl_alloc(sizeof (struct acl_ip_label));
59609+ if (!*(i_tmp + i_num))
59610+ return ERR_PTR(-ENOMEM);
59611+
59612+ if (copy_from_user
59613+ (&i_utmp2, s_tmp->ips + i_num,
59614+ sizeof (struct acl_ip_label *)))
59615+ return ERR_PTR(-EFAULT);
59616+
59617+ if (copy_from_user
59618+ (*(i_tmp + i_num), i_utmp2,
59619+ sizeof (struct acl_ip_label)))
59620+ return ERR_PTR(-EFAULT);
59621+
59622+ if ((*(i_tmp + i_num))->iface == NULL)
59623+ continue;
59624+
59625+ len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
59626+ if (!len || len >= IFNAMSIZ)
59627+ return ERR_PTR(-EINVAL);
59628+ tmp = acl_alloc(len);
59629+ if (tmp == NULL)
59630+ return ERR_PTR(-ENOMEM);
59631+ if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
59632+ return ERR_PTR(-EFAULT);
59633+ (*(i_tmp + i_num))->iface = tmp;
59634+ }
59635+
59636+ s_tmp->ips = i_tmp;
59637+
59638+insert:
59639+ if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
59640+ s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
59641+ return ERR_PTR(-ENOMEM);
59642+
59643+ return s_tmp;
59644+}
59645+
59646+static int
59647+copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
59648+{
59649+ struct acl_subject_label s_pre;
59650+ struct acl_subject_label * ret;
59651+ int err;
59652+
59653+ while (userp) {
59654+ if (copy_from_user(&s_pre, userp,
59655+ sizeof (struct acl_subject_label)))
59656+ return -EFAULT;
59657+
59658+ ret = do_copy_user_subj(userp, role, NULL);
59659+
59660+ err = PTR_ERR(ret);
59661+ if (IS_ERR(ret))
59662+ return err;
59663+
59664+ insert_acl_subj_label(ret, role);
59665+
59666+ userp = s_pre.prev;
59667+ }
59668+
59669+ return 0;
59670+}
59671+
59672+static int
59673+copy_user_acl(struct gr_arg *arg)
59674+{
59675+ struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
59676+ struct acl_subject_label *subj_list;
59677+ struct sprole_pw *sptmp;
59678+ struct gr_hash_struct *ghash;
59679+ uid_t *domainlist;
59680+ unsigned int r_num;
59681+ unsigned int len;
59682+ char *tmp;
59683+ int err = 0;
59684+ __u16 i;
59685+ __u32 num_subjs;
59686+
59687+ /* we need a default and kernel role */
59688+ if (arg->role_db.num_roles < 2)
59689+ return -EINVAL;
59690+
59691+ /* copy special role authentication info from userspace */
59692+
59693+ num_sprole_pws = arg->num_sprole_pws;
59694+ acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
59695+
59696+ if (!acl_special_roles && num_sprole_pws)
59697+ return -ENOMEM;
59698+
59699+ for (i = 0; i < num_sprole_pws; i++) {
59700+ sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
59701+ if (!sptmp)
59702+ return -ENOMEM;
59703+ if (copy_from_user(sptmp, arg->sprole_pws + i,
59704+ sizeof (struct sprole_pw)))
59705+ return -EFAULT;
59706+
59707+ len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
59708+
59709+ if (!len || len >= GR_SPROLE_LEN)
59710+ return -EINVAL;
59711+
59712+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59713+ return -ENOMEM;
59714+
59715+ if (copy_from_user(tmp, sptmp->rolename, len))
59716+ return -EFAULT;
59717+
59718+ tmp[len-1] = '\0';
59719+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59720+ printk(KERN_ALERT "Copying special role %s\n", tmp);
59721+#endif
59722+ sptmp->rolename = tmp;
59723+ acl_special_roles[i] = sptmp;
59724+ }
59725+
59726+ r_utmp = (struct acl_role_label **) arg->role_db.r_table;
59727+
59728+ for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
59729+ r_tmp = acl_alloc(sizeof (struct acl_role_label));
59730+
59731+ if (!r_tmp)
59732+ return -ENOMEM;
59733+
59734+ if (copy_from_user(&r_utmp2, r_utmp + r_num,
59735+ sizeof (struct acl_role_label *)))
59736+ return -EFAULT;
59737+
59738+ if (copy_from_user(r_tmp, r_utmp2,
59739+ sizeof (struct acl_role_label)))
59740+ return -EFAULT;
59741+
59742+ len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
59743+
59744+ if (!len || len >= PATH_MAX)
59745+ return -EINVAL;
59746+
59747+ if ((tmp = (char *) acl_alloc(len)) == NULL)
59748+ return -ENOMEM;
59749+
59750+ if (copy_from_user(tmp, r_tmp->rolename, len))
59751+ return -EFAULT;
59752+
59753+ tmp[len-1] = '\0';
59754+ r_tmp->rolename = tmp;
59755+
59756+ if (!strcmp(r_tmp->rolename, "default")
59757+ && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
59758+ default_role = r_tmp;
59759+ } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
59760+ kernel_role = r_tmp;
59761+ }
59762+
59763+ if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
59764+ return -ENOMEM;
59765+
59766+ if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
59767+ return -EFAULT;
59768+
59769+ r_tmp->hash = ghash;
59770+
59771+ num_subjs = count_user_subjs(r_tmp->hash->first);
59772+
59773+ r_tmp->subj_hash_size = num_subjs;
59774+ r_tmp->subj_hash =
59775+ (struct acl_subject_label **)
59776+ create_table(&(r_tmp->subj_hash_size), sizeof(void *));
59777+
59778+ if (!r_tmp->subj_hash)
59779+ return -ENOMEM;
59780+
59781+ err = copy_user_allowedips(r_tmp);
59782+ if (err)
59783+ return err;
59784+
59785+ /* copy domain info */
59786+ if (r_tmp->domain_children != NULL) {
59787+ domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
59788+ if (domainlist == NULL)
59789+ return -ENOMEM;
59790+
59791+ if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
59792+ return -EFAULT;
59793+
59794+ r_tmp->domain_children = domainlist;
59795+ }
59796+
59797+ err = copy_user_transitions(r_tmp);
59798+ if (err)
59799+ return err;
59800+
59801+ memset(r_tmp->subj_hash, 0,
59802+ r_tmp->subj_hash_size *
59803+ sizeof (struct acl_subject_label *));
59804+
59805+ /* acquire the list of subjects, then NULL out
59806+ the list prior to parsing the subjects for this role,
59807+ as during this parsing the list is replaced with a list
59808+ of *nested* subjects for the role
59809+ */
59810+ subj_list = r_tmp->hash->first;
59811+
59812+ /* set nested subject list to null */
59813+ r_tmp->hash->first = NULL;
59814+
59815+ err = copy_user_subjs(subj_list, r_tmp);
59816+
59817+ if (err)
59818+ return err;
59819+
59820+ insert_acl_role_label(r_tmp);
59821+ }
59822+
59823+ if (default_role == NULL || kernel_role == NULL)
59824+ return -EINVAL;
59825+
59826+ return err;
59827+}
59828+
59829+static int
59830+gracl_init(struct gr_arg *args)
59831+{
59832+ int error = 0;
59833+
59834+ memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
59835+ memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
59836+
59837+ if (init_variables(args)) {
59838+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
59839+ error = -ENOMEM;
59840+ free_variables();
59841+ goto out;
59842+ }
59843+
59844+ error = copy_user_acl(args);
59845+ free_init_variables();
59846+ if (error) {
59847+ free_variables();
59848+ goto out;
59849+ }
59850+
59851+ if ((error = gr_set_acls(0))) {
59852+ free_variables();
59853+ goto out;
59854+ }
59855+
59856+ pax_open_kernel();
59857+ gr_status |= GR_READY;
59858+ pax_close_kernel();
59859+
59860+ out:
59861+ return error;
59862+}
59863+
59864+/* derived from glibc fnmatch() 0: match, 1: no match*/
59865+
59866+static int
59867+glob_match(const char *p, const char *n)
59868+{
59869+ char c;
59870+
59871+ while ((c = *p++) != '\0') {
59872+ switch (c) {
59873+ case '?':
59874+ if (*n == '\0')
59875+ return 1;
59876+ else if (*n == '/')
59877+ return 1;
59878+ break;
59879+ case '\\':
59880+ if (*n != c)
59881+ return 1;
59882+ break;
59883+ case '*':
59884+ for (c = *p++; c == '?' || c == '*'; c = *p++) {
59885+ if (*n == '/')
59886+ return 1;
59887+ else if (c == '?') {
59888+ if (*n == '\0')
59889+ return 1;
59890+ else
59891+ ++n;
59892+ }
59893+ }
59894+ if (c == '\0') {
59895+ return 0;
59896+ } else {
59897+ const char *endp;
59898+
59899+ if ((endp = strchr(n, '/')) == NULL)
59900+ endp = n + strlen(n);
59901+
59902+ if (c == '[') {
59903+ for (--p; n < endp; ++n)
59904+ if (!glob_match(p, n))
59905+ return 0;
59906+ } else if (c == '/') {
59907+ while (*n != '\0' && *n != '/')
59908+ ++n;
59909+ if (*n == '/' && !glob_match(p, n + 1))
59910+ return 0;
59911+ } else {
59912+ for (--p; n < endp; ++n)
59913+ if (*n == c && !glob_match(p, n))
59914+ return 0;
59915+ }
59916+
59917+ return 1;
59918+ }
59919+ case '[':
59920+ {
59921+ int not;
59922+ char cold;
59923+
59924+ if (*n == '\0' || *n == '/')
59925+ return 1;
59926+
59927+ not = (*p == '!' || *p == '^');
59928+ if (not)
59929+ ++p;
59930+
59931+ c = *p++;
59932+ for (;;) {
59933+ unsigned char fn = (unsigned char)*n;
59934+
59935+ if (c == '\0')
59936+ return 1;
59937+ else {
59938+ if (c == fn)
59939+ goto matched;
59940+ cold = c;
59941+ c = *p++;
59942+
59943+ if (c == '-' && *p != ']') {
59944+ unsigned char cend = *p++;
59945+
59946+ if (cend == '\0')
59947+ return 1;
59948+
59949+ if (cold <= fn && fn <= cend)
59950+ goto matched;
59951+
59952+ c = *p++;
59953+ }
59954+ }
59955+
59956+ if (c == ']')
59957+ break;
59958+ }
59959+ if (!not)
59960+ return 1;
59961+ break;
59962+ matched:
59963+ while (c != ']') {
59964+ if (c == '\0')
59965+ return 1;
59966+
59967+ c = *p++;
59968+ }
59969+ if (not)
59970+ return 1;
59971+ }
59972+ break;
59973+ default:
59974+ if (c != *n)
59975+ return 1;
59976+ }
59977+
59978+ ++n;
59979+ }
59980+
59981+ if (*n == '\0')
59982+ return 0;
59983+
59984+ if (*n == '/')
59985+ return 0;
59986+
59987+ return 1;
59988+}
59989+
59990+static struct acl_object_label *
59991+chk_glob_label(struct acl_object_label *globbed,
59992+ const struct dentry *dentry, const struct vfsmount *mnt, char **path)
59993+{
59994+ struct acl_object_label *tmp;
59995+
59996+ if (*path == NULL)
59997+ *path = gr_to_filename_nolock(dentry, mnt);
59998+
59999+ tmp = globbed;
60000+
60001+ while (tmp) {
60002+ if (!glob_match(tmp->filename, *path))
60003+ return tmp;
60004+ tmp = tmp->next;
60005+ }
60006+
60007+ return NULL;
60008+}
60009+
60010+static struct acl_object_label *
60011+__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60012+ const ino_t curr_ino, const dev_t curr_dev,
60013+ const struct acl_subject_label *subj, char **path, const int checkglob)
60014+{
60015+ struct acl_subject_label *tmpsubj;
60016+ struct acl_object_label *retval;
60017+ struct acl_object_label *retval2;
60018+
60019+ tmpsubj = (struct acl_subject_label *) subj;
60020+ read_lock(&gr_inode_lock);
60021+ do {
60022+ retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
60023+ if (retval) {
60024+ if (checkglob && retval->globbed) {
60025+ retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
60026+ if (retval2)
60027+ retval = retval2;
60028+ }
60029+ break;
60030+ }
60031+ } while ((tmpsubj = tmpsubj->parent_subject));
60032+ read_unlock(&gr_inode_lock);
60033+
60034+ return retval;
60035+}
60036+
60037+static __inline__ struct acl_object_label *
60038+full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
60039+ struct dentry *curr_dentry,
60040+ const struct acl_subject_label *subj, char **path, const int checkglob)
60041+{
60042+ int newglob = checkglob;
60043+ ino_t inode;
60044+ dev_t device;
60045+
60046+ /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
60047+ as we don't want a / * rule to match instead of the / object
60048+ don't do this for create lookups that call this function though, since they're looking up
60049+ on the parent and thus need globbing checks on all paths
60050+ */
60051+ if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
60052+ newglob = GR_NO_GLOB;
60053+
60054+ spin_lock(&curr_dentry->d_lock);
60055+ inode = curr_dentry->d_inode->i_ino;
60056+ device = __get_dev(curr_dentry);
60057+ spin_unlock(&curr_dentry->d_lock);
60058+
60059+ return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
60060+}
60061+
60062+#ifdef CONFIG_HUGETLBFS
60063+static inline bool
60064+is_hugetlbfs_mnt(const struct vfsmount *mnt)
60065+{
60066+ int i;
60067+ for (i = 0; i < HUGE_MAX_HSTATE; i++) {
60068+ if (unlikely(hugetlbfs_vfsmount[i] == mnt))
60069+ return true;
60070+ }
60071+
60072+ return false;
60073+}
60074+#endif
60075+
60076+static struct acl_object_label *
60077+__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60078+ const struct acl_subject_label *subj, char *path, const int checkglob)
60079+{
60080+ struct dentry *dentry = (struct dentry *) l_dentry;
60081+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60082+ struct mount *real_mnt = real_mount(mnt);
60083+ struct acl_object_label *retval;
60084+ struct dentry *parent;
60085+
60086+ br_read_lock(&vfsmount_lock);
60087+ write_seqlock(&rename_lock);
60088+
60089+ if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
60090+#ifdef CONFIG_NET
60091+ mnt == sock_mnt ||
60092+#endif
60093+#ifdef CONFIG_HUGETLBFS
60094+ (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
60095+#endif
60096+ /* ignore Eric Biederman */
60097+ IS_PRIVATE(l_dentry->d_inode))) {
60098+ retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
60099+ goto out;
60100+ }
60101+
60102+ for (;;) {
60103+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60104+ break;
60105+
60106+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60107+ if (!mnt_has_parent(real_mnt))
60108+ break;
60109+
60110+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60111+ if (retval != NULL)
60112+ goto out;
60113+
60114+ dentry = real_mnt->mnt_mountpoint;
60115+ real_mnt = real_mnt->mnt_parent;
60116+ mnt = &real_mnt->mnt;
60117+ continue;
60118+ }
60119+
60120+ parent = dentry->d_parent;
60121+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60122+ if (retval != NULL)
60123+ goto out;
60124+
60125+ dentry = parent;
60126+ }
60127+
60128+ retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
60129+
60130+ /* real_root is pinned so we don't have to hold a reference */
60131+ if (retval == NULL)
60132+ retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
60133+out:
60134+ write_sequnlock(&rename_lock);
60135+ br_read_unlock(&vfsmount_lock);
60136+
60137+ BUG_ON(retval == NULL);
60138+
60139+ return retval;
60140+}
60141+
60142+static __inline__ struct acl_object_label *
60143+chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60144+ const struct acl_subject_label *subj)
60145+{
60146+ char *path = NULL;
60147+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
60148+}
60149+
60150+static __inline__ struct acl_object_label *
60151+chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60152+ const struct acl_subject_label *subj)
60153+{
60154+ char *path = NULL;
60155+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
60156+}
60157+
60158+static __inline__ struct acl_object_label *
60159+chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60160+ const struct acl_subject_label *subj, char *path)
60161+{
60162+ return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
60163+}
60164+
60165+static struct acl_subject_label *
60166+chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
60167+ const struct acl_role_label *role)
60168+{
60169+ struct dentry *dentry = (struct dentry *) l_dentry;
60170+ struct vfsmount *mnt = (struct vfsmount *) l_mnt;
60171+ struct mount *real_mnt = real_mount(mnt);
60172+ struct acl_subject_label *retval;
60173+ struct dentry *parent;
60174+
60175+ br_read_lock(&vfsmount_lock);
60176+ write_seqlock(&rename_lock);
60177+
60178+ for (;;) {
60179+ if (dentry == real_root.dentry && mnt == real_root.mnt)
60180+ break;
60181+ if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
60182+ if (!mnt_has_parent(real_mnt))
60183+ break;
60184+
60185+ spin_lock(&dentry->d_lock);
60186+ read_lock(&gr_inode_lock);
60187+ retval =
60188+ lookup_acl_subj_label(dentry->d_inode->i_ino,
60189+ __get_dev(dentry), role);
60190+ read_unlock(&gr_inode_lock);
60191+ spin_unlock(&dentry->d_lock);
60192+ if (retval != NULL)
60193+ goto out;
60194+
60195+ dentry = real_mnt->mnt_mountpoint;
60196+ real_mnt = real_mnt->mnt_parent;
60197+ mnt = &real_mnt->mnt;
60198+ continue;
60199+ }
60200+
60201+ spin_lock(&dentry->d_lock);
60202+ read_lock(&gr_inode_lock);
60203+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60204+ __get_dev(dentry), role);
60205+ read_unlock(&gr_inode_lock);
60206+ parent = dentry->d_parent;
60207+ spin_unlock(&dentry->d_lock);
60208+
60209+ if (retval != NULL)
60210+ goto out;
60211+
60212+ dentry = parent;
60213+ }
60214+
60215+ spin_lock(&dentry->d_lock);
60216+ read_lock(&gr_inode_lock);
60217+ retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
60218+ __get_dev(dentry), role);
60219+ read_unlock(&gr_inode_lock);
60220+ spin_unlock(&dentry->d_lock);
60221+
60222+ if (unlikely(retval == NULL)) {
60223+ /* real_root is pinned, we don't need to hold a reference */
60224+ read_lock(&gr_inode_lock);
60225+ retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
60226+ __get_dev(real_root.dentry), role);
60227+ read_unlock(&gr_inode_lock);
60228+ }
60229+out:
60230+ write_sequnlock(&rename_lock);
60231+ br_read_unlock(&vfsmount_lock);
60232+
60233+ BUG_ON(retval == NULL);
60234+
60235+ return retval;
60236+}
60237+
60238+static void
60239+gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
60240+{
60241+ struct task_struct *task = current;
60242+ const struct cred *cred = current_cred();
60243+
60244+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
60245+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60246+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60247+ 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
60248+
60249+ return;
60250+}
60251+
60252+static void
60253+gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
60254+{
60255+ struct task_struct *task = current;
60256+ const struct cred *cred = current_cred();
60257+
60258+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60259+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60260+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60261+ 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
60262+
60263+ return;
60264+}
60265+
60266+static void
60267+gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
60268+{
60269+ struct task_struct *task = current;
60270+ const struct cred *cred = current_cred();
60271+
60272+ security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
60273+ GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
60274+ task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
60275+ 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
60276+
60277+ return;
60278+}
60279+
60280+__u32
60281+gr_search_file(const struct dentry * dentry, const __u32 mode,
60282+ const struct vfsmount * mnt)
60283+{
60284+ __u32 retval = mode;
60285+ struct acl_subject_label *curracl;
60286+ struct acl_object_label *currobj;
60287+
60288+ if (unlikely(!(gr_status & GR_READY)))
60289+ return (mode & ~GR_AUDITS);
60290+
60291+ curracl = current->acl;
60292+
60293+ currobj = chk_obj_label(dentry, mnt, curracl);
60294+ retval = currobj->mode & mode;
60295+
60296+ /* if we're opening a specified transfer file for writing
60297+ (e.g. /dev/initctl), then transfer our role to init
60298+ */
60299+ if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
60300+ current->role->roletype & GR_ROLE_PERSIST)) {
60301+ struct task_struct *task = init_pid_ns.child_reaper;
60302+
60303+ if (task->role != current->role) {
60304+ task->acl_sp_role = 0;
60305+ task->acl_role_id = current->acl_role_id;
60306+ task->role = current->role;
60307+ rcu_read_lock();
60308+ read_lock(&grsec_exec_file_lock);
60309+ gr_apply_subject_to_task(task);
60310+ read_unlock(&grsec_exec_file_lock);
60311+ rcu_read_unlock();
60312+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
60313+ }
60314+ }
60315+
60316+ if (unlikely
60317+ ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
60318+ && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
60319+ __u32 new_mode = mode;
60320+
60321+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60322+
60323+ retval = new_mode;
60324+
60325+ if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
60326+ new_mode |= GR_INHERIT;
60327+
60328+ if (!(mode & GR_NOLEARN))
60329+ gr_log_learn(dentry, mnt, new_mode);
60330+ }
60331+
60332+ return retval;
60333+}
60334+
60335+struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
60336+ const struct dentry *parent,
60337+ const struct vfsmount *mnt)
60338+{
60339+ struct name_entry *match;
60340+ struct acl_object_label *matchpo;
60341+ struct acl_subject_label *curracl;
60342+ char *path;
60343+
60344+ if (unlikely(!(gr_status & GR_READY)))
60345+ return NULL;
60346+
60347+ preempt_disable();
60348+ path = gr_to_filename_rbac(new_dentry, mnt);
60349+ match = lookup_name_entry_create(path);
60350+
60351+ curracl = current->acl;
60352+
60353+ if (match) {
60354+ read_lock(&gr_inode_lock);
60355+ matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
60356+ read_unlock(&gr_inode_lock);
60357+
60358+ if (matchpo) {
60359+ preempt_enable();
60360+ return matchpo;
60361+ }
60362+ }
60363+
60364+ // lookup parent
60365+
60366+ matchpo = chk_obj_create_label(parent, mnt, curracl, path);
60367+
60368+ preempt_enable();
60369+ return matchpo;
60370+}
60371+
60372+__u32
60373+gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
60374+ const struct vfsmount * mnt, const __u32 mode)
60375+{
60376+ struct acl_object_label *matchpo;
60377+ __u32 retval;
60378+
60379+ if (unlikely(!(gr_status & GR_READY)))
60380+ return (mode & ~GR_AUDITS);
60381+
60382+ matchpo = gr_get_create_object(new_dentry, parent, mnt);
60383+
60384+ retval = matchpo->mode & mode;
60385+
60386+ if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
60387+ && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60388+ __u32 new_mode = mode;
60389+
60390+ new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
60391+
60392+ gr_log_learn(new_dentry, mnt, new_mode);
60393+ return new_mode;
60394+ }
60395+
60396+ return retval;
60397+}
60398+
60399+__u32
60400+gr_check_link(const struct dentry * new_dentry,
60401+ const struct dentry * parent_dentry,
60402+ const struct vfsmount * parent_mnt,
60403+ const struct dentry * old_dentry, const struct vfsmount * old_mnt)
60404+{
60405+ struct acl_object_label *obj;
60406+ __u32 oldmode, newmode;
60407+ __u32 needmode;
60408+ __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
60409+ GR_DELETE | GR_INHERIT;
60410+
60411+ if (unlikely(!(gr_status & GR_READY)))
60412+ return (GR_CREATE | GR_LINK);
60413+
60414+ obj = chk_obj_label(old_dentry, old_mnt, current->acl);
60415+ oldmode = obj->mode;
60416+
60417+ obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
60418+ newmode = obj->mode;
60419+
60420+ needmode = newmode & checkmodes;
60421+
60422+ // old name for hardlink must have at least the permissions of the new name
60423+ if ((oldmode & needmode) != needmode)
60424+ goto bad;
60425+
60426+ // if old name had restrictions/auditing, make sure the new name does as well
60427+ needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
60428+
60429+ // don't allow hardlinking of suid/sgid/fcapped files without permission
60430+ if (is_privileged_binary(old_dentry))
60431+ needmode |= GR_SETID;
60432+
60433+ if ((newmode & needmode) != needmode)
60434+ goto bad;
60435+
60436+ // enforce minimum permissions
60437+ if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
60438+ return newmode;
60439+bad:
60440+ needmode = oldmode;
60441+ if (is_privileged_binary(old_dentry))
60442+ needmode |= GR_SETID;
60443+
60444+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
60445+ gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
60446+ return (GR_CREATE | GR_LINK);
60447+ } else if (newmode & GR_SUPPRESS)
60448+ return GR_SUPPRESS;
60449+ else
60450+ return 0;
60451+}
60452+
60453+int
60454+gr_check_hidden_task(const struct task_struct *task)
60455+{
60456+ if (unlikely(!(gr_status & GR_READY)))
60457+ return 0;
60458+
60459+ if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
60460+ return 1;
60461+
60462+ return 0;
60463+}
60464+
60465+int
60466+gr_check_protected_task(const struct task_struct *task)
60467+{
60468+ if (unlikely(!(gr_status & GR_READY) || !task))
60469+ return 0;
60470+
60471+ if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60472+ task->acl != current->acl)
60473+ return 1;
60474+
60475+ return 0;
60476+}
60477+
60478+int
60479+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
60480+{
60481+ struct task_struct *p;
60482+ int ret = 0;
60483+
60484+ if (unlikely(!(gr_status & GR_READY) || !pid))
60485+ return ret;
60486+
60487+ read_lock(&tasklist_lock);
60488+ do_each_pid_task(pid, type, p) {
60489+ if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
60490+ p->acl != current->acl) {
60491+ ret = 1;
60492+ goto out;
60493+ }
60494+ } while_each_pid_task(pid, type, p);
60495+out:
60496+ read_unlock(&tasklist_lock);
60497+
60498+ return ret;
60499+}
60500+
60501+void
60502+gr_copy_label(struct task_struct *tsk)
60503+{
60504+ tsk->signal->used_accept = 0;
60505+ tsk->acl_sp_role = 0;
60506+ tsk->acl_role_id = current->acl_role_id;
60507+ tsk->acl = current->acl;
60508+ tsk->role = current->role;
60509+ tsk->signal->curr_ip = current->signal->curr_ip;
60510+ tsk->signal->saved_ip = current->signal->saved_ip;
60511+ if (current->exec_file)
60512+ get_file(current->exec_file);
60513+ tsk->exec_file = current->exec_file;
60514+ tsk->is_writable = current->is_writable;
60515+ if (unlikely(current->signal->used_accept)) {
60516+ current->signal->curr_ip = 0;
60517+ current->signal->saved_ip = 0;
60518+ }
60519+
60520+ return;
60521+}
60522+
60523+static void
60524+gr_set_proc_res(struct task_struct *task)
60525+{
60526+ struct acl_subject_label *proc;
60527+ unsigned short i;
60528+
60529+ proc = task->acl;
60530+
60531+ if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
60532+ return;
60533+
60534+ for (i = 0; i < RLIM_NLIMITS; i++) {
60535+ if (!(proc->resmask & (1U << i)))
60536+ continue;
60537+
60538+ task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
60539+ task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
60540+
60541+ if (i == RLIMIT_CPU)
60542+ update_rlimit_cpu(task, proc->res[i].rlim_cur);
60543+ }
60544+
60545+ return;
60546+}
60547+
60548+extern int __gr_process_user_ban(struct user_struct *user);
60549+
60550+int
60551+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
60552+{
60553+ unsigned int i;
60554+ __u16 num;
60555+ uid_t *uidlist;
60556+ uid_t curuid;
60557+ int realok = 0;
60558+ int effectiveok = 0;
60559+ int fsok = 0;
60560+ uid_t globalreal, globaleffective, globalfs;
60561+
60562+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
60563+ struct user_struct *user;
60564+
60565+ if (!uid_valid(real))
60566+ goto skipit;
60567+
60568+ /* find user based on global namespace */
60569+
60570+ globalreal = GR_GLOBAL_UID(real);
60571+
60572+ user = find_user(make_kuid(&init_user_ns, globalreal));
60573+ if (user == NULL)
60574+ goto skipit;
60575+
60576+ if (__gr_process_user_ban(user)) {
60577+ /* for find_user */
60578+ free_uid(user);
60579+ return 1;
60580+ }
60581+
60582+ /* for find_user */
60583+ free_uid(user);
60584+
60585+skipit:
60586+#endif
60587+
60588+ if (unlikely(!(gr_status & GR_READY)))
60589+ return 0;
60590+
60591+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60592+ gr_log_learn_uid_change(real, effective, fs);
60593+
60594+ num = current->acl->user_trans_num;
60595+ uidlist = current->acl->user_transitions;
60596+
60597+ if (uidlist == NULL)
60598+ return 0;
60599+
60600+ if (!uid_valid(real)) {
60601+ realok = 1;
60602+ globalreal = (uid_t)-1;
60603+ } else {
60604+ globalreal = GR_GLOBAL_UID(real);
60605+ }
60606+ if (!uid_valid(effective)) {
60607+ effectiveok = 1;
60608+ globaleffective = (uid_t)-1;
60609+ } else {
60610+ globaleffective = GR_GLOBAL_UID(effective);
60611+ }
60612+ if (!uid_valid(fs)) {
60613+ fsok = 1;
60614+ globalfs = (uid_t)-1;
60615+ } else {
60616+ globalfs = GR_GLOBAL_UID(fs);
60617+ }
60618+
60619+ if (current->acl->user_trans_type & GR_ID_ALLOW) {
60620+ for (i = 0; i < num; i++) {
60621+ curuid = uidlist[i];
60622+ if (globalreal == curuid)
60623+ realok = 1;
60624+ if (globaleffective == curuid)
60625+ effectiveok = 1;
60626+ if (globalfs == curuid)
60627+ fsok = 1;
60628+ }
60629+ } else if (current->acl->user_trans_type & GR_ID_DENY) {
60630+ for (i = 0; i < num; i++) {
60631+ curuid = uidlist[i];
60632+ if (globalreal == curuid)
60633+ break;
60634+ if (globaleffective == curuid)
60635+ break;
60636+ if (globalfs == curuid)
60637+ break;
60638+ }
60639+ /* not in deny list */
60640+ if (i == num) {
60641+ realok = 1;
60642+ effectiveok = 1;
60643+ fsok = 1;
60644+ }
60645+ }
60646+
60647+ if (realok && effectiveok && fsok)
60648+ return 0;
60649+ else {
60650+ gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60651+ return 1;
60652+ }
60653+}
60654+
60655+int
60656+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
60657+{
60658+ unsigned int i;
60659+ __u16 num;
60660+ gid_t *gidlist;
60661+ gid_t curgid;
60662+ int realok = 0;
60663+ int effectiveok = 0;
60664+ int fsok = 0;
60665+ gid_t globalreal, globaleffective, globalfs;
60666+
60667+ if (unlikely(!(gr_status & GR_READY)))
60668+ return 0;
60669+
60670+ if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60671+ gr_log_learn_gid_change(real, effective, fs);
60672+
60673+ num = current->acl->group_trans_num;
60674+ gidlist = current->acl->group_transitions;
60675+
60676+ if (gidlist == NULL)
60677+ return 0;
60678+
60679+ if (!gid_valid(real)) {
60680+ realok = 1;
60681+ globalreal = (gid_t)-1;
60682+ } else {
60683+ globalreal = GR_GLOBAL_GID(real);
60684+ }
60685+ if (!gid_valid(effective)) {
60686+ effectiveok = 1;
60687+ globaleffective = (gid_t)-1;
60688+ } else {
60689+ globaleffective = GR_GLOBAL_GID(effective);
60690+ }
60691+ if (!gid_valid(fs)) {
60692+ fsok = 1;
60693+ globalfs = (gid_t)-1;
60694+ } else {
60695+ globalfs = GR_GLOBAL_GID(fs);
60696+ }
60697+
60698+ if (current->acl->group_trans_type & GR_ID_ALLOW) {
60699+ for (i = 0; i < num; i++) {
60700+ curgid = gidlist[i];
60701+ if (globalreal == curgid)
60702+ realok = 1;
60703+ if (globaleffective == curgid)
60704+ effectiveok = 1;
60705+ if (globalfs == curgid)
60706+ fsok = 1;
60707+ }
60708+ } else if (current->acl->group_trans_type & GR_ID_DENY) {
60709+ for (i = 0; i < num; i++) {
60710+ curgid = gidlist[i];
60711+ if (globalreal == curgid)
60712+ break;
60713+ if (globaleffective == curgid)
60714+ break;
60715+ if (globalfs == curgid)
60716+ break;
60717+ }
60718+ /* not in deny list */
60719+ if (i == num) {
60720+ realok = 1;
60721+ effectiveok = 1;
60722+ fsok = 1;
60723+ }
60724+ }
60725+
60726+ if (realok && effectiveok && fsok)
60727+ return 0;
60728+ else {
60729+ gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
60730+ return 1;
60731+ }
60732+}
60733+
60734+extern int gr_acl_is_capable(const int cap);
60735+
60736+void
60737+gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
60738+{
60739+ struct acl_role_label *role = task->role;
60740+ struct acl_subject_label *subj = NULL;
60741+ struct acl_object_label *obj;
60742+ struct file *filp;
60743+ uid_t uid;
60744+ gid_t gid;
60745+
60746+ if (unlikely(!(gr_status & GR_READY)))
60747+ return;
60748+
60749+ uid = GR_GLOBAL_UID(kuid);
60750+ gid = GR_GLOBAL_GID(kgid);
60751+
60752+ filp = task->exec_file;
60753+
60754+ /* kernel process, we'll give them the kernel role */
60755+ if (unlikely(!filp)) {
60756+ task->role = kernel_role;
60757+ task->acl = kernel_role->root_label;
60758+ return;
60759+ } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
60760+ role = lookup_acl_role_label(task, uid, gid);
60761+
60762+ /* don't change the role if we're not a privileged process */
60763+ if (role && task->role != role &&
60764+ (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
60765+ ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
60766+ return;
60767+
60768+ /* perform subject lookup in possibly new role
60769+ we can use this result below in the case where role == task->role
60770+ */
60771+ subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
60772+
60773+ /* if we changed uid/gid, but result in the same role
60774+ and are using inheritance, don't lose the inherited subject
60775+ if current subject is other than what normal lookup
60776+ would result in, we arrived via inheritance, don't
60777+ lose subject
60778+ */
60779+ if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
60780+ (subj == task->acl)))
60781+ task->acl = subj;
60782+
60783+ task->role = role;
60784+
60785+ task->is_writable = 0;
60786+
60787+ /* ignore additional mmap checks for processes that are writable
60788+ by the default ACL */
60789+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60790+ if (unlikely(obj->mode & GR_WRITE))
60791+ task->is_writable = 1;
60792+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60793+ if (unlikely(obj->mode & GR_WRITE))
60794+ task->is_writable = 1;
60795+
60796+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60797+ 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);
60798+#endif
60799+
60800+ gr_set_proc_res(task);
60801+
60802+ return;
60803+}
60804+
60805+int
60806+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
60807+ const int unsafe_flags)
60808+{
60809+ struct task_struct *task = current;
60810+ struct acl_subject_label *newacl;
60811+ struct acl_object_label *obj;
60812+ __u32 retmode;
60813+
60814+ if (unlikely(!(gr_status & GR_READY)))
60815+ return 0;
60816+
60817+ newacl = chk_subj_label(dentry, mnt, task->role);
60818+
60819+ /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
60820+ did an exec
60821+ */
60822+ rcu_read_lock();
60823+ read_lock(&tasklist_lock);
60824+ if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
60825+ (task->parent->acl->mode & GR_POVERRIDE))) {
60826+ read_unlock(&tasklist_lock);
60827+ rcu_read_unlock();
60828+ goto skip_check;
60829+ }
60830+ read_unlock(&tasklist_lock);
60831+ rcu_read_unlock();
60832+
60833+ if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
60834+ !(task->role->roletype & GR_ROLE_GOD) &&
60835+ !gr_search_file(dentry, GR_PTRACERD, mnt) &&
60836+ !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
60837+ if (unsafe_flags & LSM_UNSAFE_SHARE)
60838+ gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
60839+ else
60840+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
60841+ return -EACCES;
60842+ }
60843+
60844+skip_check:
60845+
60846+ obj = chk_obj_label(dentry, mnt, task->acl);
60847+ retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
60848+
60849+ if (!(task->acl->mode & GR_INHERITLEARN) &&
60850+ ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
60851+ if (obj->nested)
60852+ task->acl = obj->nested;
60853+ else
60854+ task->acl = newacl;
60855+ } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
60856+ gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
60857+
60858+ task->is_writable = 0;
60859+
60860+ /* ignore additional mmap checks for processes that are writable
60861+ by the default ACL */
60862+ obj = chk_obj_label(dentry, mnt, default_role->root_label);
60863+ if (unlikely(obj->mode & GR_WRITE))
60864+ task->is_writable = 1;
60865+ obj = chk_obj_label(dentry, mnt, task->role->root_label);
60866+ if (unlikely(obj->mode & GR_WRITE))
60867+ task->is_writable = 1;
60868+
60869+ gr_set_proc_res(task);
60870+
60871+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60872+ 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);
60873+#endif
60874+ return 0;
60875+}
60876+
60877+/* always called with valid inodev ptr */
60878+static void
60879+do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
60880+{
60881+ struct acl_object_label *matchpo;
60882+ struct acl_subject_label *matchps;
60883+ struct acl_subject_label *subj;
60884+ struct acl_role_label *role;
60885+ unsigned int x;
60886+
60887+ FOR_EACH_ROLE_START(role)
60888+ FOR_EACH_SUBJECT_START(role, subj, x)
60889+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60890+ matchpo->mode |= GR_DELETED;
60891+ FOR_EACH_SUBJECT_END(subj,x)
60892+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
60893+ /* nested subjects aren't in the role's subj_hash table */
60894+ if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
60895+ matchpo->mode |= GR_DELETED;
60896+ FOR_EACH_NESTED_SUBJECT_END(subj)
60897+ if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
60898+ matchps->mode |= GR_DELETED;
60899+ FOR_EACH_ROLE_END(role)
60900+
60901+ inodev->nentry->deleted = 1;
60902+
60903+ return;
60904+}
60905+
60906+void
60907+gr_handle_delete(const ino_t ino, const dev_t dev)
60908+{
60909+ struct inodev_entry *inodev;
60910+
60911+ if (unlikely(!(gr_status & GR_READY)))
60912+ return;
60913+
60914+ write_lock(&gr_inode_lock);
60915+ inodev = lookup_inodev_entry(ino, dev);
60916+ if (inodev != NULL)
60917+ do_handle_delete(inodev, ino, dev);
60918+ write_unlock(&gr_inode_lock);
60919+
60920+ return;
60921+}
60922+
60923+static void
60924+update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
60925+ const ino_t newinode, const dev_t newdevice,
60926+ struct acl_subject_label *subj)
60927+{
60928+ unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
60929+ struct acl_object_label *match;
60930+
60931+ match = subj->obj_hash[index];
60932+
60933+ while (match && (match->inode != oldinode ||
60934+ match->device != olddevice ||
60935+ !(match->mode & GR_DELETED)))
60936+ match = match->next;
60937+
60938+ if (match && (match->inode == oldinode)
60939+ && (match->device == olddevice)
60940+ && (match->mode & GR_DELETED)) {
60941+ if (match->prev == NULL) {
60942+ subj->obj_hash[index] = match->next;
60943+ if (match->next != NULL)
60944+ match->next->prev = NULL;
60945+ } else {
60946+ match->prev->next = match->next;
60947+ if (match->next != NULL)
60948+ match->next->prev = match->prev;
60949+ }
60950+ match->prev = NULL;
60951+ match->next = NULL;
60952+ match->inode = newinode;
60953+ match->device = newdevice;
60954+ match->mode &= ~GR_DELETED;
60955+
60956+ insert_acl_obj_label(match, subj);
60957+ }
60958+
60959+ return;
60960+}
60961+
60962+static void
60963+update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
60964+ const ino_t newinode, const dev_t newdevice,
60965+ struct acl_role_label *role)
60966+{
60967+ unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
60968+ struct acl_subject_label *match;
60969+
60970+ match = role->subj_hash[index];
60971+
60972+ while (match && (match->inode != oldinode ||
60973+ match->device != olddevice ||
60974+ !(match->mode & GR_DELETED)))
60975+ match = match->next;
60976+
60977+ if (match && (match->inode == oldinode)
60978+ && (match->device == olddevice)
60979+ && (match->mode & GR_DELETED)) {
60980+ if (match->prev == NULL) {
60981+ role->subj_hash[index] = match->next;
60982+ if (match->next != NULL)
60983+ match->next->prev = NULL;
60984+ } else {
60985+ match->prev->next = match->next;
60986+ if (match->next != NULL)
60987+ match->next->prev = match->prev;
60988+ }
60989+ match->prev = NULL;
60990+ match->next = NULL;
60991+ match->inode = newinode;
60992+ match->device = newdevice;
60993+ match->mode &= ~GR_DELETED;
60994+
60995+ insert_acl_subj_label(match, role);
60996+ }
60997+
60998+ return;
60999+}
61000+
61001+static void
61002+update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
61003+ const ino_t newinode, const dev_t newdevice)
61004+{
61005+ unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
61006+ struct inodev_entry *match;
61007+
61008+ match = inodev_set.i_hash[index];
61009+
61010+ while (match && (match->nentry->inode != oldinode ||
61011+ match->nentry->device != olddevice || !match->nentry->deleted))
61012+ match = match->next;
61013+
61014+ if (match && (match->nentry->inode == oldinode)
61015+ && (match->nentry->device == olddevice) &&
61016+ match->nentry->deleted) {
61017+ if (match->prev == NULL) {
61018+ inodev_set.i_hash[index] = match->next;
61019+ if (match->next != NULL)
61020+ match->next->prev = NULL;
61021+ } else {
61022+ match->prev->next = match->next;
61023+ if (match->next != NULL)
61024+ match->next->prev = match->prev;
61025+ }
61026+ match->prev = NULL;
61027+ match->next = NULL;
61028+ match->nentry->inode = newinode;
61029+ match->nentry->device = newdevice;
61030+ match->nentry->deleted = 0;
61031+
61032+ insert_inodev_entry(match);
61033+ }
61034+
61035+ return;
61036+}
61037+
61038+static void
61039+__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
61040+{
61041+ struct acl_subject_label *subj;
61042+ struct acl_role_label *role;
61043+ unsigned int x;
61044+
61045+ FOR_EACH_ROLE_START(role)
61046+ update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
61047+
61048+ FOR_EACH_NESTED_SUBJECT_START(role, subj)
61049+ if ((subj->inode == ino) && (subj->device == dev)) {
61050+ subj->inode = ino;
61051+ subj->device = dev;
61052+ }
61053+ /* nested subjects aren't in the role's subj_hash table */
61054+ update_acl_obj_label(matchn->inode, matchn->device,
61055+ ino, dev, subj);
61056+ FOR_EACH_NESTED_SUBJECT_END(subj)
61057+ FOR_EACH_SUBJECT_START(role, subj, x)
61058+ update_acl_obj_label(matchn->inode, matchn->device,
61059+ ino, dev, subj);
61060+ FOR_EACH_SUBJECT_END(subj,x)
61061+ FOR_EACH_ROLE_END(role)
61062+
61063+ update_inodev_entry(matchn->inode, matchn->device, ino, dev);
61064+
61065+ return;
61066+}
61067+
61068+static void
61069+do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
61070+ const struct vfsmount *mnt)
61071+{
61072+ ino_t ino = dentry->d_inode->i_ino;
61073+ dev_t dev = __get_dev(dentry);
61074+
61075+ __do_handle_create(matchn, ino, dev);
61076+
61077+ return;
61078+}
61079+
61080+void
61081+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
61082+{
61083+ struct name_entry *matchn;
61084+
61085+ if (unlikely(!(gr_status & GR_READY)))
61086+ return;
61087+
61088+ preempt_disable();
61089+ matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
61090+
61091+ if (unlikely((unsigned long)matchn)) {
61092+ write_lock(&gr_inode_lock);
61093+ do_handle_create(matchn, dentry, mnt);
61094+ write_unlock(&gr_inode_lock);
61095+ }
61096+ preempt_enable();
61097+
61098+ return;
61099+}
61100+
61101+void
61102+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
61103+{
61104+ struct name_entry *matchn;
61105+
61106+ if (unlikely(!(gr_status & GR_READY)))
61107+ return;
61108+
61109+ preempt_disable();
61110+ matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
61111+
61112+ if (unlikely((unsigned long)matchn)) {
61113+ write_lock(&gr_inode_lock);
61114+ __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
61115+ write_unlock(&gr_inode_lock);
61116+ }
61117+ preempt_enable();
61118+
61119+ return;
61120+}
61121+
61122+void
61123+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
61124+ struct dentry *old_dentry,
61125+ struct dentry *new_dentry,
61126+ struct vfsmount *mnt, const __u8 replace)
61127+{
61128+ struct name_entry *matchn;
61129+ struct inodev_entry *inodev;
61130+ struct inode *inode = new_dentry->d_inode;
61131+ ino_t old_ino = old_dentry->d_inode->i_ino;
61132+ dev_t old_dev = __get_dev(old_dentry);
61133+
61134+ /* vfs_rename swaps the name and parent link for old_dentry and
61135+ new_dentry
61136+ at this point, old_dentry has the new name, parent link, and inode
61137+ for the renamed file
61138+ if a file is being replaced by a rename, new_dentry has the inode
61139+ and name for the replaced file
61140+ */
61141+
61142+ if (unlikely(!(gr_status & GR_READY)))
61143+ return;
61144+
61145+ preempt_disable();
61146+ matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
61147+
61148+ /* we wouldn't have to check d_inode if it weren't for
61149+ NFS silly-renaming
61150+ */
61151+
61152+ write_lock(&gr_inode_lock);
61153+ if (unlikely(replace && inode)) {
61154+ ino_t new_ino = inode->i_ino;
61155+ dev_t new_dev = __get_dev(new_dentry);
61156+
61157+ inodev = lookup_inodev_entry(new_ino, new_dev);
61158+ if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
61159+ do_handle_delete(inodev, new_ino, new_dev);
61160+ }
61161+
61162+ inodev = lookup_inodev_entry(old_ino, old_dev);
61163+ if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
61164+ do_handle_delete(inodev, old_ino, old_dev);
61165+
61166+ if (unlikely((unsigned long)matchn))
61167+ do_handle_create(matchn, old_dentry, mnt);
61168+
61169+ write_unlock(&gr_inode_lock);
61170+ preempt_enable();
61171+
61172+ return;
61173+}
61174+
61175+static int
61176+lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
61177+ unsigned char **sum)
61178+{
61179+ struct acl_role_label *r;
61180+ struct role_allowed_ip *ipp;
61181+ struct role_transition *trans;
61182+ unsigned int i;
61183+ int found = 0;
61184+ u32 curr_ip = current->signal->curr_ip;
61185+
61186+ current->signal->saved_ip = curr_ip;
61187+
61188+ /* check transition table */
61189+
61190+ for (trans = current->role->transitions; trans; trans = trans->next) {
61191+ if (!strcmp(rolename, trans->rolename)) {
61192+ found = 1;
61193+ break;
61194+ }
61195+ }
61196+
61197+ if (!found)
61198+ return 0;
61199+
61200+ /* handle special roles that do not require authentication
61201+ and check ip */
61202+
61203+ FOR_EACH_ROLE_START(r)
61204+ if (!strcmp(rolename, r->rolename) &&
61205+ (r->roletype & GR_ROLE_SPECIAL)) {
61206+ found = 0;
61207+ if (r->allowed_ips != NULL) {
61208+ for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
61209+ if ((ntohl(curr_ip) & ipp->netmask) ==
61210+ (ntohl(ipp->addr) & ipp->netmask))
61211+ found = 1;
61212+ }
61213+ } else
61214+ found = 2;
61215+ if (!found)
61216+ return 0;
61217+
61218+ if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
61219+ ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
61220+ *salt = NULL;
61221+ *sum = NULL;
61222+ return 1;
61223+ }
61224+ }
61225+ FOR_EACH_ROLE_END(r)
61226+
61227+ for (i = 0; i < num_sprole_pws; i++) {
61228+ if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
61229+ *salt = acl_special_roles[i]->salt;
61230+ *sum = acl_special_roles[i]->sum;
61231+ return 1;
61232+ }
61233+ }
61234+
61235+ return 0;
61236+}
61237+
61238+static void
61239+assign_special_role(char *rolename)
61240+{
61241+ struct acl_object_label *obj;
61242+ struct acl_role_label *r;
61243+ struct acl_role_label *assigned = NULL;
61244+ struct task_struct *tsk;
61245+ struct file *filp;
61246+
61247+ FOR_EACH_ROLE_START(r)
61248+ if (!strcmp(rolename, r->rolename) &&
61249+ (r->roletype & GR_ROLE_SPECIAL)) {
61250+ assigned = r;
61251+ break;
61252+ }
61253+ FOR_EACH_ROLE_END(r)
61254+
61255+ if (!assigned)
61256+ return;
61257+
61258+ read_lock(&tasklist_lock);
61259+ read_lock(&grsec_exec_file_lock);
61260+
61261+ tsk = current->real_parent;
61262+ if (tsk == NULL)
61263+ goto out_unlock;
61264+
61265+ filp = tsk->exec_file;
61266+ if (filp == NULL)
61267+ goto out_unlock;
61268+
61269+ tsk->is_writable = 0;
61270+
61271+ tsk->acl_sp_role = 1;
61272+ tsk->acl_role_id = ++acl_sp_role_value;
61273+ tsk->role = assigned;
61274+ tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
61275+
61276+ /* ignore additional mmap checks for processes that are writable
61277+ by the default ACL */
61278+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61279+ if (unlikely(obj->mode & GR_WRITE))
61280+ tsk->is_writable = 1;
61281+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
61282+ if (unlikely(obj->mode & GR_WRITE))
61283+ tsk->is_writable = 1;
61284+
61285+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61286+ 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));
61287+#endif
61288+
61289+out_unlock:
61290+ read_unlock(&grsec_exec_file_lock);
61291+ read_unlock(&tasklist_lock);
61292+ return;
61293+}
61294+
61295+int gr_check_secure_terminal(struct task_struct *task)
61296+{
61297+ struct task_struct *p, *p2, *p3;
61298+ struct files_struct *files;
61299+ struct fdtable *fdt;
61300+ struct file *our_file = NULL, *file;
61301+ int i;
61302+
61303+ if (task->signal->tty == NULL)
61304+ return 1;
61305+
61306+ files = get_files_struct(task);
61307+ if (files != NULL) {
61308+ rcu_read_lock();
61309+ fdt = files_fdtable(files);
61310+ for (i=0; i < fdt->max_fds; i++) {
61311+ file = fcheck_files(files, i);
61312+ if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
61313+ get_file(file);
61314+ our_file = file;
61315+ }
61316+ }
61317+ rcu_read_unlock();
61318+ put_files_struct(files);
61319+ }
61320+
61321+ if (our_file == NULL)
61322+ return 1;
61323+
61324+ read_lock(&tasklist_lock);
61325+ do_each_thread(p2, p) {
61326+ files = get_files_struct(p);
61327+ if (files == NULL ||
61328+ (p->signal && p->signal->tty == task->signal->tty)) {
61329+ if (files != NULL)
61330+ put_files_struct(files);
61331+ continue;
61332+ }
61333+ rcu_read_lock();
61334+ fdt = files_fdtable(files);
61335+ for (i=0; i < fdt->max_fds; i++) {
61336+ file = fcheck_files(files, i);
61337+ if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
61338+ file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
61339+ p3 = task;
61340+ while (task_pid_nr(p3) > 0) {
61341+ if (p3 == p)
61342+ break;
61343+ p3 = p3->real_parent;
61344+ }
61345+ if (p3 == p)
61346+ break;
61347+ gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
61348+ gr_handle_alertkill(p);
61349+ rcu_read_unlock();
61350+ put_files_struct(files);
61351+ read_unlock(&tasklist_lock);
61352+ fput(our_file);
61353+ return 0;
61354+ }
61355+ }
61356+ rcu_read_unlock();
61357+ put_files_struct(files);
61358+ } while_each_thread(p2, p);
61359+ read_unlock(&tasklist_lock);
61360+
61361+ fput(our_file);
61362+ return 1;
61363+}
61364+
61365+static int gr_rbac_disable(void *unused)
61366+{
61367+ pax_open_kernel();
61368+ gr_status &= ~GR_READY;
61369+ pax_close_kernel();
61370+
61371+ return 0;
61372+}
61373+
61374+ssize_t
61375+write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
61376+{
61377+ struct gr_arg_wrapper uwrap;
61378+ unsigned char *sprole_salt = NULL;
61379+ unsigned char *sprole_sum = NULL;
61380+ int error = sizeof (struct gr_arg_wrapper);
61381+ int error2 = 0;
61382+
61383+ mutex_lock(&gr_dev_mutex);
61384+
61385+ if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
61386+ error = -EPERM;
61387+ goto out;
61388+ }
61389+
61390+ if (count != sizeof (struct gr_arg_wrapper)) {
61391+ gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
61392+ error = -EINVAL;
61393+ goto out;
61394+ }
61395+
61396+
61397+ if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
61398+ gr_auth_expires = 0;
61399+ gr_auth_attempts = 0;
61400+ }
61401+
61402+ if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
61403+ error = -EFAULT;
61404+ goto out;
61405+ }
61406+
61407+ if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
61408+ error = -EINVAL;
61409+ goto out;
61410+ }
61411+
61412+ if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
61413+ error = -EFAULT;
61414+ goto out;
61415+ }
61416+
61417+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61418+ gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61419+ time_after(gr_auth_expires, get_seconds())) {
61420+ error = -EBUSY;
61421+ goto out;
61422+ }
61423+
61424+ /* if non-root trying to do anything other than use a special role,
61425+ do not attempt authentication, do not count towards authentication
61426+ locking
61427+ */
61428+
61429+ if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
61430+ gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
61431+ gr_is_global_nonroot(current_uid())) {
61432+ error = -EPERM;
61433+ goto out;
61434+ }
61435+
61436+ /* ensure pw and special role name are null terminated */
61437+
61438+ gr_usermode->pw[GR_PW_LEN - 1] = '\0';
61439+ gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
61440+
61441+ /* Okay.
61442+ * We have our enough of the argument structure..(we have yet
61443+ * to copy_from_user the tables themselves) . Copy the tables
61444+ * only if we need them, i.e. for loading operations. */
61445+
61446+ switch (gr_usermode->mode) {
61447+ case GR_STATUS:
61448+ if (gr_status & GR_READY) {
61449+ error = 1;
61450+ if (!gr_check_secure_terminal(current))
61451+ error = 3;
61452+ } else
61453+ error = 2;
61454+ goto out;
61455+ case GR_SHUTDOWN:
61456+ if ((gr_status & GR_READY)
61457+ && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61458+ stop_machine(gr_rbac_disable, NULL, NULL);
61459+ free_variables();
61460+ memset(gr_usermode, 0, sizeof (struct gr_arg));
61461+ memset(gr_system_salt, 0, GR_SALT_LEN);
61462+ memset(gr_system_sum, 0, GR_SHA_LEN);
61463+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
61464+ } else if (gr_status & GR_READY) {
61465+ gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
61466+ error = -EPERM;
61467+ } else {
61468+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
61469+ error = -EAGAIN;
61470+ }
61471+ break;
61472+ case GR_ENABLE:
61473+ if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
61474+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
61475+ else {
61476+ if (gr_status & GR_READY)
61477+ error = -EAGAIN;
61478+ else
61479+ error = error2;
61480+ gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
61481+ }
61482+ break;
61483+ case GR_RELOAD:
61484+ if (!(gr_status & GR_READY)) {
61485+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
61486+ error = -EAGAIN;
61487+ } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61488+ stop_machine(gr_rbac_disable, NULL, NULL);
61489+ free_variables();
61490+ error2 = gracl_init(gr_usermode);
61491+ if (!error2)
61492+ gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
61493+ else {
61494+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61495+ error = error2;
61496+ }
61497+ } else {
61498+ gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
61499+ error = -EPERM;
61500+ }
61501+ break;
61502+ case GR_SEGVMOD:
61503+ if (unlikely(!(gr_status & GR_READY))) {
61504+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
61505+ error = -EAGAIN;
61506+ break;
61507+ }
61508+
61509+ if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
61510+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
61511+ if (gr_usermode->segv_device && gr_usermode->segv_inode) {
61512+ struct acl_subject_label *segvacl;
61513+ segvacl =
61514+ lookup_acl_subj_label(gr_usermode->segv_inode,
61515+ gr_usermode->segv_device,
61516+ current->role);
61517+ if (segvacl) {
61518+ segvacl->crashes = 0;
61519+ segvacl->expires = 0;
61520+ }
61521+ } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
61522+ gr_remove_uid(gr_usermode->segv_uid);
61523+ }
61524+ } else {
61525+ gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
61526+ error = -EPERM;
61527+ }
61528+ break;
61529+ case GR_SPROLE:
61530+ case GR_SPROLEPAM:
61531+ if (unlikely(!(gr_status & GR_READY))) {
61532+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
61533+ error = -EAGAIN;
61534+ break;
61535+ }
61536+
61537+ if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
61538+ current->role->expires = 0;
61539+ current->role->auth_attempts = 0;
61540+ }
61541+
61542+ if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
61543+ time_after(current->role->expires, get_seconds())) {
61544+ error = -EBUSY;
61545+ goto out;
61546+ }
61547+
61548+ if (lookup_special_role_auth
61549+ (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
61550+ && ((!sprole_salt && !sprole_sum)
61551+ || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
61552+ char *p = "";
61553+ assign_special_role(gr_usermode->sp_role);
61554+ read_lock(&tasklist_lock);
61555+ if (current->real_parent)
61556+ p = current->real_parent->role->rolename;
61557+ read_unlock(&tasklist_lock);
61558+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
61559+ p, acl_sp_role_value);
61560+ } else {
61561+ gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
61562+ error = -EPERM;
61563+ if(!(current->role->auth_attempts++))
61564+ current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61565+
61566+ goto out;
61567+ }
61568+ break;
61569+ case GR_UNSPROLE:
61570+ if (unlikely(!(gr_status & GR_READY))) {
61571+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
61572+ error = -EAGAIN;
61573+ break;
61574+ }
61575+
61576+ if (current->role->roletype & GR_ROLE_SPECIAL) {
61577+ char *p = "";
61578+ int i = 0;
61579+
61580+ read_lock(&tasklist_lock);
61581+ if (current->real_parent) {
61582+ p = current->real_parent->role->rolename;
61583+ i = current->real_parent->acl_role_id;
61584+ }
61585+ read_unlock(&tasklist_lock);
61586+
61587+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
61588+ gr_set_acls(1);
61589+ } else {
61590+ error = -EPERM;
61591+ goto out;
61592+ }
61593+ break;
61594+ default:
61595+ gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
61596+ error = -EINVAL;
61597+ break;
61598+ }
61599+
61600+ if (error != -EPERM)
61601+ goto out;
61602+
61603+ if(!(gr_auth_attempts++))
61604+ gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
61605+
61606+ out:
61607+ mutex_unlock(&gr_dev_mutex);
61608+ return error;
61609+}
61610+
61611+/* must be called with
61612+ rcu_read_lock();
61613+ read_lock(&tasklist_lock);
61614+ read_lock(&grsec_exec_file_lock);
61615+*/
61616+int gr_apply_subject_to_task(struct task_struct *task)
61617+{
61618+ struct acl_object_label *obj;
61619+ char *tmpname;
61620+ struct acl_subject_label *tmpsubj;
61621+ struct file *filp;
61622+ struct name_entry *nmatch;
61623+
61624+ filp = task->exec_file;
61625+ if (filp == NULL)
61626+ return 0;
61627+
61628+ /* the following is to apply the correct subject
61629+ on binaries running when the RBAC system
61630+ is enabled, when the binaries have been
61631+ replaced or deleted since their execution
61632+ -----
61633+ when the RBAC system starts, the inode/dev
61634+ from exec_file will be one the RBAC system
61635+ is unaware of. It only knows the inode/dev
61636+ of the present file on disk, or the absence
61637+ of it.
61638+ */
61639+ preempt_disable();
61640+ tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
61641+
61642+ nmatch = lookup_name_entry(tmpname);
61643+ preempt_enable();
61644+ tmpsubj = NULL;
61645+ if (nmatch) {
61646+ if (nmatch->deleted)
61647+ tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
61648+ else
61649+ tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
61650+ if (tmpsubj != NULL)
61651+ task->acl = tmpsubj;
61652+ }
61653+ if (tmpsubj == NULL)
61654+ task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
61655+ task->role);
61656+ if (task->acl) {
61657+ task->is_writable = 0;
61658+ /* ignore additional mmap checks for processes that are writable
61659+ by the default ACL */
61660+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61661+ if (unlikely(obj->mode & GR_WRITE))
61662+ task->is_writable = 1;
61663+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
61664+ if (unlikely(obj->mode & GR_WRITE))
61665+ task->is_writable = 1;
61666+
61667+ gr_set_proc_res(task);
61668+
61669+#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
61670+ 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);
61671+#endif
61672+ } else {
61673+ return 1;
61674+ }
61675+
61676+ return 0;
61677+}
61678+
61679+int
61680+gr_set_acls(const int type)
61681+{
61682+ struct task_struct *task, *task2;
61683+ struct acl_role_label *role = current->role;
61684+ __u16 acl_role_id = current->acl_role_id;
61685+ const struct cred *cred;
61686+ int ret;
61687+
61688+ rcu_read_lock();
61689+ read_lock(&tasklist_lock);
61690+ read_lock(&grsec_exec_file_lock);
61691+ do_each_thread(task2, task) {
61692+ /* check to see if we're called from the exit handler,
61693+ if so, only replace ACLs that have inherited the admin
61694+ ACL */
61695+
61696+ if (type && (task->role != role ||
61697+ task->acl_role_id != acl_role_id))
61698+ continue;
61699+
61700+ task->acl_role_id = 0;
61701+ task->acl_sp_role = 0;
61702+
61703+ if (task->exec_file) {
61704+ cred = __task_cred(task);
61705+ task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
61706+ ret = gr_apply_subject_to_task(task);
61707+ if (ret) {
61708+ read_unlock(&grsec_exec_file_lock);
61709+ read_unlock(&tasklist_lock);
61710+ rcu_read_unlock();
61711+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
61712+ return ret;
61713+ }
61714+ } else {
61715+ // it's a kernel process
61716+ task->role = kernel_role;
61717+ task->acl = kernel_role->root_label;
61718+#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
61719+ task->acl->mode &= ~GR_PROCFIND;
61720+#endif
61721+ }
61722+ } while_each_thread(task2, task);
61723+ read_unlock(&grsec_exec_file_lock);
61724+ read_unlock(&tasklist_lock);
61725+ rcu_read_unlock();
61726+
61727+ return 0;
61728+}
61729+
61730+#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
61731+static const unsigned long res_learn_bumps[GR_NLIMITS] = {
61732+ [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
61733+ [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
61734+ [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
61735+ [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
61736+ [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
61737+ [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
61738+ [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
61739+ [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
61740+ [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
61741+ [RLIMIT_AS] = GR_RLIM_AS_BUMP,
61742+ [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
61743+ [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
61744+ [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
61745+ [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
61746+ [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
61747+ [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
61748+};
61749+
61750+void
61751+gr_learn_resource(const struct task_struct *task,
61752+ const int res, const unsigned long wanted, const int gt)
61753+{
61754+ struct acl_subject_label *acl;
61755+ const struct cred *cred;
61756+
61757+ if (unlikely((gr_status & GR_READY) &&
61758+ task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
61759+ goto skip_reslog;
61760+
61761+ gr_log_resource(task, res, wanted, gt);
61762+skip_reslog:
61763+
61764+ if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
61765+ return;
61766+
61767+ acl = task->acl;
61768+
61769+ if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
61770+ !(acl->resmask & (1U << (unsigned short) res))))
61771+ return;
61772+
61773+ if (wanted >= acl->res[res].rlim_cur) {
61774+ unsigned long res_add;
61775+
61776+ res_add = wanted + res_learn_bumps[res];
61777+
61778+ acl->res[res].rlim_cur = res_add;
61779+
61780+ if (wanted > acl->res[res].rlim_max)
61781+ acl->res[res].rlim_max = res_add;
61782+
61783+ /* only log the subject filename, since resource logging is supported for
61784+ single-subject learning only */
61785+ rcu_read_lock();
61786+ cred = __task_cred(task);
61787+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
61788+ task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
61789+ acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
61790+ "", (unsigned long) res, &task->signal->saved_ip);
61791+ rcu_read_unlock();
61792+ }
61793+
61794+ return;
61795+}
61796+EXPORT_SYMBOL(gr_learn_resource);
61797+#endif
61798+
61799+#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
61800+void
61801+pax_set_initial_flags(struct linux_binprm *bprm)
61802+{
61803+ struct task_struct *task = current;
61804+ struct acl_subject_label *proc;
61805+ unsigned long flags;
61806+
61807+ if (unlikely(!(gr_status & GR_READY)))
61808+ return;
61809+
61810+ flags = pax_get_flags(task);
61811+
61812+ proc = task->acl;
61813+
61814+ if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
61815+ flags &= ~MF_PAX_PAGEEXEC;
61816+ if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
61817+ flags &= ~MF_PAX_SEGMEXEC;
61818+ if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
61819+ flags &= ~MF_PAX_RANDMMAP;
61820+ if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
61821+ flags &= ~MF_PAX_EMUTRAMP;
61822+ if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
61823+ flags &= ~MF_PAX_MPROTECT;
61824+
61825+ if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
61826+ flags |= MF_PAX_PAGEEXEC;
61827+ if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
61828+ flags |= MF_PAX_SEGMEXEC;
61829+ if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
61830+ flags |= MF_PAX_RANDMMAP;
61831+ if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
61832+ flags |= MF_PAX_EMUTRAMP;
61833+ if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
61834+ flags |= MF_PAX_MPROTECT;
61835+
61836+ pax_set_flags(task, flags);
61837+
61838+ return;
61839+}
61840+#endif
61841+
61842+int
61843+gr_handle_proc_ptrace(struct task_struct *task)
61844+{
61845+ struct file *filp;
61846+ struct task_struct *tmp = task;
61847+ struct task_struct *curtemp = current;
61848+ __u32 retmode;
61849+
61850+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61851+ if (unlikely(!(gr_status & GR_READY)))
61852+ return 0;
61853+#endif
61854+
61855+ read_lock(&tasklist_lock);
61856+ read_lock(&grsec_exec_file_lock);
61857+ filp = task->exec_file;
61858+
61859+ while (task_pid_nr(tmp) > 0) {
61860+ if (tmp == curtemp)
61861+ break;
61862+ tmp = tmp->real_parent;
61863+ }
61864+
61865+ if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61866+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
61867+ read_unlock(&grsec_exec_file_lock);
61868+ read_unlock(&tasklist_lock);
61869+ return 1;
61870+ }
61871+
61872+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61873+ if (!(gr_status & GR_READY)) {
61874+ read_unlock(&grsec_exec_file_lock);
61875+ read_unlock(&tasklist_lock);
61876+ return 0;
61877+ }
61878+#endif
61879+
61880+ retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
61881+ read_unlock(&grsec_exec_file_lock);
61882+ read_unlock(&tasklist_lock);
61883+
61884+ if (retmode & GR_NOPTRACE)
61885+ return 1;
61886+
61887+ if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
61888+ && (current->acl != task->acl || (current->acl != current->role->root_label
61889+ && task_pid_nr(current) != task_pid_nr(task))))
61890+ return 1;
61891+
61892+ return 0;
61893+}
61894+
61895+void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
61896+{
61897+ if (unlikely(!(gr_status & GR_READY)))
61898+ return;
61899+
61900+ if (!(current->role->roletype & GR_ROLE_GOD))
61901+ return;
61902+
61903+ seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
61904+ p->role->rolename, gr_task_roletype_to_char(p),
61905+ p->acl->filename);
61906+}
61907+
61908+int
61909+gr_handle_ptrace(struct task_struct *task, const long request)
61910+{
61911+ struct task_struct *tmp = task;
61912+ struct task_struct *curtemp = current;
61913+ __u32 retmode;
61914+
61915+#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
61916+ if (unlikely(!(gr_status & GR_READY)))
61917+ return 0;
61918+#endif
61919+ if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
61920+ read_lock(&tasklist_lock);
61921+ while (task_pid_nr(tmp) > 0) {
61922+ if (tmp == curtemp)
61923+ break;
61924+ tmp = tmp->real_parent;
61925+ }
61926+
61927+ if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
61928+ ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
61929+ read_unlock(&tasklist_lock);
61930+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61931+ return 1;
61932+ }
61933+ read_unlock(&tasklist_lock);
61934+ }
61935+
61936+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
61937+ if (!(gr_status & GR_READY))
61938+ return 0;
61939+#endif
61940+
61941+ read_lock(&grsec_exec_file_lock);
61942+ if (unlikely(!task->exec_file)) {
61943+ read_unlock(&grsec_exec_file_lock);
61944+ return 0;
61945+ }
61946+
61947+ retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
61948+ read_unlock(&grsec_exec_file_lock);
61949+
61950+ if (retmode & GR_NOPTRACE) {
61951+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61952+ return 1;
61953+ }
61954+
61955+ if (retmode & GR_PTRACERD) {
61956+ switch (request) {
61957+ case PTRACE_SEIZE:
61958+ case PTRACE_POKETEXT:
61959+ case PTRACE_POKEDATA:
61960+ case PTRACE_POKEUSR:
61961+#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
61962+ case PTRACE_SETREGS:
61963+ case PTRACE_SETFPREGS:
61964+#endif
61965+#ifdef CONFIG_X86
61966+ case PTRACE_SETFPXREGS:
61967+#endif
61968+#ifdef CONFIG_ALTIVEC
61969+ case PTRACE_SETVRREGS:
61970+#endif
61971+ return 1;
61972+ default:
61973+ return 0;
61974+ }
61975+ } else if (!(current->acl->mode & GR_POVERRIDE) &&
61976+ !(current->role->roletype & GR_ROLE_GOD) &&
61977+ (current->acl != task->acl)) {
61978+ gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
61979+ return 1;
61980+ }
61981+
61982+ return 0;
61983+}
61984+
61985+static int is_writable_mmap(const struct file *filp)
61986+{
61987+ struct task_struct *task = current;
61988+ struct acl_object_label *obj, *obj2;
61989+
61990+ if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
61991+ !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))) {
61992+ obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
61993+ obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
61994+ task->role->root_label);
61995+ if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
61996+ gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
61997+ return 1;
61998+ }
61999+ }
62000+ return 0;
62001+}
62002+
62003+int
62004+gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
62005+{
62006+ __u32 mode;
62007+
62008+ if (unlikely(!file || !(prot & PROT_EXEC)))
62009+ return 1;
62010+
62011+ if (is_writable_mmap(file))
62012+ return 0;
62013+
62014+ mode =
62015+ gr_search_file(file->f_path.dentry,
62016+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62017+ file->f_path.mnt);
62018+
62019+ if (!gr_tpe_allow(file))
62020+ return 0;
62021+
62022+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62023+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62024+ return 0;
62025+ } else if (unlikely(!(mode & GR_EXEC))) {
62026+ return 0;
62027+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62028+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62029+ return 1;
62030+ }
62031+
62032+ return 1;
62033+}
62034+
62035+int
62036+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
62037+{
62038+ __u32 mode;
62039+
62040+ if (unlikely(!file || !(prot & PROT_EXEC)))
62041+ return 1;
62042+
62043+ if (is_writable_mmap(file))
62044+ return 0;
62045+
62046+ mode =
62047+ gr_search_file(file->f_path.dentry,
62048+ GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
62049+ file->f_path.mnt);
62050+
62051+ if (!gr_tpe_allow(file))
62052+ return 0;
62053+
62054+ if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
62055+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62056+ return 0;
62057+ } else if (unlikely(!(mode & GR_EXEC))) {
62058+ return 0;
62059+ } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
62060+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
62061+ return 1;
62062+ }
62063+
62064+ return 1;
62065+}
62066+
62067+void
62068+gr_acl_handle_psacct(struct task_struct *task, const long code)
62069+{
62070+ unsigned long runtime;
62071+ unsigned long cputime;
62072+ unsigned int wday, cday;
62073+ __u8 whr, chr;
62074+ __u8 wmin, cmin;
62075+ __u8 wsec, csec;
62076+ struct timespec timeval;
62077+
62078+ if (unlikely(!(gr_status & GR_READY) || !task->acl ||
62079+ !(task->acl->mode & GR_PROCACCT)))
62080+ return;
62081+
62082+ do_posix_clock_monotonic_gettime(&timeval);
62083+ runtime = timeval.tv_sec - task->start_time.tv_sec;
62084+ wday = runtime / (3600 * 24);
62085+ runtime -= wday * (3600 * 24);
62086+ whr = runtime / 3600;
62087+ runtime -= whr * 3600;
62088+ wmin = runtime / 60;
62089+ runtime -= wmin * 60;
62090+ wsec = runtime;
62091+
62092+ cputime = (task->utime + task->stime) / HZ;
62093+ cday = cputime / (3600 * 24);
62094+ cputime -= cday * (3600 * 24);
62095+ chr = cputime / 3600;
62096+ cputime -= chr * 3600;
62097+ cmin = cputime / 60;
62098+ cputime -= cmin * 60;
62099+ csec = cputime;
62100+
62101+ gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
62102+
62103+ return;
62104+}
62105+
62106+void gr_set_kernel_label(struct task_struct *task)
62107+{
62108+ if (gr_status & GR_READY) {
62109+ task->role = kernel_role;
62110+ task->acl = kernel_role->root_label;
62111+ }
62112+ return;
62113+}
62114+
62115+#ifdef CONFIG_TASKSTATS
62116+int gr_is_taskstats_denied(int pid)
62117+{
62118+ struct task_struct *task;
62119+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62120+ const struct cred *cred;
62121+#endif
62122+ int ret = 0;
62123+
62124+ /* restrict taskstats viewing to un-chrooted root users
62125+ who have the 'view' subject flag if the RBAC system is enabled
62126+ */
62127+
62128+ rcu_read_lock();
62129+ read_lock(&tasklist_lock);
62130+ task = find_task_by_vpid(pid);
62131+ if (task) {
62132+#ifdef CONFIG_GRKERNSEC_CHROOT
62133+ if (proc_is_chrooted(task))
62134+ ret = -EACCES;
62135+#endif
62136+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62137+ cred = __task_cred(task);
62138+#ifdef CONFIG_GRKERNSEC_PROC_USER
62139+ if (gr_is_global_nonroot(cred->uid))
62140+ ret = -EACCES;
62141+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62142+ if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
62143+ ret = -EACCES;
62144+#endif
62145+#endif
62146+ if (gr_status & GR_READY) {
62147+ if (!(task->acl->mode & GR_VIEW))
62148+ ret = -EACCES;
62149+ }
62150+ } else
62151+ ret = -ENOENT;
62152+
62153+ read_unlock(&tasklist_lock);
62154+ rcu_read_unlock();
62155+
62156+ return ret;
62157+}
62158+#endif
62159+
62160+/* AUXV entries are filled via a descendant of search_binary_handler
62161+ after we've already applied the subject for the target
62162+*/
62163+int gr_acl_enable_at_secure(void)
62164+{
62165+ if (unlikely(!(gr_status & GR_READY)))
62166+ return 0;
62167+
62168+ if (current->acl->mode & GR_ATSECURE)
62169+ return 1;
62170+
62171+ return 0;
62172+}
62173+
62174+int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
62175+{
62176+ struct task_struct *task = current;
62177+ struct dentry *dentry = file->f_path.dentry;
62178+ struct vfsmount *mnt = file->f_path.mnt;
62179+ struct acl_object_label *obj, *tmp;
62180+ struct acl_subject_label *subj;
62181+ unsigned int bufsize;
62182+ int is_not_root;
62183+ char *path;
62184+ dev_t dev = __get_dev(dentry);
62185+
62186+ if (unlikely(!(gr_status & GR_READY)))
62187+ return 1;
62188+
62189+ if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
62190+ return 1;
62191+
62192+ /* ignore Eric Biederman */
62193+ if (IS_PRIVATE(dentry->d_inode))
62194+ return 1;
62195+
62196+ subj = task->acl;
62197+ read_lock(&gr_inode_lock);
62198+ do {
62199+ obj = lookup_acl_obj_label(ino, dev, subj);
62200+ if (obj != NULL) {
62201+ read_unlock(&gr_inode_lock);
62202+ return (obj->mode & GR_FIND) ? 1 : 0;
62203+ }
62204+ } while ((subj = subj->parent_subject));
62205+ read_unlock(&gr_inode_lock);
62206+
62207+ /* this is purely an optimization since we're looking for an object
62208+ for the directory we're doing a readdir on
62209+ if it's possible for any globbed object to match the entry we're
62210+ filling into the directory, then the object we find here will be
62211+ an anchor point with attached globbed objects
62212+ */
62213+ obj = chk_obj_label_noglob(dentry, mnt, task->acl);
62214+ if (obj->globbed == NULL)
62215+ return (obj->mode & GR_FIND) ? 1 : 0;
62216+
62217+ is_not_root = ((obj->filename[0] == '/') &&
62218+ (obj->filename[1] == '\0')) ? 0 : 1;
62219+ bufsize = PAGE_SIZE - namelen - is_not_root;
62220+
62221+ /* check bufsize > PAGE_SIZE || bufsize == 0 */
62222+ if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
62223+ return 1;
62224+
62225+ preempt_disable();
62226+ path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
62227+ bufsize);
62228+
62229+ bufsize = strlen(path);
62230+
62231+ /* if base is "/", don't append an additional slash */
62232+ if (is_not_root)
62233+ *(path + bufsize) = '/';
62234+ memcpy(path + bufsize + is_not_root, name, namelen);
62235+ *(path + bufsize + namelen + is_not_root) = '\0';
62236+
62237+ tmp = obj->globbed;
62238+ while (tmp) {
62239+ if (!glob_match(tmp->filename, path)) {
62240+ preempt_enable();
62241+ return (tmp->mode & GR_FIND) ? 1 : 0;
62242+ }
62243+ tmp = tmp->next;
62244+ }
62245+ preempt_enable();
62246+ return (obj->mode & GR_FIND) ? 1 : 0;
62247+}
62248+
62249+void gr_put_exec_file(struct task_struct *task)
62250+{
62251+ struct file *filp;
62252+
62253+ write_lock(&grsec_exec_file_lock);
62254+ filp = task->exec_file;
62255+ task->exec_file = NULL;
62256+ write_unlock(&grsec_exec_file_lock);
62257+
62258+ if (filp)
62259+ fput(filp);
62260+
62261+ return;
62262+}
62263+
62264+
62265+#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
62266+EXPORT_SYMBOL(gr_acl_is_enabled);
62267+#endif
62268+EXPORT_SYMBOL(gr_set_kernel_label);
62269+#ifdef CONFIG_SECURITY
62270+EXPORT_SYMBOL(gr_check_user_change);
62271+EXPORT_SYMBOL(gr_check_group_change);
62272+#endif
62273+
62274diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
62275new file mode 100644
62276index 0000000..34fefda
62277--- /dev/null
62278+++ b/grsecurity/gracl_alloc.c
62279@@ -0,0 +1,105 @@
62280+#include <linux/kernel.h>
62281+#include <linux/mm.h>
62282+#include <linux/slab.h>
62283+#include <linux/vmalloc.h>
62284+#include <linux/gracl.h>
62285+#include <linux/grsecurity.h>
62286+
62287+static unsigned long alloc_stack_next = 1;
62288+static unsigned long alloc_stack_size = 1;
62289+static void **alloc_stack;
62290+
62291+static __inline__ int
62292+alloc_pop(void)
62293+{
62294+ if (alloc_stack_next == 1)
62295+ return 0;
62296+
62297+ kfree(alloc_stack[alloc_stack_next - 2]);
62298+
62299+ alloc_stack_next--;
62300+
62301+ return 1;
62302+}
62303+
62304+static __inline__ int
62305+alloc_push(void *buf)
62306+{
62307+ if (alloc_stack_next >= alloc_stack_size)
62308+ return 1;
62309+
62310+ alloc_stack[alloc_stack_next - 1] = buf;
62311+
62312+ alloc_stack_next++;
62313+
62314+ return 0;
62315+}
62316+
62317+void *
62318+acl_alloc(unsigned long len)
62319+{
62320+ void *ret = NULL;
62321+
62322+ if (!len || len > PAGE_SIZE)
62323+ goto out;
62324+
62325+ ret = kmalloc(len, GFP_KERNEL);
62326+
62327+ if (ret) {
62328+ if (alloc_push(ret)) {
62329+ kfree(ret);
62330+ ret = NULL;
62331+ }
62332+ }
62333+
62334+out:
62335+ return ret;
62336+}
62337+
62338+void *
62339+acl_alloc_num(unsigned long num, unsigned long len)
62340+{
62341+ if (!len || (num > (PAGE_SIZE / len)))
62342+ return NULL;
62343+
62344+ return acl_alloc(num * len);
62345+}
62346+
62347+void
62348+acl_free_all(void)
62349+{
62350+ if (gr_acl_is_enabled() || !alloc_stack)
62351+ return;
62352+
62353+ while (alloc_pop()) ;
62354+
62355+ if (alloc_stack) {
62356+ if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
62357+ kfree(alloc_stack);
62358+ else
62359+ vfree(alloc_stack);
62360+ }
62361+
62362+ alloc_stack = NULL;
62363+ alloc_stack_size = 1;
62364+ alloc_stack_next = 1;
62365+
62366+ return;
62367+}
62368+
62369+int
62370+acl_alloc_stack_init(unsigned long size)
62371+{
62372+ if ((size * sizeof (void *)) <= PAGE_SIZE)
62373+ alloc_stack =
62374+ (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
62375+ else
62376+ alloc_stack = (void **) vmalloc(size * sizeof (void *));
62377+
62378+ alloc_stack_size = size;
62379+
62380+ if (!alloc_stack)
62381+ return 0;
62382+ else
62383+ return 1;
62384+}
62385diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
62386new file mode 100644
62387index 0000000..bdd51ea
62388--- /dev/null
62389+++ b/grsecurity/gracl_cap.c
62390@@ -0,0 +1,110 @@
62391+#include <linux/kernel.h>
62392+#include <linux/module.h>
62393+#include <linux/sched.h>
62394+#include <linux/gracl.h>
62395+#include <linux/grsecurity.h>
62396+#include <linux/grinternal.h>
62397+
62398+extern const char *captab_log[];
62399+extern int captab_log_entries;
62400+
62401+int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62402+{
62403+ struct acl_subject_label *curracl;
62404+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62405+ kernel_cap_t cap_audit = __cap_empty_set;
62406+
62407+ if (!gr_acl_is_enabled())
62408+ return 1;
62409+
62410+ curracl = task->acl;
62411+
62412+ cap_drop = curracl->cap_lower;
62413+ cap_mask = curracl->cap_mask;
62414+ cap_audit = curracl->cap_invert_audit;
62415+
62416+ while ((curracl = curracl->parent_subject)) {
62417+ /* if the cap isn't specified in the current computed mask but is specified in the
62418+ current level subject, and is lowered in the current level subject, then add
62419+ it to the set of dropped capabilities
62420+ otherwise, add the current level subject's mask to the current computed mask
62421+ */
62422+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62423+ cap_raise(cap_mask, cap);
62424+ if (cap_raised(curracl->cap_lower, cap))
62425+ cap_raise(cap_drop, cap);
62426+ if (cap_raised(curracl->cap_invert_audit, cap))
62427+ cap_raise(cap_audit, cap);
62428+ }
62429+ }
62430+
62431+ if (!cap_raised(cap_drop, cap)) {
62432+ if (cap_raised(cap_audit, cap))
62433+ gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
62434+ return 1;
62435+ }
62436+
62437+ curracl = task->acl;
62438+
62439+ if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
62440+ && cap_raised(cred->cap_effective, cap)) {
62441+ security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
62442+ task->role->roletype, GR_GLOBAL_UID(cred->uid),
62443+ GR_GLOBAL_GID(cred->gid), task->exec_file ?
62444+ gr_to_filename(task->exec_file->f_path.dentry,
62445+ task->exec_file->f_path.mnt) : curracl->filename,
62446+ curracl->filename, 0UL,
62447+ 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
62448+ return 1;
62449+ }
62450+
62451+ if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
62452+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
62453+
62454+ return 0;
62455+}
62456+
62457+int
62458+gr_acl_is_capable(const int cap)
62459+{
62460+ return gr_task_acl_is_capable(current, current_cred(), cap);
62461+}
62462+
62463+int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
62464+{
62465+ struct acl_subject_label *curracl;
62466+ kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
62467+
62468+ if (!gr_acl_is_enabled())
62469+ return 1;
62470+
62471+ curracl = task->acl;
62472+
62473+ cap_drop = curracl->cap_lower;
62474+ cap_mask = curracl->cap_mask;
62475+
62476+ while ((curracl = curracl->parent_subject)) {
62477+ /* if the cap isn't specified in the current computed mask but is specified in the
62478+ current level subject, and is lowered in the current level subject, then add
62479+ it to the set of dropped capabilities
62480+ otherwise, add the current level subject's mask to the current computed mask
62481+ */
62482+ if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
62483+ cap_raise(cap_mask, cap);
62484+ if (cap_raised(curracl->cap_lower, cap))
62485+ cap_raise(cap_drop, cap);
62486+ }
62487+ }
62488+
62489+ if (!cap_raised(cap_drop, cap))
62490+ return 1;
62491+
62492+ return 0;
62493+}
62494+
62495+int
62496+gr_acl_is_capable_nolog(const int cap)
62497+{
62498+ return gr_task_acl_is_capable_nolog(current, cap);
62499+}
62500+
62501diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
62502new file mode 100644
62503index 0000000..a340c17
62504--- /dev/null
62505+++ b/grsecurity/gracl_fs.c
62506@@ -0,0 +1,431 @@
62507+#include <linux/kernel.h>
62508+#include <linux/sched.h>
62509+#include <linux/types.h>
62510+#include <linux/fs.h>
62511+#include <linux/file.h>
62512+#include <linux/stat.h>
62513+#include <linux/grsecurity.h>
62514+#include <linux/grinternal.h>
62515+#include <linux/gracl.h>
62516+
62517+umode_t
62518+gr_acl_umask(void)
62519+{
62520+ if (unlikely(!gr_acl_is_enabled()))
62521+ return 0;
62522+
62523+ return current->role->umask;
62524+}
62525+
62526+__u32
62527+gr_acl_handle_hidden_file(const struct dentry * dentry,
62528+ const struct vfsmount * mnt)
62529+{
62530+ __u32 mode;
62531+
62532+ if (unlikely(!dentry->d_inode))
62533+ return GR_FIND;
62534+
62535+ mode =
62536+ gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
62537+
62538+ if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
62539+ gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62540+ return mode;
62541+ } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
62542+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
62543+ return 0;
62544+ } else if (unlikely(!(mode & GR_FIND)))
62545+ return 0;
62546+
62547+ return GR_FIND;
62548+}
62549+
62550+__u32
62551+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
62552+ int acc_mode)
62553+{
62554+ __u32 reqmode = GR_FIND;
62555+ __u32 mode;
62556+
62557+ if (unlikely(!dentry->d_inode))
62558+ return reqmode;
62559+
62560+ if (acc_mode & MAY_APPEND)
62561+ reqmode |= GR_APPEND;
62562+ else if (acc_mode & MAY_WRITE)
62563+ reqmode |= GR_WRITE;
62564+ if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
62565+ reqmode |= GR_READ;
62566+
62567+ mode =
62568+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62569+ mnt);
62570+
62571+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62572+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62573+ reqmode & GR_READ ? " reading" : "",
62574+ reqmode & GR_WRITE ? " writing" : reqmode &
62575+ GR_APPEND ? " appending" : "");
62576+ return reqmode;
62577+ } else
62578+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62579+ {
62580+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
62581+ reqmode & GR_READ ? " reading" : "",
62582+ reqmode & GR_WRITE ? " writing" : reqmode &
62583+ GR_APPEND ? " appending" : "");
62584+ return 0;
62585+ } else if (unlikely((mode & reqmode) != reqmode))
62586+ return 0;
62587+
62588+ return reqmode;
62589+}
62590+
62591+__u32
62592+gr_acl_handle_creat(const struct dentry * dentry,
62593+ const struct dentry * p_dentry,
62594+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
62595+ const int imode)
62596+{
62597+ __u32 reqmode = GR_WRITE | GR_CREATE;
62598+ __u32 mode;
62599+
62600+ if (acc_mode & MAY_APPEND)
62601+ reqmode |= GR_APPEND;
62602+ // if a directory was required or the directory already exists, then
62603+ // don't count this open as a read
62604+ if ((acc_mode & MAY_READ) &&
62605+ !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
62606+ reqmode |= GR_READ;
62607+ if ((open_flags & O_CREAT) &&
62608+ ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62609+ reqmode |= GR_SETID;
62610+
62611+ mode =
62612+ gr_check_create(dentry, p_dentry, p_mnt,
62613+ reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62614+
62615+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62616+ gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62617+ reqmode & GR_READ ? " reading" : "",
62618+ reqmode & GR_WRITE ? " writing" : reqmode &
62619+ GR_APPEND ? " appending" : "");
62620+ return reqmode;
62621+ } else
62622+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62623+ {
62624+ gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
62625+ reqmode & GR_READ ? " reading" : "",
62626+ reqmode & GR_WRITE ? " writing" : reqmode &
62627+ GR_APPEND ? " appending" : "");
62628+ return 0;
62629+ } else if (unlikely((mode & reqmode) != reqmode))
62630+ return 0;
62631+
62632+ return reqmode;
62633+}
62634+
62635+__u32
62636+gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
62637+ const int fmode)
62638+{
62639+ __u32 mode, reqmode = GR_FIND;
62640+
62641+ if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
62642+ reqmode |= GR_EXEC;
62643+ if (fmode & S_IWOTH)
62644+ reqmode |= GR_WRITE;
62645+ if (fmode & S_IROTH)
62646+ reqmode |= GR_READ;
62647+
62648+ mode =
62649+ gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
62650+ mnt);
62651+
62652+ if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
62653+ gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62654+ reqmode & GR_READ ? " reading" : "",
62655+ reqmode & GR_WRITE ? " writing" : "",
62656+ reqmode & GR_EXEC ? " executing" : "");
62657+ return reqmode;
62658+ } else
62659+ if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
62660+ {
62661+ gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
62662+ reqmode & GR_READ ? " reading" : "",
62663+ reqmode & GR_WRITE ? " writing" : "",
62664+ reqmode & GR_EXEC ? " executing" : "");
62665+ return 0;
62666+ } else if (unlikely((mode & reqmode) != reqmode))
62667+ return 0;
62668+
62669+ return reqmode;
62670+}
62671+
62672+static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
62673+{
62674+ __u32 mode;
62675+
62676+ mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
62677+
62678+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62679+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
62680+ return mode;
62681+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62682+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
62683+ return 0;
62684+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62685+ return 0;
62686+
62687+ return (reqmode);
62688+}
62689+
62690+__u32
62691+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
62692+{
62693+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
62694+}
62695+
62696+__u32
62697+gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
62698+{
62699+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
62700+}
62701+
62702+__u32
62703+gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
62704+{
62705+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
62706+}
62707+
62708+__u32
62709+gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
62710+{
62711+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
62712+}
62713+
62714+__u32
62715+gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
62716+ umode_t *modeptr)
62717+{
62718+ umode_t mode;
62719+
62720+ *modeptr &= ~gr_acl_umask();
62721+ mode = *modeptr;
62722+
62723+ if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
62724+ return 1;
62725+
62726+ if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
62727+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
62728+ return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
62729+ GR_CHMOD_ACL_MSG);
62730+ } else {
62731+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
62732+ }
62733+}
62734+
62735+__u32
62736+gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
62737+{
62738+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
62739+}
62740+
62741+__u32
62742+gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
62743+{
62744+ return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
62745+}
62746+
62747+__u32
62748+gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
62749+{
62750+ return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
62751+}
62752+
62753+__u32
62754+gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
62755+{
62756+ return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
62757+ GR_UNIXCONNECT_ACL_MSG);
62758+}
62759+
62760+/* hardlinks require at minimum create and link permission,
62761+ any additional privilege required is based on the
62762+ privilege of the file being linked to
62763+*/
62764+__u32
62765+gr_acl_handle_link(const struct dentry * new_dentry,
62766+ const struct dentry * parent_dentry,
62767+ const struct vfsmount * parent_mnt,
62768+ const struct dentry * old_dentry,
62769+ const struct vfsmount * old_mnt, const struct filename *to)
62770+{
62771+ __u32 mode;
62772+ __u32 needmode = GR_CREATE | GR_LINK;
62773+ __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
62774+
62775+ mode =
62776+ gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
62777+ old_mnt);
62778+
62779+ if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
62780+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62781+ return mode;
62782+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62783+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
62784+ return 0;
62785+ } else if (unlikely((mode & needmode) != needmode))
62786+ return 0;
62787+
62788+ return 1;
62789+}
62790+
62791+__u32
62792+gr_acl_handle_symlink(const struct dentry * new_dentry,
62793+ const struct dentry * parent_dentry,
62794+ const struct vfsmount * parent_mnt, const struct filename *from)
62795+{
62796+ __u32 needmode = GR_WRITE | GR_CREATE;
62797+ __u32 mode;
62798+
62799+ mode =
62800+ gr_check_create(new_dentry, parent_dentry, parent_mnt,
62801+ GR_CREATE | GR_AUDIT_CREATE |
62802+ GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
62803+
62804+ if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
62805+ gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62806+ return mode;
62807+ } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
62808+ gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
62809+ return 0;
62810+ } else if (unlikely((mode & needmode) != needmode))
62811+ return 0;
62812+
62813+ return (GR_WRITE | GR_CREATE);
62814+}
62815+
62816+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)
62817+{
62818+ __u32 mode;
62819+
62820+ mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
62821+
62822+ if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
62823+ gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
62824+ return mode;
62825+ } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
62826+ gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
62827+ return 0;
62828+ } else if (unlikely((mode & (reqmode)) != (reqmode)))
62829+ return 0;
62830+
62831+ return (reqmode);
62832+}
62833+
62834+__u32
62835+gr_acl_handle_mknod(const struct dentry * new_dentry,
62836+ const struct dentry * parent_dentry,
62837+ const struct vfsmount * parent_mnt,
62838+ const int mode)
62839+{
62840+ __u32 reqmode = GR_WRITE | GR_CREATE;
62841+ if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
62842+ reqmode |= GR_SETID;
62843+
62844+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62845+ reqmode, GR_MKNOD_ACL_MSG);
62846+}
62847+
62848+__u32
62849+gr_acl_handle_mkdir(const struct dentry *new_dentry,
62850+ const struct dentry *parent_dentry,
62851+ const struct vfsmount *parent_mnt)
62852+{
62853+ return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
62854+ GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
62855+}
62856+
62857+#define RENAME_CHECK_SUCCESS(old, new) \
62858+ (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
62859+ ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
62860+
62861+int
62862+gr_acl_handle_rename(struct dentry *new_dentry,
62863+ struct dentry *parent_dentry,
62864+ const struct vfsmount *parent_mnt,
62865+ struct dentry *old_dentry,
62866+ struct inode *old_parent_inode,
62867+ struct vfsmount *old_mnt, const struct filename *newname)
62868+{
62869+ __u32 comp1, comp2;
62870+ int error = 0;
62871+
62872+ if (unlikely(!gr_acl_is_enabled()))
62873+ return 0;
62874+
62875+ if (!new_dentry->d_inode) {
62876+ comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
62877+ GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
62878+ GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
62879+ comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
62880+ GR_DELETE | GR_AUDIT_DELETE |
62881+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62882+ GR_SUPPRESS, old_mnt);
62883+ } else {
62884+ comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
62885+ GR_CREATE | GR_DELETE |
62886+ GR_AUDIT_CREATE | GR_AUDIT_DELETE |
62887+ GR_AUDIT_READ | GR_AUDIT_WRITE |
62888+ GR_SUPPRESS, parent_mnt);
62889+ comp2 =
62890+ gr_search_file(old_dentry,
62891+ GR_READ | GR_WRITE | GR_AUDIT_READ |
62892+ GR_DELETE | GR_AUDIT_DELETE |
62893+ GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
62894+ }
62895+
62896+ if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
62897+ ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
62898+ gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62899+ else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
62900+ && !(comp2 & GR_SUPPRESS)) {
62901+ gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
62902+ error = -EACCES;
62903+ } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
62904+ error = -EACCES;
62905+
62906+ return error;
62907+}
62908+
62909+void
62910+gr_acl_handle_exit(void)
62911+{
62912+ u16 id;
62913+ char *rolename;
62914+
62915+ if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
62916+ !(current->role->roletype & GR_ROLE_PERSIST))) {
62917+ id = current->acl_role_id;
62918+ rolename = current->role->rolename;
62919+ gr_set_acls(1);
62920+ gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
62921+ }
62922+
62923+ gr_put_exec_file(current);
62924+ return;
62925+}
62926+
62927+int
62928+gr_acl_handle_procpidmem(const struct task_struct *task)
62929+{
62930+ if (unlikely(!gr_acl_is_enabled()))
62931+ return 0;
62932+
62933+ if (task != current && task->acl->mode & GR_PROTPROCFD)
62934+ return -EACCES;
62935+
62936+ return 0;
62937+}
62938diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
62939new file mode 100644
62940index 0000000..8132048
62941--- /dev/null
62942+++ b/grsecurity/gracl_ip.c
62943@@ -0,0 +1,387 @@
62944+#include <linux/kernel.h>
62945+#include <asm/uaccess.h>
62946+#include <asm/errno.h>
62947+#include <net/sock.h>
62948+#include <linux/file.h>
62949+#include <linux/fs.h>
62950+#include <linux/net.h>
62951+#include <linux/in.h>
62952+#include <linux/skbuff.h>
62953+#include <linux/ip.h>
62954+#include <linux/udp.h>
62955+#include <linux/types.h>
62956+#include <linux/sched.h>
62957+#include <linux/netdevice.h>
62958+#include <linux/inetdevice.h>
62959+#include <linux/gracl.h>
62960+#include <linux/grsecurity.h>
62961+#include <linux/grinternal.h>
62962+
62963+#define GR_BIND 0x01
62964+#define GR_CONNECT 0x02
62965+#define GR_INVERT 0x04
62966+#define GR_BINDOVERRIDE 0x08
62967+#define GR_CONNECTOVERRIDE 0x10
62968+#define GR_SOCK_FAMILY 0x20
62969+
62970+static const char * gr_protocols[IPPROTO_MAX] = {
62971+ "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
62972+ "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
62973+ "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
62974+ "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
62975+ "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
62976+ "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
62977+ "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
62978+ "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
62979+ "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
62980+ "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
62981+ "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
62982+ "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
62983+ "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
62984+ "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
62985+ "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
62986+ "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
62987+ "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
62988+ "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
62989+ "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
62990+ "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
62991+ "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
62992+ "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
62993+ "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
62994+ "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
62995+ "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
62996+ "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
62997+ "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
62998+ "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
62999+ "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
63000+ "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
63001+ "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
63002+ "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
63003+ };
63004+
63005+static const char * gr_socktypes[SOCK_MAX] = {
63006+ "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
63007+ "unknown:7", "unknown:8", "unknown:9", "packet"
63008+ };
63009+
63010+static const char * gr_sockfamilies[AF_MAX+1] = {
63011+ "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
63012+ "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
63013+ "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
63014+ "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
63015+ };
63016+
63017+const char *
63018+gr_proto_to_name(unsigned char proto)
63019+{
63020+ return gr_protocols[proto];
63021+}
63022+
63023+const char *
63024+gr_socktype_to_name(unsigned char type)
63025+{
63026+ return gr_socktypes[type];
63027+}
63028+
63029+const char *
63030+gr_sockfamily_to_name(unsigned char family)
63031+{
63032+ return gr_sockfamilies[family];
63033+}
63034+
63035+int
63036+gr_search_socket(const int domain, const int type, const int protocol)
63037+{
63038+ struct acl_subject_label *curr;
63039+ const struct cred *cred = current_cred();
63040+
63041+ if (unlikely(!gr_acl_is_enabled()))
63042+ goto exit;
63043+
63044+ if ((domain < 0) || (type < 0) || (protocol < 0) ||
63045+ (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
63046+ goto exit; // let the kernel handle it
63047+
63048+ curr = current->acl;
63049+
63050+ if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
63051+ /* the family is allowed, if this is PF_INET allow it only if
63052+ the extra sock type/protocol checks pass */
63053+ if (domain == PF_INET)
63054+ goto inet_check;
63055+ goto exit;
63056+ } else {
63057+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63058+ __u32 fakeip = 0;
63059+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63060+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63061+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63062+ gr_to_filename(current->exec_file->f_path.dentry,
63063+ current->exec_file->f_path.mnt) :
63064+ curr->filename, curr->filename,
63065+ &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
63066+ &current->signal->saved_ip);
63067+ goto exit;
63068+ }
63069+ goto exit_fail;
63070+ }
63071+
63072+inet_check:
63073+ /* the rest of this checking is for IPv4 only */
63074+ if (!curr->ips)
63075+ goto exit;
63076+
63077+ if ((curr->ip_type & (1U << type)) &&
63078+ (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
63079+ goto exit;
63080+
63081+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63082+ /* we don't place acls on raw sockets , and sometimes
63083+ dgram/ip sockets are opened for ioctl and not
63084+ bind/connect, so we'll fake a bind learn log */
63085+ if (type == SOCK_RAW || type == SOCK_PACKET) {
63086+ __u32 fakeip = 0;
63087+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63088+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63089+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63090+ gr_to_filename(current->exec_file->f_path.dentry,
63091+ current->exec_file->f_path.mnt) :
63092+ curr->filename, curr->filename,
63093+ &fakeip, 0, type,
63094+ protocol, GR_CONNECT, &current->signal->saved_ip);
63095+ } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
63096+ __u32 fakeip = 0;
63097+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63098+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63099+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63100+ gr_to_filename(current->exec_file->f_path.dentry,
63101+ current->exec_file->f_path.mnt) :
63102+ curr->filename, curr->filename,
63103+ &fakeip, 0, type,
63104+ protocol, GR_BIND, &current->signal->saved_ip);
63105+ }
63106+ /* we'll log when they use connect or bind */
63107+ goto exit;
63108+ }
63109+
63110+exit_fail:
63111+ if (domain == PF_INET)
63112+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
63113+ gr_socktype_to_name(type), gr_proto_to_name(protocol));
63114+ else
63115+#ifndef CONFIG_IPV6
63116+ if (domain != PF_INET6)
63117+#endif
63118+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
63119+ gr_socktype_to_name(type), protocol);
63120+
63121+ return 0;
63122+exit:
63123+ return 1;
63124+}
63125+
63126+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)
63127+{
63128+ if ((ip->mode & mode) &&
63129+ (ip_port >= ip->low) &&
63130+ (ip_port <= ip->high) &&
63131+ ((ntohl(ip_addr) & our_netmask) ==
63132+ (ntohl(our_addr) & our_netmask))
63133+ && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
63134+ && (ip->type & (1U << type))) {
63135+ if (ip->mode & GR_INVERT)
63136+ return 2; // specifically denied
63137+ else
63138+ return 1; // allowed
63139+ }
63140+
63141+ return 0; // not specifically allowed, may continue parsing
63142+}
63143+
63144+static int
63145+gr_search_connectbind(const int full_mode, struct sock *sk,
63146+ struct sockaddr_in *addr, const int type)
63147+{
63148+ char iface[IFNAMSIZ] = {0};
63149+ struct acl_subject_label *curr;
63150+ struct acl_ip_label *ip;
63151+ struct inet_sock *isk;
63152+ struct net_device *dev;
63153+ struct in_device *idev;
63154+ unsigned long i;
63155+ int ret;
63156+ int mode = full_mode & (GR_BIND | GR_CONNECT);
63157+ __u32 ip_addr = 0;
63158+ __u32 our_addr;
63159+ __u32 our_netmask;
63160+ char *p;
63161+ __u16 ip_port = 0;
63162+ const struct cred *cred = current_cred();
63163+
63164+ if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
63165+ return 0;
63166+
63167+ curr = current->acl;
63168+ isk = inet_sk(sk);
63169+
63170+ /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
63171+ if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
63172+ addr->sin_addr.s_addr = curr->inaddr_any_override;
63173+ if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
63174+ struct sockaddr_in saddr;
63175+ int err;
63176+
63177+ saddr.sin_family = AF_INET;
63178+ saddr.sin_addr.s_addr = curr->inaddr_any_override;
63179+ saddr.sin_port = isk->inet_sport;
63180+
63181+ err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63182+ if (err)
63183+ return err;
63184+
63185+ err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
63186+ if (err)
63187+ return err;
63188+ }
63189+
63190+ if (!curr->ips)
63191+ return 0;
63192+
63193+ ip_addr = addr->sin_addr.s_addr;
63194+ ip_port = ntohs(addr->sin_port);
63195+
63196+ if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
63197+ security_learn(GR_IP_LEARN_MSG, current->role->rolename,
63198+ current->role->roletype, GR_GLOBAL_UID(cred->uid),
63199+ GR_GLOBAL_GID(cred->gid), current->exec_file ?
63200+ gr_to_filename(current->exec_file->f_path.dentry,
63201+ current->exec_file->f_path.mnt) :
63202+ curr->filename, curr->filename,
63203+ &ip_addr, ip_port, type,
63204+ sk->sk_protocol, mode, &current->signal->saved_ip);
63205+ return 0;
63206+ }
63207+
63208+ for (i = 0; i < curr->ip_num; i++) {
63209+ ip = *(curr->ips + i);
63210+ if (ip->iface != NULL) {
63211+ strncpy(iface, ip->iface, IFNAMSIZ - 1);
63212+ p = strchr(iface, ':');
63213+ if (p != NULL)
63214+ *p = '\0';
63215+ dev = dev_get_by_name(sock_net(sk), iface);
63216+ if (dev == NULL)
63217+ continue;
63218+ idev = in_dev_get(dev);
63219+ if (idev == NULL) {
63220+ dev_put(dev);
63221+ continue;
63222+ }
63223+ rcu_read_lock();
63224+ for_ifa(idev) {
63225+ if (!strcmp(ip->iface, ifa->ifa_label)) {
63226+ our_addr = ifa->ifa_address;
63227+ our_netmask = 0xffffffff;
63228+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63229+ if (ret == 1) {
63230+ rcu_read_unlock();
63231+ in_dev_put(idev);
63232+ dev_put(dev);
63233+ return 0;
63234+ } else if (ret == 2) {
63235+ rcu_read_unlock();
63236+ in_dev_put(idev);
63237+ dev_put(dev);
63238+ goto denied;
63239+ }
63240+ }
63241+ } endfor_ifa(idev);
63242+ rcu_read_unlock();
63243+ in_dev_put(idev);
63244+ dev_put(dev);
63245+ } else {
63246+ our_addr = ip->addr;
63247+ our_netmask = ip->netmask;
63248+ ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
63249+ if (ret == 1)
63250+ return 0;
63251+ else if (ret == 2)
63252+ goto denied;
63253+ }
63254+ }
63255+
63256+denied:
63257+ if (mode == GR_BIND)
63258+ 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));
63259+ else if (mode == GR_CONNECT)
63260+ 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));
63261+
63262+ return -EACCES;
63263+}
63264+
63265+int
63266+gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
63267+{
63268+ /* always allow disconnection of dgram sockets with connect */
63269+ if (addr->sin_family == AF_UNSPEC)
63270+ return 0;
63271+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
63272+}
63273+
63274+int
63275+gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
63276+{
63277+ return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
63278+}
63279+
63280+int gr_search_listen(struct socket *sock)
63281+{
63282+ struct sock *sk = sock->sk;
63283+ struct sockaddr_in addr;
63284+
63285+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63286+ addr.sin_port = inet_sk(sk)->inet_sport;
63287+
63288+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63289+}
63290+
63291+int gr_search_accept(struct socket *sock)
63292+{
63293+ struct sock *sk = sock->sk;
63294+ struct sockaddr_in addr;
63295+
63296+ addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
63297+ addr.sin_port = inet_sk(sk)->inet_sport;
63298+
63299+ return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
63300+}
63301+
63302+int
63303+gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
63304+{
63305+ if (addr)
63306+ return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
63307+ else {
63308+ struct sockaddr_in sin;
63309+ const struct inet_sock *inet = inet_sk(sk);
63310+
63311+ sin.sin_addr.s_addr = inet->inet_daddr;
63312+ sin.sin_port = inet->inet_dport;
63313+
63314+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63315+ }
63316+}
63317+
63318+int
63319+gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
63320+{
63321+ struct sockaddr_in sin;
63322+
63323+ if (unlikely(skb->len < sizeof (struct udphdr)))
63324+ return 0; // skip this packet
63325+
63326+ sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
63327+ sin.sin_port = udp_hdr(skb)->source;
63328+
63329+ return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
63330+}
63331diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
63332new file mode 100644
63333index 0000000..25f54ef
63334--- /dev/null
63335+++ b/grsecurity/gracl_learn.c
63336@@ -0,0 +1,207 @@
63337+#include <linux/kernel.h>
63338+#include <linux/mm.h>
63339+#include <linux/sched.h>
63340+#include <linux/poll.h>
63341+#include <linux/string.h>
63342+#include <linux/file.h>
63343+#include <linux/types.h>
63344+#include <linux/vmalloc.h>
63345+#include <linux/grinternal.h>
63346+
63347+extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
63348+ size_t count, loff_t *ppos);
63349+extern int gr_acl_is_enabled(void);
63350+
63351+static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
63352+static int gr_learn_attached;
63353+
63354+/* use a 512k buffer */
63355+#define LEARN_BUFFER_SIZE (512 * 1024)
63356+
63357+static DEFINE_SPINLOCK(gr_learn_lock);
63358+static DEFINE_MUTEX(gr_learn_user_mutex);
63359+
63360+/* we need to maintain two buffers, so that the kernel context of grlearn
63361+ uses a semaphore around the userspace copying, and the other kernel contexts
63362+ use a spinlock when copying into the buffer, since they cannot sleep
63363+*/
63364+static char *learn_buffer;
63365+static char *learn_buffer_user;
63366+static int learn_buffer_len;
63367+static int learn_buffer_user_len;
63368+
63369+static ssize_t
63370+read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
63371+{
63372+ DECLARE_WAITQUEUE(wait, current);
63373+ ssize_t retval = 0;
63374+
63375+ add_wait_queue(&learn_wait, &wait);
63376+ set_current_state(TASK_INTERRUPTIBLE);
63377+ do {
63378+ mutex_lock(&gr_learn_user_mutex);
63379+ spin_lock(&gr_learn_lock);
63380+ if (learn_buffer_len)
63381+ break;
63382+ spin_unlock(&gr_learn_lock);
63383+ mutex_unlock(&gr_learn_user_mutex);
63384+ if (file->f_flags & O_NONBLOCK) {
63385+ retval = -EAGAIN;
63386+ goto out;
63387+ }
63388+ if (signal_pending(current)) {
63389+ retval = -ERESTARTSYS;
63390+ goto out;
63391+ }
63392+
63393+ schedule();
63394+ } while (1);
63395+
63396+ memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
63397+ learn_buffer_user_len = learn_buffer_len;
63398+ retval = learn_buffer_len;
63399+ learn_buffer_len = 0;
63400+
63401+ spin_unlock(&gr_learn_lock);
63402+
63403+ if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
63404+ retval = -EFAULT;
63405+
63406+ mutex_unlock(&gr_learn_user_mutex);
63407+out:
63408+ set_current_state(TASK_RUNNING);
63409+ remove_wait_queue(&learn_wait, &wait);
63410+ return retval;
63411+}
63412+
63413+static unsigned int
63414+poll_learn(struct file * file, poll_table * wait)
63415+{
63416+ poll_wait(file, &learn_wait, wait);
63417+
63418+ if (learn_buffer_len)
63419+ return (POLLIN | POLLRDNORM);
63420+
63421+ return 0;
63422+}
63423+
63424+void
63425+gr_clear_learn_entries(void)
63426+{
63427+ char *tmp;
63428+
63429+ mutex_lock(&gr_learn_user_mutex);
63430+ spin_lock(&gr_learn_lock);
63431+ tmp = learn_buffer;
63432+ learn_buffer = NULL;
63433+ spin_unlock(&gr_learn_lock);
63434+ if (tmp)
63435+ vfree(tmp);
63436+ if (learn_buffer_user != NULL) {
63437+ vfree(learn_buffer_user);
63438+ learn_buffer_user = NULL;
63439+ }
63440+ learn_buffer_len = 0;
63441+ mutex_unlock(&gr_learn_user_mutex);
63442+
63443+ return;
63444+}
63445+
63446+void
63447+gr_add_learn_entry(const char *fmt, ...)
63448+{
63449+ va_list args;
63450+ unsigned int len;
63451+
63452+ if (!gr_learn_attached)
63453+ return;
63454+
63455+ spin_lock(&gr_learn_lock);
63456+
63457+ /* leave a gap at the end so we know when it's "full" but don't have to
63458+ compute the exact length of the string we're trying to append
63459+ */
63460+ if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
63461+ spin_unlock(&gr_learn_lock);
63462+ wake_up_interruptible(&learn_wait);
63463+ return;
63464+ }
63465+ if (learn_buffer == NULL) {
63466+ spin_unlock(&gr_learn_lock);
63467+ return;
63468+ }
63469+
63470+ va_start(args, fmt);
63471+ len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
63472+ va_end(args);
63473+
63474+ learn_buffer_len += len + 1;
63475+
63476+ spin_unlock(&gr_learn_lock);
63477+ wake_up_interruptible(&learn_wait);
63478+
63479+ return;
63480+}
63481+
63482+static int
63483+open_learn(struct inode *inode, struct file *file)
63484+{
63485+ if (file->f_mode & FMODE_READ && gr_learn_attached)
63486+ return -EBUSY;
63487+ if (file->f_mode & FMODE_READ) {
63488+ int retval = 0;
63489+ mutex_lock(&gr_learn_user_mutex);
63490+ if (learn_buffer == NULL)
63491+ learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
63492+ if (learn_buffer_user == NULL)
63493+ learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
63494+ if (learn_buffer == NULL) {
63495+ retval = -ENOMEM;
63496+ goto out_error;
63497+ }
63498+ if (learn_buffer_user == NULL) {
63499+ retval = -ENOMEM;
63500+ goto out_error;
63501+ }
63502+ learn_buffer_len = 0;
63503+ learn_buffer_user_len = 0;
63504+ gr_learn_attached = 1;
63505+out_error:
63506+ mutex_unlock(&gr_learn_user_mutex);
63507+ return retval;
63508+ }
63509+ return 0;
63510+}
63511+
63512+static int
63513+close_learn(struct inode *inode, struct file *file)
63514+{
63515+ if (file->f_mode & FMODE_READ) {
63516+ char *tmp = NULL;
63517+ mutex_lock(&gr_learn_user_mutex);
63518+ spin_lock(&gr_learn_lock);
63519+ tmp = learn_buffer;
63520+ learn_buffer = NULL;
63521+ spin_unlock(&gr_learn_lock);
63522+ if (tmp)
63523+ vfree(tmp);
63524+ if (learn_buffer_user != NULL) {
63525+ vfree(learn_buffer_user);
63526+ learn_buffer_user = NULL;
63527+ }
63528+ learn_buffer_len = 0;
63529+ learn_buffer_user_len = 0;
63530+ gr_learn_attached = 0;
63531+ mutex_unlock(&gr_learn_user_mutex);
63532+ }
63533+
63534+ return 0;
63535+}
63536+
63537+const struct file_operations grsec_fops = {
63538+ .read = read_learn,
63539+ .write = write_grsec_handler,
63540+ .open = open_learn,
63541+ .release = close_learn,
63542+ .poll = poll_learn,
63543+};
63544diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
63545new file mode 100644
63546index 0000000..39645c9
63547--- /dev/null
63548+++ b/grsecurity/gracl_res.c
63549@@ -0,0 +1,68 @@
63550+#include <linux/kernel.h>
63551+#include <linux/sched.h>
63552+#include <linux/gracl.h>
63553+#include <linux/grinternal.h>
63554+
63555+static const char *restab_log[] = {
63556+ [RLIMIT_CPU] = "RLIMIT_CPU",
63557+ [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
63558+ [RLIMIT_DATA] = "RLIMIT_DATA",
63559+ [RLIMIT_STACK] = "RLIMIT_STACK",
63560+ [RLIMIT_CORE] = "RLIMIT_CORE",
63561+ [RLIMIT_RSS] = "RLIMIT_RSS",
63562+ [RLIMIT_NPROC] = "RLIMIT_NPROC",
63563+ [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
63564+ [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
63565+ [RLIMIT_AS] = "RLIMIT_AS",
63566+ [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
63567+ [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
63568+ [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
63569+ [RLIMIT_NICE] = "RLIMIT_NICE",
63570+ [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
63571+ [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
63572+ [GR_CRASH_RES] = "RLIMIT_CRASH"
63573+};
63574+
63575+void
63576+gr_log_resource(const struct task_struct *task,
63577+ const int res, const unsigned long wanted, const int gt)
63578+{
63579+ const struct cred *cred;
63580+ unsigned long rlim;
63581+
63582+ if (!gr_acl_is_enabled() && !grsec_resource_logging)
63583+ return;
63584+
63585+ // not yet supported resource
63586+ if (unlikely(!restab_log[res]))
63587+ return;
63588+
63589+ if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
63590+ rlim = task_rlimit_max(task, res);
63591+ else
63592+ rlim = task_rlimit(task, res);
63593+
63594+ if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
63595+ return;
63596+
63597+ rcu_read_lock();
63598+ cred = __task_cred(task);
63599+
63600+ if (res == RLIMIT_NPROC &&
63601+ (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
63602+ cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
63603+ goto out_rcu_unlock;
63604+ else if (res == RLIMIT_MEMLOCK &&
63605+ cap_raised(cred->cap_effective, CAP_IPC_LOCK))
63606+ goto out_rcu_unlock;
63607+ else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
63608+ goto out_rcu_unlock;
63609+ rcu_read_unlock();
63610+
63611+ gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
63612+
63613+ return;
63614+out_rcu_unlock:
63615+ rcu_read_unlock();
63616+ return;
63617+}
63618diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
63619new file mode 100644
63620index 0000000..4dcc92a
63621--- /dev/null
63622+++ b/grsecurity/gracl_segv.c
63623@@ -0,0 +1,305 @@
63624+#include <linux/kernel.h>
63625+#include <linux/mm.h>
63626+#include <asm/uaccess.h>
63627+#include <asm/errno.h>
63628+#include <asm/mman.h>
63629+#include <net/sock.h>
63630+#include <linux/file.h>
63631+#include <linux/fs.h>
63632+#include <linux/net.h>
63633+#include <linux/in.h>
63634+#include <linux/slab.h>
63635+#include <linux/types.h>
63636+#include <linux/sched.h>
63637+#include <linux/timer.h>
63638+#include <linux/gracl.h>
63639+#include <linux/grsecurity.h>
63640+#include <linux/grinternal.h>
63641+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63642+#include <linux/magic.h>
63643+#include <linux/pagemap.h>
63644+#include "../fs/btrfs/async-thread.h"
63645+#include "../fs/btrfs/ctree.h"
63646+#include "../fs/btrfs/btrfs_inode.h"
63647+#endif
63648+
63649+static struct crash_uid *uid_set;
63650+static unsigned short uid_used;
63651+static DEFINE_SPINLOCK(gr_uid_lock);
63652+extern rwlock_t gr_inode_lock;
63653+extern struct acl_subject_label *
63654+ lookup_acl_subj_label(const ino_t inode, const dev_t dev,
63655+ struct acl_role_label *role);
63656+
63657+static inline dev_t __get_dev(const struct dentry *dentry)
63658+{
63659+#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
63660+ if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
63661+ return BTRFS_I(dentry->d_inode)->root->anon_dev;
63662+ else
63663+#endif
63664+ return dentry->d_sb->s_dev;
63665+}
63666+
63667+int
63668+gr_init_uidset(void)
63669+{
63670+ uid_set =
63671+ kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
63672+ uid_used = 0;
63673+
63674+ return uid_set ? 1 : 0;
63675+}
63676+
63677+void
63678+gr_free_uidset(void)
63679+{
63680+ if (uid_set)
63681+ kfree(uid_set);
63682+
63683+ return;
63684+}
63685+
63686+int
63687+gr_find_uid(const uid_t uid)
63688+{
63689+ struct crash_uid *tmp = uid_set;
63690+ uid_t buid;
63691+ int low = 0, high = uid_used - 1, mid;
63692+
63693+ while (high >= low) {
63694+ mid = (low + high) >> 1;
63695+ buid = tmp[mid].uid;
63696+ if (buid == uid)
63697+ return mid;
63698+ if (buid > uid)
63699+ high = mid - 1;
63700+ if (buid < uid)
63701+ low = mid + 1;
63702+ }
63703+
63704+ return -1;
63705+}
63706+
63707+static __inline__ void
63708+gr_insertsort(void)
63709+{
63710+ unsigned short i, j;
63711+ struct crash_uid index;
63712+
63713+ for (i = 1; i < uid_used; i++) {
63714+ index = uid_set[i];
63715+ j = i;
63716+ while ((j > 0) && uid_set[j - 1].uid > index.uid) {
63717+ uid_set[j] = uid_set[j - 1];
63718+ j--;
63719+ }
63720+ uid_set[j] = index;
63721+ }
63722+
63723+ return;
63724+}
63725+
63726+static __inline__ void
63727+gr_insert_uid(const kuid_t kuid, const unsigned long expires)
63728+{
63729+ int loc;
63730+ uid_t uid = GR_GLOBAL_UID(kuid);
63731+
63732+ if (uid_used == GR_UIDTABLE_MAX)
63733+ return;
63734+
63735+ loc = gr_find_uid(uid);
63736+
63737+ if (loc >= 0) {
63738+ uid_set[loc].expires = expires;
63739+ return;
63740+ }
63741+
63742+ uid_set[uid_used].uid = uid;
63743+ uid_set[uid_used].expires = expires;
63744+ uid_used++;
63745+
63746+ gr_insertsort();
63747+
63748+ return;
63749+}
63750+
63751+void
63752+gr_remove_uid(const unsigned short loc)
63753+{
63754+ unsigned short i;
63755+
63756+ for (i = loc + 1; i < uid_used; i++)
63757+ uid_set[i - 1] = uid_set[i];
63758+
63759+ uid_used--;
63760+
63761+ return;
63762+}
63763+
63764+int
63765+gr_check_crash_uid(const kuid_t kuid)
63766+{
63767+ int loc;
63768+ int ret = 0;
63769+ uid_t uid;
63770+
63771+ if (unlikely(!gr_acl_is_enabled()))
63772+ return 0;
63773+
63774+ uid = GR_GLOBAL_UID(kuid);
63775+
63776+ spin_lock(&gr_uid_lock);
63777+ loc = gr_find_uid(uid);
63778+
63779+ if (loc < 0)
63780+ goto out_unlock;
63781+
63782+ if (time_before_eq(uid_set[loc].expires, get_seconds()))
63783+ gr_remove_uid(loc);
63784+ else
63785+ ret = 1;
63786+
63787+out_unlock:
63788+ spin_unlock(&gr_uid_lock);
63789+ return ret;
63790+}
63791+
63792+static __inline__ int
63793+proc_is_setxid(const struct cred *cred)
63794+{
63795+ if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
63796+ !uid_eq(cred->uid, cred->fsuid))
63797+ return 1;
63798+ if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
63799+ !gid_eq(cred->gid, cred->fsgid))
63800+ return 1;
63801+
63802+ return 0;
63803+}
63804+
63805+extern int gr_fake_force_sig(int sig, struct task_struct *t);
63806+
63807+void
63808+gr_handle_crash(struct task_struct *task, const int sig)
63809+{
63810+ struct acl_subject_label *curr;
63811+ struct task_struct *tsk, *tsk2;
63812+ const struct cred *cred;
63813+ const struct cred *cred2;
63814+
63815+ if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
63816+ return;
63817+
63818+ if (unlikely(!gr_acl_is_enabled()))
63819+ return;
63820+
63821+ curr = task->acl;
63822+
63823+ if (!(curr->resmask & (1U << GR_CRASH_RES)))
63824+ return;
63825+
63826+ if (time_before_eq(curr->expires, get_seconds())) {
63827+ curr->expires = 0;
63828+ curr->crashes = 0;
63829+ }
63830+
63831+ curr->crashes++;
63832+
63833+ if (!curr->expires)
63834+ curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
63835+
63836+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63837+ time_after(curr->expires, get_seconds())) {
63838+ rcu_read_lock();
63839+ cred = __task_cred(task);
63840+ if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
63841+ gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63842+ spin_lock(&gr_uid_lock);
63843+ gr_insert_uid(cred->uid, curr->expires);
63844+ spin_unlock(&gr_uid_lock);
63845+ curr->expires = 0;
63846+ curr->crashes = 0;
63847+ read_lock(&tasklist_lock);
63848+ do_each_thread(tsk2, tsk) {
63849+ cred2 = __task_cred(tsk);
63850+ if (tsk != task && uid_eq(cred2->uid, cred->uid))
63851+ gr_fake_force_sig(SIGKILL, tsk);
63852+ } while_each_thread(tsk2, tsk);
63853+ read_unlock(&tasklist_lock);
63854+ } else {
63855+ gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
63856+ read_lock(&tasklist_lock);
63857+ read_lock(&grsec_exec_file_lock);
63858+ do_each_thread(tsk2, tsk) {
63859+ if (likely(tsk != task)) {
63860+ // if this thread has the same subject as the one that triggered
63861+ // RES_CRASH and it's the same binary, kill it
63862+ if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
63863+ gr_fake_force_sig(SIGKILL, tsk);
63864+ }
63865+ } while_each_thread(tsk2, tsk);
63866+ read_unlock(&grsec_exec_file_lock);
63867+ read_unlock(&tasklist_lock);
63868+ }
63869+ rcu_read_unlock();
63870+ }
63871+
63872+ return;
63873+}
63874+
63875+int
63876+gr_check_crash_exec(const struct file *filp)
63877+{
63878+ struct acl_subject_label *curr;
63879+
63880+ if (unlikely(!gr_acl_is_enabled()))
63881+ return 0;
63882+
63883+ read_lock(&gr_inode_lock);
63884+ curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
63885+ __get_dev(filp->f_path.dentry),
63886+ current->role);
63887+ read_unlock(&gr_inode_lock);
63888+
63889+ if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
63890+ (!curr->crashes && !curr->expires))
63891+ return 0;
63892+
63893+ if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
63894+ time_after(curr->expires, get_seconds()))
63895+ return 1;
63896+ else if (time_before_eq(curr->expires, get_seconds())) {
63897+ curr->crashes = 0;
63898+ curr->expires = 0;
63899+ }
63900+
63901+ return 0;
63902+}
63903+
63904+void
63905+gr_handle_alertkill(struct task_struct *task)
63906+{
63907+ struct acl_subject_label *curracl;
63908+ __u32 curr_ip;
63909+ struct task_struct *p, *p2;
63910+
63911+ if (unlikely(!gr_acl_is_enabled()))
63912+ return;
63913+
63914+ curracl = task->acl;
63915+ curr_ip = task->signal->curr_ip;
63916+
63917+ if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
63918+ read_lock(&tasklist_lock);
63919+ do_each_thread(p2, p) {
63920+ if (p->signal->curr_ip == curr_ip)
63921+ gr_fake_force_sig(SIGKILL, p);
63922+ } while_each_thread(p2, p);
63923+ read_unlock(&tasklist_lock);
63924+ } else if (curracl->mode & GR_KILLPROC)
63925+ gr_fake_force_sig(SIGKILL, task);
63926+
63927+ return;
63928+}
63929diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
63930new file mode 100644
63931index 0000000..98011b0
63932--- /dev/null
63933+++ b/grsecurity/gracl_shm.c
63934@@ -0,0 +1,40 @@
63935+#include <linux/kernel.h>
63936+#include <linux/mm.h>
63937+#include <linux/sched.h>
63938+#include <linux/file.h>
63939+#include <linux/ipc.h>
63940+#include <linux/gracl.h>
63941+#include <linux/grsecurity.h>
63942+#include <linux/grinternal.h>
63943+
63944+int
63945+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63946+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
63947+{
63948+ struct task_struct *task;
63949+
63950+ if (!gr_acl_is_enabled())
63951+ return 1;
63952+
63953+ rcu_read_lock();
63954+ read_lock(&tasklist_lock);
63955+
63956+ task = find_task_by_vpid(shm_cprid);
63957+
63958+ if (unlikely(!task))
63959+ task = find_task_by_vpid(shm_lapid);
63960+
63961+ if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
63962+ (task_pid_nr(task) == shm_lapid)) &&
63963+ (task->acl->mode & GR_PROTSHM) &&
63964+ (task->acl != current->acl))) {
63965+ read_unlock(&tasklist_lock);
63966+ rcu_read_unlock();
63967+ gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
63968+ return 0;
63969+ }
63970+ read_unlock(&tasklist_lock);
63971+ rcu_read_unlock();
63972+
63973+ return 1;
63974+}
63975diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
63976new file mode 100644
63977index 0000000..bc0be01
63978--- /dev/null
63979+++ b/grsecurity/grsec_chdir.c
63980@@ -0,0 +1,19 @@
63981+#include <linux/kernel.h>
63982+#include <linux/sched.h>
63983+#include <linux/fs.h>
63984+#include <linux/file.h>
63985+#include <linux/grsecurity.h>
63986+#include <linux/grinternal.h>
63987+
63988+void
63989+gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
63990+{
63991+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63992+ if ((grsec_enable_chdir && grsec_enable_group &&
63993+ in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
63994+ !grsec_enable_group)) {
63995+ gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
63996+ }
63997+#endif
63998+ return;
63999+}
64000diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
64001new file mode 100644
64002index 0000000..bd6e105
64003--- /dev/null
64004+++ b/grsecurity/grsec_chroot.c
64005@@ -0,0 +1,370 @@
64006+#include <linux/kernel.h>
64007+#include <linux/module.h>
64008+#include <linux/sched.h>
64009+#include <linux/file.h>
64010+#include <linux/fs.h>
64011+#include <linux/mount.h>
64012+#include <linux/types.h>
64013+#include "../fs/mount.h"
64014+#include <linux/grsecurity.h>
64015+#include <linux/grinternal.h>
64016+
64017+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64018+static int gr_init_ran;
64019+#endif
64020+
64021+void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
64022+{
64023+#ifdef CONFIG_GRKERNSEC
64024+ if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
64025+ path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
64026+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64027+ && gr_init_ran
64028+#endif
64029+ )
64030+ task->gr_is_chrooted = 1;
64031+ else {
64032+#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
64033+ if (task_pid_nr(task) == 1 && !gr_init_ran)
64034+ gr_init_ran = 1;
64035+#endif
64036+ task->gr_is_chrooted = 0;
64037+ }
64038+
64039+ task->gr_chroot_dentry = path->dentry;
64040+#endif
64041+ return;
64042+}
64043+
64044+void gr_clear_chroot_entries(struct task_struct *task)
64045+{
64046+#ifdef CONFIG_GRKERNSEC
64047+ task->gr_is_chrooted = 0;
64048+ task->gr_chroot_dentry = NULL;
64049+#endif
64050+ return;
64051+}
64052+
64053+int
64054+gr_handle_chroot_unix(const pid_t pid)
64055+{
64056+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
64057+ struct task_struct *p;
64058+
64059+ if (unlikely(!grsec_enable_chroot_unix))
64060+ return 1;
64061+
64062+ if (likely(!proc_is_chrooted(current)))
64063+ return 1;
64064+
64065+ rcu_read_lock();
64066+ read_lock(&tasklist_lock);
64067+ p = find_task_by_vpid_unrestricted(pid);
64068+ if (unlikely(p && !have_same_root(current, p))) {
64069+ read_unlock(&tasklist_lock);
64070+ rcu_read_unlock();
64071+ gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
64072+ return 0;
64073+ }
64074+ read_unlock(&tasklist_lock);
64075+ rcu_read_unlock();
64076+#endif
64077+ return 1;
64078+}
64079+
64080+int
64081+gr_handle_chroot_nice(void)
64082+{
64083+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64084+ if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
64085+ gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
64086+ return -EPERM;
64087+ }
64088+#endif
64089+ return 0;
64090+}
64091+
64092+int
64093+gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
64094+{
64095+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
64096+ if (grsec_enable_chroot_nice && (niceval < task_nice(p))
64097+ && proc_is_chrooted(current)) {
64098+ gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
64099+ return -EACCES;
64100+ }
64101+#endif
64102+ return 0;
64103+}
64104+
64105+int
64106+gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
64107+{
64108+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64109+ struct task_struct *p;
64110+ int ret = 0;
64111+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
64112+ return ret;
64113+
64114+ read_lock(&tasklist_lock);
64115+ do_each_pid_task(pid, type, p) {
64116+ if (!have_same_root(current, p)) {
64117+ ret = 1;
64118+ goto out;
64119+ }
64120+ } while_each_pid_task(pid, type, p);
64121+out:
64122+ read_unlock(&tasklist_lock);
64123+ return ret;
64124+#endif
64125+ return 0;
64126+}
64127+
64128+int
64129+gr_pid_is_chrooted(struct task_struct *p)
64130+{
64131+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
64132+ if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
64133+ return 0;
64134+
64135+ if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
64136+ !have_same_root(current, p)) {
64137+ return 1;
64138+ }
64139+#endif
64140+ return 0;
64141+}
64142+
64143+EXPORT_SYMBOL(gr_pid_is_chrooted);
64144+
64145+#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
64146+int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
64147+{
64148+ struct path path, currentroot;
64149+ int ret = 0;
64150+
64151+ path.dentry = (struct dentry *)u_dentry;
64152+ path.mnt = (struct vfsmount *)u_mnt;
64153+ get_fs_root(current->fs, &currentroot);
64154+ if (path_is_under(&path, &currentroot))
64155+ ret = 1;
64156+ path_put(&currentroot);
64157+
64158+ return ret;
64159+}
64160+#endif
64161+
64162+int
64163+gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
64164+{
64165+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
64166+ if (!grsec_enable_chroot_fchdir)
64167+ return 1;
64168+
64169+ if (!proc_is_chrooted(current))
64170+ return 1;
64171+ else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
64172+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
64173+ return 0;
64174+ }
64175+#endif
64176+ return 1;
64177+}
64178+
64179+int
64180+gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64181+ const time_t shm_createtime)
64182+{
64183+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
64184+ struct task_struct *p;
64185+ time_t starttime;
64186+
64187+ if (unlikely(!grsec_enable_chroot_shmat))
64188+ return 1;
64189+
64190+ if (likely(!proc_is_chrooted(current)))
64191+ return 1;
64192+
64193+ rcu_read_lock();
64194+ read_lock(&tasklist_lock);
64195+
64196+ if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
64197+ starttime = p->start_time.tv_sec;
64198+ if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
64199+ if (have_same_root(current, p)) {
64200+ goto allow;
64201+ } else {
64202+ read_unlock(&tasklist_lock);
64203+ rcu_read_unlock();
64204+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64205+ return 0;
64206+ }
64207+ }
64208+ /* creator exited, pid reuse, fall through to next check */
64209+ }
64210+ if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
64211+ if (unlikely(!have_same_root(current, p))) {
64212+ read_unlock(&tasklist_lock);
64213+ rcu_read_unlock();
64214+ gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
64215+ return 0;
64216+ }
64217+ }
64218+
64219+allow:
64220+ read_unlock(&tasklist_lock);
64221+ rcu_read_unlock();
64222+#endif
64223+ return 1;
64224+}
64225+
64226+void
64227+gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
64228+{
64229+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
64230+ if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
64231+ gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
64232+#endif
64233+ return;
64234+}
64235+
64236+int
64237+gr_handle_chroot_mknod(const struct dentry *dentry,
64238+ const struct vfsmount *mnt, const int mode)
64239+{
64240+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
64241+ if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
64242+ proc_is_chrooted(current)) {
64243+ gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
64244+ return -EPERM;
64245+ }
64246+#endif
64247+ return 0;
64248+}
64249+
64250+int
64251+gr_handle_chroot_mount(const struct dentry *dentry,
64252+ const struct vfsmount *mnt, const char *dev_name)
64253+{
64254+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
64255+ if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
64256+ gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
64257+ return -EPERM;
64258+ }
64259+#endif
64260+ return 0;
64261+}
64262+
64263+int
64264+gr_handle_chroot_pivot(void)
64265+{
64266+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
64267+ if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
64268+ gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
64269+ return -EPERM;
64270+ }
64271+#endif
64272+ return 0;
64273+}
64274+
64275+int
64276+gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
64277+{
64278+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
64279+ if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
64280+ !gr_is_outside_chroot(dentry, mnt)) {
64281+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
64282+ return -EPERM;
64283+ }
64284+#endif
64285+ return 0;
64286+}
64287+
64288+extern const char *captab_log[];
64289+extern int captab_log_entries;
64290+
64291+int
64292+gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64293+{
64294+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64295+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64296+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64297+ if (cap_raised(chroot_caps, cap)) {
64298+ if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
64299+ gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
64300+ }
64301+ return 0;
64302+ }
64303+ }
64304+#endif
64305+ return 1;
64306+}
64307+
64308+int
64309+gr_chroot_is_capable(const int cap)
64310+{
64311+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64312+ return gr_task_chroot_is_capable(current, current_cred(), cap);
64313+#endif
64314+ return 1;
64315+}
64316+
64317+int
64318+gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
64319+{
64320+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64321+ if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
64322+ kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
64323+ if (cap_raised(chroot_caps, cap)) {
64324+ return 0;
64325+ }
64326+ }
64327+#endif
64328+ return 1;
64329+}
64330+
64331+int
64332+gr_chroot_is_capable_nolog(const int cap)
64333+{
64334+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
64335+ return gr_task_chroot_is_capable_nolog(current, cap);
64336+#endif
64337+ return 1;
64338+}
64339+
64340+int
64341+gr_handle_chroot_sysctl(const int op)
64342+{
64343+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
64344+ if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
64345+ proc_is_chrooted(current))
64346+ return -EACCES;
64347+#endif
64348+ return 0;
64349+}
64350+
64351+void
64352+gr_handle_chroot_chdir(const struct path *path)
64353+{
64354+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
64355+ if (grsec_enable_chroot_chdir)
64356+ set_fs_pwd(current->fs, path);
64357+#endif
64358+ return;
64359+}
64360+
64361+int
64362+gr_handle_chroot_chmod(const struct dentry *dentry,
64363+ const struct vfsmount *mnt, const int mode)
64364+{
64365+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
64366+ /* allow chmod +s on directories, but not files */
64367+ if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
64368+ ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
64369+ proc_is_chrooted(current)) {
64370+ gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
64371+ return -EPERM;
64372+ }
64373+#endif
64374+ return 0;
64375+}
64376diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
64377new file mode 100644
64378index 0000000..ce65ceb
64379--- /dev/null
64380+++ b/grsecurity/grsec_disabled.c
64381@@ -0,0 +1,434 @@
64382+#include <linux/kernel.h>
64383+#include <linux/module.h>
64384+#include <linux/sched.h>
64385+#include <linux/file.h>
64386+#include <linux/fs.h>
64387+#include <linux/kdev_t.h>
64388+#include <linux/net.h>
64389+#include <linux/in.h>
64390+#include <linux/ip.h>
64391+#include <linux/skbuff.h>
64392+#include <linux/sysctl.h>
64393+
64394+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64395+void
64396+pax_set_initial_flags(struct linux_binprm *bprm)
64397+{
64398+ return;
64399+}
64400+#endif
64401+
64402+#ifdef CONFIG_SYSCTL
64403+__u32
64404+gr_handle_sysctl(const struct ctl_table * table, const int op)
64405+{
64406+ return 0;
64407+}
64408+#endif
64409+
64410+#ifdef CONFIG_TASKSTATS
64411+int gr_is_taskstats_denied(int pid)
64412+{
64413+ return 0;
64414+}
64415+#endif
64416+
64417+int
64418+gr_acl_is_enabled(void)
64419+{
64420+ return 0;
64421+}
64422+
64423+void
64424+gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
64425+{
64426+ return;
64427+}
64428+
64429+int
64430+gr_handle_rawio(const struct inode *inode)
64431+{
64432+ return 0;
64433+}
64434+
64435+void
64436+gr_acl_handle_psacct(struct task_struct *task, const long code)
64437+{
64438+ return;
64439+}
64440+
64441+int
64442+gr_handle_ptrace(struct task_struct *task, const long request)
64443+{
64444+ return 0;
64445+}
64446+
64447+int
64448+gr_handle_proc_ptrace(struct task_struct *task)
64449+{
64450+ return 0;
64451+}
64452+
64453+int
64454+gr_set_acls(const int type)
64455+{
64456+ return 0;
64457+}
64458+
64459+int
64460+gr_check_hidden_task(const struct task_struct *tsk)
64461+{
64462+ return 0;
64463+}
64464+
64465+int
64466+gr_check_protected_task(const struct task_struct *task)
64467+{
64468+ return 0;
64469+}
64470+
64471+int
64472+gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
64473+{
64474+ return 0;
64475+}
64476+
64477+void
64478+gr_copy_label(struct task_struct *tsk)
64479+{
64480+ return;
64481+}
64482+
64483+void
64484+gr_set_pax_flags(struct task_struct *task)
64485+{
64486+ return;
64487+}
64488+
64489+int
64490+gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
64491+ const int unsafe_share)
64492+{
64493+ return 0;
64494+}
64495+
64496+void
64497+gr_handle_delete(const ino_t ino, const dev_t dev)
64498+{
64499+ return;
64500+}
64501+
64502+void
64503+gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
64504+{
64505+ return;
64506+}
64507+
64508+void
64509+gr_handle_crash(struct task_struct *task, const int sig)
64510+{
64511+ return;
64512+}
64513+
64514+int
64515+gr_check_crash_exec(const struct file *filp)
64516+{
64517+ return 0;
64518+}
64519+
64520+int
64521+gr_check_crash_uid(const kuid_t uid)
64522+{
64523+ return 0;
64524+}
64525+
64526+void
64527+gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
64528+ struct dentry *old_dentry,
64529+ struct dentry *new_dentry,
64530+ struct vfsmount *mnt, const __u8 replace)
64531+{
64532+ return;
64533+}
64534+
64535+int
64536+gr_search_socket(const int family, const int type, const int protocol)
64537+{
64538+ return 1;
64539+}
64540+
64541+int
64542+gr_search_connectbind(const int mode, const struct socket *sock,
64543+ const struct sockaddr_in *addr)
64544+{
64545+ return 0;
64546+}
64547+
64548+void
64549+gr_handle_alertkill(struct task_struct *task)
64550+{
64551+ return;
64552+}
64553+
64554+__u32
64555+gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
64556+{
64557+ return 1;
64558+}
64559+
64560+__u32
64561+gr_acl_handle_hidden_file(const struct dentry * dentry,
64562+ const struct vfsmount * mnt)
64563+{
64564+ return 1;
64565+}
64566+
64567+__u32
64568+gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
64569+ int acc_mode)
64570+{
64571+ return 1;
64572+}
64573+
64574+__u32
64575+gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
64576+{
64577+ return 1;
64578+}
64579+
64580+__u32
64581+gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
64582+{
64583+ return 1;
64584+}
64585+
64586+int
64587+gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
64588+ unsigned int *vm_flags)
64589+{
64590+ return 1;
64591+}
64592+
64593+__u32
64594+gr_acl_handle_truncate(const struct dentry * dentry,
64595+ const struct vfsmount * mnt)
64596+{
64597+ return 1;
64598+}
64599+
64600+__u32
64601+gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
64602+{
64603+ return 1;
64604+}
64605+
64606+__u32
64607+gr_acl_handle_access(const struct dentry * dentry,
64608+ const struct vfsmount * mnt, const int fmode)
64609+{
64610+ return 1;
64611+}
64612+
64613+__u32
64614+gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
64615+ umode_t *mode)
64616+{
64617+ return 1;
64618+}
64619+
64620+__u32
64621+gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
64622+{
64623+ return 1;
64624+}
64625+
64626+__u32
64627+gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
64628+{
64629+ return 1;
64630+}
64631+
64632+void
64633+grsecurity_init(void)
64634+{
64635+ return;
64636+}
64637+
64638+umode_t gr_acl_umask(void)
64639+{
64640+ return 0;
64641+}
64642+
64643+__u32
64644+gr_acl_handle_mknod(const struct dentry * new_dentry,
64645+ const struct dentry * parent_dentry,
64646+ const struct vfsmount * parent_mnt,
64647+ const int mode)
64648+{
64649+ return 1;
64650+}
64651+
64652+__u32
64653+gr_acl_handle_mkdir(const struct dentry * new_dentry,
64654+ const struct dentry * parent_dentry,
64655+ const struct vfsmount * parent_mnt)
64656+{
64657+ return 1;
64658+}
64659+
64660+__u32
64661+gr_acl_handle_symlink(const struct dentry * new_dentry,
64662+ const struct dentry * parent_dentry,
64663+ const struct vfsmount * parent_mnt, const struct filename *from)
64664+{
64665+ return 1;
64666+}
64667+
64668+__u32
64669+gr_acl_handle_link(const struct dentry * new_dentry,
64670+ const struct dentry * parent_dentry,
64671+ const struct vfsmount * parent_mnt,
64672+ const struct dentry * old_dentry,
64673+ const struct vfsmount * old_mnt, const struct filename *to)
64674+{
64675+ return 1;
64676+}
64677+
64678+int
64679+gr_acl_handle_rename(const struct dentry *new_dentry,
64680+ const struct dentry *parent_dentry,
64681+ const struct vfsmount *parent_mnt,
64682+ const struct dentry *old_dentry,
64683+ const struct inode *old_parent_inode,
64684+ const struct vfsmount *old_mnt, const struct filename *newname)
64685+{
64686+ return 0;
64687+}
64688+
64689+int
64690+gr_acl_handle_filldir(const struct file *file, const char *name,
64691+ const int namelen, const ino_t ino)
64692+{
64693+ return 1;
64694+}
64695+
64696+int
64697+gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
64698+ const time_t shm_createtime, const kuid_t cuid, const int shmid)
64699+{
64700+ return 1;
64701+}
64702+
64703+int
64704+gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
64705+{
64706+ return 0;
64707+}
64708+
64709+int
64710+gr_search_accept(const struct socket *sock)
64711+{
64712+ return 0;
64713+}
64714+
64715+int
64716+gr_search_listen(const struct socket *sock)
64717+{
64718+ return 0;
64719+}
64720+
64721+int
64722+gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
64723+{
64724+ return 0;
64725+}
64726+
64727+__u32
64728+gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
64729+{
64730+ return 1;
64731+}
64732+
64733+__u32
64734+gr_acl_handle_creat(const struct dentry * dentry,
64735+ const struct dentry * p_dentry,
64736+ const struct vfsmount * p_mnt, int open_flags, int acc_mode,
64737+ const int imode)
64738+{
64739+ return 1;
64740+}
64741+
64742+void
64743+gr_acl_handle_exit(void)
64744+{
64745+ return;
64746+}
64747+
64748+int
64749+gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
64750+{
64751+ return 1;
64752+}
64753+
64754+void
64755+gr_set_role_label(const kuid_t uid, const kgid_t gid)
64756+{
64757+ return;
64758+}
64759+
64760+int
64761+gr_acl_handle_procpidmem(const struct task_struct *task)
64762+{
64763+ return 0;
64764+}
64765+
64766+int
64767+gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
64768+{
64769+ return 0;
64770+}
64771+
64772+int
64773+gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
64774+{
64775+ return 0;
64776+}
64777+
64778+void
64779+gr_set_kernel_label(struct task_struct *task)
64780+{
64781+ return;
64782+}
64783+
64784+int
64785+gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
64786+{
64787+ return 0;
64788+}
64789+
64790+int
64791+gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
64792+{
64793+ return 0;
64794+}
64795+
64796+int gr_acl_enable_at_secure(void)
64797+{
64798+ return 0;
64799+}
64800+
64801+dev_t gr_get_dev_from_dentry(struct dentry *dentry)
64802+{
64803+ return dentry->d_sb->s_dev;
64804+}
64805+
64806+void gr_put_exec_file(struct task_struct *task)
64807+{
64808+ return;
64809+}
64810+
64811+EXPORT_SYMBOL(gr_set_kernel_label);
64812+#ifdef CONFIG_SECURITY
64813+EXPORT_SYMBOL(gr_check_user_change);
64814+EXPORT_SYMBOL(gr_check_group_change);
64815+#endif
64816diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
64817new file mode 100644
64818index 0000000..387032b
64819--- /dev/null
64820+++ b/grsecurity/grsec_exec.c
64821@@ -0,0 +1,187 @@
64822+#include <linux/kernel.h>
64823+#include <linux/sched.h>
64824+#include <linux/file.h>
64825+#include <linux/binfmts.h>
64826+#include <linux/fs.h>
64827+#include <linux/types.h>
64828+#include <linux/grdefs.h>
64829+#include <linux/grsecurity.h>
64830+#include <linux/grinternal.h>
64831+#include <linux/capability.h>
64832+#include <linux/module.h>
64833+#include <linux/compat.h>
64834+
64835+#include <asm/uaccess.h>
64836+
64837+#ifdef CONFIG_GRKERNSEC_EXECLOG
64838+static char gr_exec_arg_buf[132];
64839+static DEFINE_MUTEX(gr_exec_arg_mutex);
64840+#endif
64841+
64842+struct user_arg_ptr {
64843+#ifdef CONFIG_COMPAT
64844+ bool is_compat;
64845+#endif
64846+ union {
64847+ const char __user *const __user *native;
64848+#ifdef CONFIG_COMPAT
64849+ const compat_uptr_t __user *compat;
64850+#endif
64851+ } ptr;
64852+};
64853+
64854+extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
64855+
64856+void
64857+gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
64858+{
64859+#ifdef CONFIG_GRKERNSEC_EXECLOG
64860+ char *grarg = gr_exec_arg_buf;
64861+ unsigned int i, x, execlen = 0;
64862+ char c;
64863+
64864+ if (!((grsec_enable_execlog && grsec_enable_group &&
64865+ in_group_p(grsec_audit_gid))
64866+ || (grsec_enable_execlog && !grsec_enable_group)))
64867+ return;
64868+
64869+ mutex_lock(&gr_exec_arg_mutex);
64870+ memset(grarg, 0, sizeof(gr_exec_arg_buf));
64871+
64872+ for (i = 0; i < bprm->argc && execlen < 128; i++) {
64873+ const char __user *p;
64874+ unsigned int len;
64875+
64876+ p = get_user_arg_ptr(argv, i);
64877+ if (IS_ERR(p))
64878+ goto log;
64879+
64880+ len = strnlen_user(p, 128 - execlen);
64881+ if (len > 128 - execlen)
64882+ len = 128 - execlen;
64883+ else if (len > 0)
64884+ len--;
64885+ if (copy_from_user(grarg + execlen, p, len))
64886+ goto log;
64887+
64888+ /* rewrite unprintable characters */
64889+ for (x = 0; x < len; x++) {
64890+ c = *(grarg + execlen + x);
64891+ if (c < 32 || c > 126)
64892+ *(grarg + execlen + x) = ' ';
64893+ }
64894+
64895+ execlen += len;
64896+ *(grarg + execlen) = ' ';
64897+ *(grarg + execlen + 1) = '\0';
64898+ execlen++;
64899+ }
64900+
64901+ log:
64902+ gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
64903+ bprm->file->f_path.mnt, grarg);
64904+ mutex_unlock(&gr_exec_arg_mutex);
64905+#endif
64906+ return;
64907+}
64908+
64909+#ifdef CONFIG_GRKERNSEC
64910+extern int gr_acl_is_capable(const int cap);
64911+extern int gr_acl_is_capable_nolog(const int cap);
64912+extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64913+extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
64914+extern int gr_chroot_is_capable(const int cap);
64915+extern int gr_chroot_is_capable_nolog(const int cap);
64916+extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
64917+extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
64918+#endif
64919+
64920+const char *captab_log[] = {
64921+ "CAP_CHOWN",
64922+ "CAP_DAC_OVERRIDE",
64923+ "CAP_DAC_READ_SEARCH",
64924+ "CAP_FOWNER",
64925+ "CAP_FSETID",
64926+ "CAP_KILL",
64927+ "CAP_SETGID",
64928+ "CAP_SETUID",
64929+ "CAP_SETPCAP",
64930+ "CAP_LINUX_IMMUTABLE",
64931+ "CAP_NET_BIND_SERVICE",
64932+ "CAP_NET_BROADCAST",
64933+ "CAP_NET_ADMIN",
64934+ "CAP_NET_RAW",
64935+ "CAP_IPC_LOCK",
64936+ "CAP_IPC_OWNER",
64937+ "CAP_SYS_MODULE",
64938+ "CAP_SYS_RAWIO",
64939+ "CAP_SYS_CHROOT",
64940+ "CAP_SYS_PTRACE",
64941+ "CAP_SYS_PACCT",
64942+ "CAP_SYS_ADMIN",
64943+ "CAP_SYS_BOOT",
64944+ "CAP_SYS_NICE",
64945+ "CAP_SYS_RESOURCE",
64946+ "CAP_SYS_TIME",
64947+ "CAP_SYS_TTY_CONFIG",
64948+ "CAP_MKNOD",
64949+ "CAP_LEASE",
64950+ "CAP_AUDIT_WRITE",
64951+ "CAP_AUDIT_CONTROL",
64952+ "CAP_SETFCAP",
64953+ "CAP_MAC_OVERRIDE",
64954+ "CAP_MAC_ADMIN",
64955+ "CAP_SYSLOG",
64956+ "CAP_WAKE_ALARM"
64957+};
64958+
64959+int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
64960+
64961+int gr_is_capable(const int cap)
64962+{
64963+#ifdef CONFIG_GRKERNSEC
64964+ if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
64965+ return 1;
64966+ return 0;
64967+#else
64968+ return 1;
64969+#endif
64970+}
64971+
64972+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
64973+{
64974+#ifdef CONFIG_GRKERNSEC
64975+ if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
64976+ return 1;
64977+ return 0;
64978+#else
64979+ return 1;
64980+#endif
64981+}
64982+
64983+int gr_is_capable_nolog(const int cap)
64984+{
64985+#ifdef CONFIG_GRKERNSEC
64986+ if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
64987+ return 1;
64988+ return 0;
64989+#else
64990+ return 1;
64991+#endif
64992+}
64993+
64994+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
64995+{
64996+#ifdef CONFIG_GRKERNSEC
64997+ if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
64998+ return 1;
64999+ return 0;
65000+#else
65001+ return 1;
65002+#endif
65003+}
65004+
65005+EXPORT_SYMBOL(gr_is_capable);
65006+EXPORT_SYMBOL(gr_is_capable_nolog);
65007+EXPORT_SYMBOL(gr_task_is_capable);
65008+EXPORT_SYMBOL(gr_task_is_capable_nolog);
65009diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
65010new file mode 100644
65011index 0000000..06cc6ea
65012--- /dev/null
65013+++ b/grsecurity/grsec_fifo.c
65014@@ -0,0 +1,24 @@
65015+#include <linux/kernel.h>
65016+#include <linux/sched.h>
65017+#include <linux/fs.h>
65018+#include <linux/file.h>
65019+#include <linux/grinternal.h>
65020+
65021+int
65022+gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
65023+ const struct dentry *dir, const int flag, const int acc_mode)
65024+{
65025+#ifdef CONFIG_GRKERNSEC_FIFO
65026+ const struct cred *cred = current_cred();
65027+
65028+ if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
65029+ !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
65030+ !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
65031+ !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
65032+ if (!inode_permission(dentry->d_inode, acc_mode))
65033+ 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));
65034+ return -EACCES;
65035+ }
65036+#endif
65037+ return 0;
65038+}
65039diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
65040new file mode 100644
65041index 0000000..8ca18bf
65042--- /dev/null
65043+++ b/grsecurity/grsec_fork.c
65044@@ -0,0 +1,23 @@
65045+#include <linux/kernel.h>
65046+#include <linux/sched.h>
65047+#include <linux/grsecurity.h>
65048+#include <linux/grinternal.h>
65049+#include <linux/errno.h>
65050+
65051+void
65052+gr_log_forkfail(const int retval)
65053+{
65054+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65055+ if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
65056+ switch (retval) {
65057+ case -EAGAIN:
65058+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
65059+ break;
65060+ case -ENOMEM:
65061+ gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
65062+ break;
65063+ }
65064+ }
65065+#endif
65066+ return;
65067+}
65068diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
65069new file mode 100644
65070index 0000000..a862e9f
65071--- /dev/null
65072+++ b/grsecurity/grsec_init.c
65073@@ -0,0 +1,283 @@
65074+#include <linux/kernel.h>
65075+#include <linux/sched.h>
65076+#include <linux/mm.h>
65077+#include <linux/gracl.h>
65078+#include <linux/slab.h>
65079+#include <linux/vmalloc.h>
65080+#include <linux/percpu.h>
65081+#include <linux/module.h>
65082+
65083+int grsec_enable_ptrace_readexec;
65084+int grsec_enable_setxid;
65085+int grsec_enable_symlinkown;
65086+kgid_t grsec_symlinkown_gid;
65087+int grsec_enable_brute;
65088+int grsec_enable_link;
65089+int grsec_enable_dmesg;
65090+int grsec_enable_harden_ptrace;
65091+int grsec_enable_fifo;
65092+int grsec_enable_execlog;
65093+int grsec_enable_signal;
65094+int grsec_enable_forkfail;
65095+int grsec_enable_audit_ptrace;
65096+int grsec_enable_time;
65097+int grsec_enable_audit_textrel;
65098+int grsec_enable_group;
65099+kgid_t grsec_audit_gid;
65100+int grsec_enable_chdir;
65101+int grsec_enable_mount;
65102+int grsec_enable_rofs;
65103+int grsec_enable_chroot_findtask;
65104+int grsec_enable_chroot_mount;
65105+int grsec_enable_chroot_shmat;
65106+int grsec_enable_chroot_fchdir;
65107+int grsec_enable_chroot_double;
65108+int grsec_enable_chroot_pivot;
65109+int grsec_enable_chroot_chdir;
65110+int grsec_enable_chroot_chmod;
65111+int grsec_enable_chroot_mknod;
65112+int grsec_enable_chroot_nice;
65113+int grsec_enable_chroot_execlog;
65114+int grsec_enable_chroot_caps;
65115+int grsec_enable_chroot_sysctl;
65116+int grsec_enable_chroot_unix;
65117+int grsec_enable_tpe;
65118+kgid_t grsec_tpe_gid;
65119+int grsec_enable_blackhole;
65120+#ifdef CONFIG_IPV6_MODULE
65121+EXPORT_SYMBOL(grsec_enable_blackhole);
65122+#endif
65123+int grsec_lastack_retries;
65124+int grsec_enable_tpe_all;
65125+int grsec_enable_tpe_invert;
65126+int grsec_enable_socket_all;
65127+kgid_t grsec_socket_all_gid;
65128+int grsec_enable_socket_client;
65129+kgid_t grsec_socket_client_gid;
65130+int grsec_enable_socket_server;
65131+kgid_t grsec_socket_server_gid;
65132+int grsec_resource_logging;
65133+int grsec_disable_privio;
65134+int grsec_enable_log_rwxmaps;
65135+int grsec_lock;
65136+
65137+DEFINE_SPINLOCK(grsec_alert_lock);
65138+unsigned long grsec_alert_wtime = 0;
65139+unsigned long grsec_alert_fyet = 0;
65140+
65141+DEFINE_SPINLOCK(grsec_audit_lock);
65142+
65143+DEFINE_RWLOCK(grsec_exec_file_lock);
65144+
65145+char *gr_shared_page[4];
65146+
65147+char *gr_alert_log_fmt;
65148+char *gr_audit_log_fmt;
65149+char *gr_alert_log_buf;
65150+char *gr_audit_log_buf;
65151+
65152+extern struct gr_arg *gr_usermode;
65153+extern unsigned char *gr_system_salt;
65154+extern unsigned char *gr_system_sum;
65155+
65156+void __init
65157+grsecurity_init(void)
65158+{
65159+ int j;
65160+ /* create the per-cpu shared pages */
65161+
65162+#ifdef CONFIG_X86
65163+ memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
65164+#endif
65165+
65166+ for (j = 0; j < 4; j++) {
65167+ gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
65168+ if (gr_shared_page[j] == NULL) {
65169+ panic("Unable to allocate grsecurity shared page");
65170+ return;
65171+ }
65172+ }
65173+
65174+ /* allocate log buffers */
65175+ gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
65176+ if (!gr_alert_log_fmt) {
65177+ panic("Unable to allocate grsecurity alert log format buffer");
65178+ return;
65179+ }
65180+ gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
65181+ if (!gr_audit_log_fmt) {
65182+ panic("Unable to allocate grsecurity audit log format buffer");
65183+ return;
65184+ }
65185+ gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65186+ if (!gr_alert_log_buf) {
65187+ panic("Unable to allocate grsecurity alert log buffer");
65188+ return;
65189+ }
65190+ gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
65191+ if (!gr_audit_log_buf) {
65192+ panic("Unable to allocate grsecurity audit log buffer");
65193+ return;
65194+ }
65195+
65196+ /* allocate memory for authentication structure */
65197+ gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
65198+ gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
65199+ gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
65200+
65201+ if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
65202+ panic("Unable to allocate grsecurity authentication structure");
65203+ return;
65204+ }
65205+
65206+
65207+#ifdef CONFIG_GRKERNSEC_IO
65208+#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
65209+ grsec_disable_privio = 1;
65210+#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65211+ grsec_disable_privio = 1;
65212+#else
65213+ grsec_disable_privio = 0;
65214+#endif
65215+#endif
65216+
65217+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65218+ /* for backward compatibility, tpe_invert always defaults to on if
65219+ enabled in the kernel
65220+ */
65221+ grsec_enable_tpe_invert = 1;
65222+#endif
65223+
65224+#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
65225+#ifndef CONFIG_GRKERNSEC_SYSCTL
65226+ grsec_lock = 1;
65227+#endif
65228+
65229+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65230+ grsec_enable_audit_textrel = 1;
65231+#endif
65232+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65233+ grsec_enable_log_rwxmaps = 1;
65234+#endif
65235+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65236+ grsec_enable_group = 1;
65237+ grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
65238+#endif
65239+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65240+ grsec_enable_ptrace_readexec = 1;
65241+#endif
65242+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65243+ grsec_enable_chdir = 1;
65244+#endif
65245+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65246+ grsec_enable_harden_ptrace = 1;
65247+#endif
65248+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65249+ grsec_enable_mount = 1;
65250+#endif
65251+#ifdef CONFIG_GRKERNSEC_LINK
65252+ grsec_enable_link = 1;
65253+#endif
65254+#ifdef CONFIG_GRKERNSEC_BRUTE
65255+ grsec_enable_brute = 1;
65256+#endif
65257+#ifdef CONFIG_GRKERNSEC_DMESG
65258+ grsec_enable_dmesg = 1;
65259+#endif
65260+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65261+ grsec_enable_blackhole = 1;
65262+ grsec_lastack_retries = 4;
65263+#endif
65264+#ifdef CONFIG_GRKERNSEC_FIFO
65265+ grsec_enable_fifo = 1;
65266+#endif
65267+#ifdef CONFIG_GRKERNSEC_EXECLOG
65268+ grsec_enable_execlog = 1;
65269+#endif
65270+#ifdef CONFIG_GRKERNSEC_SETXID
65271+ grsec_enable_setxid = 1;
65272+#endif
65273+#ifdef CONFIG_GRKERNSEC_SIGNAL
65274+ grsec_enable_signal = 1;
65275+#endif
65276+#ifdef CONFIG_GRKERNSEC_FORKFAIL
65277+ grsec_enable_forkfail = 1;
65278+#endif
65279+#ifdef CONFIG_GRKERNSEC_TIME
65280+ grsec_enable_time = 1;
65281+#endif
65282+#ifdef CONFIG_GRKERNSEC_RESLOG
65283+ grsec_resource_logging = 1;
65284+#endif
65285+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65286+ grsec_enable_chroot_findtask = 1;
65287+#endif
65288+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65289+ grsec_enable_chroot_unix = 1;
65290+#endif
65291+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65292+ grsec_enable_chroot_mount = 1;
65293+#endif
65294+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65295+ grsec_enable_chroot_fchdir = 1;
65296+#endif
65297+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65298+ grsec_enable_chroot_shmat = 1;
65299+#endif
65300+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65301+ grsec_enable_audit_ptrace = 1;
65302+#endif
65303+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65304+ grsec_enable_chroot_double = 1;
65305+#endif
65306+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65307+ grsec_enable_chroot_pivot = 1;
65308+#endif
65309+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65310+ grsec_enable_chroot_chdir = 1;
65311+#endif
65312+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65313+ grsec_enable_chroot_chmod = 1;
65314+#endif
65315+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65316+ grsec_enable_chroot_mknod = 1;
65317+#endif
65318+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65319+ grsec_enable_chroot_nice = 1;
65320+#endif
65321+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65322+ grsec_enable_chroot_execlog = 1;
65323+#endif
65324+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65325+ grsec_enable_chroot_caps = 1;
65326+#endif
65327+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65328+ grsec_enable_chroot_sysctl = 1;
65329+#endif
65330+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65331+ grsec_enable_symlinkown = 1;
65332+ grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
65333+#endif
65334+#ifdef CONFIG_GRKERNSEC_TPE
65335+ grsec_enable_tpe = 1;
65336+ grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
65337+#ifdef CONFIG_GRKERNSEC_TPE_ALL
65338+ grsec_enable_tpe_all = 1;
65339+#endif
65340+#endif
65341+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65342+ grsec_enable_socket_all = 1;
65343+ grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
65344+#endif
65345+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65346+ grsec_enable_socket_client = 1;
65347+ grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
65348+#endif
65349+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65350+ grsec_enable_socket_server = 1;
65351+ grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
65352+#endif
65353+#endif
65354+
65355+ return;
65356+}
65357diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
65358new file mode 100644
65359index 0000000..5e05e20
65360--- /dev/null
65361+++ b/grsecurity/grsec_link.c
65362@@ -0,0 +1,58 @@
65363+#include <linux/kernel.h>
65364+#include <linux/sched.h>
65365+#include <linux/fs.h>
65366+#include <linux/file.h>
65367+#include <linux/grinternal.h>
65368+
65369+int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
65370+{
65371+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
65372+ const struct inode *link_inode = link->dentry->d_inode;
65373+
65374+ if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
65375+ /* ignore root-owned links, e.g. /proc/self */
65376+ gr_is_global_nonroot(link_inode->i_uid) && target &&
65377+ !uid_eq(link_inode->i_uid, target->i_uid)) {
65378+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
65379+ return 1;
65380+ }
65381+#endif
65382+ return 0;
65383+}
65384+
65385+int
65386+gr_handle_follow_link(const struct inode *parent,
65387+ const struct inode *inode,
65388+ const struct dentry *dentry, const struct vfsmount *mnt)
65389+{
65390+#ifdef CONFIG_GRKERNSEC_LINK
65391+ const struct cred *cred = current_cred();
65392+
65393+ if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
65394+ (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
65395+ (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
65396+ gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
65397+ return -EACCES;
65398+ }
65399+#endif
65400+ return 0;
65401+}
65402+
65403+int
65404+gr_handle_hardlink(const struct dentry *dentry,
65405+ const struct vfsmount *mnt,
65406+ struct inode *inode, const int mode, const struct filename *to)
65407+{
65408+#ifdef CONFIG_GRKERNSEC_LINK
65409+ const struct cred *cred = current_cred();
65410+
65411+ if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
65412+ (!S_ISREG(mode) || is_privileged_binary(dentry) ||
65413+ (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
65414+ !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
65415+ gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
65416+ return -EPERM;
65417+ }
65418+#endif
65419+ return 0;
65420+}
65421diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
65422new file mode 100644
65423index 0000000..7c06085
65424--- /dev/null
65425+++ b/grsecurity/grsec_log.c
65426@@ -0,0 +1,326 @@
65427+#include <linux/kernel.h>
65428+#include <linux/sched.h>
65429+#include <linux/file.h>
65430+#include <linux/tty.h>
65431+#include <linux/fs.h>
65432+#include <linux/grinternal.h>
65433+
65434+#ifdef CONFIG_TREE_PREEMPT_RCU
65435+#define DISABLE_PREEMPT() preempt_disable()
65436+#define ENABLE_PREEMPT() preempt_enable()
65437+#else
65438+#define DISABLE_PREEMPT()
65439+#define ENABLE_PREEMPT()
65440+#endif
65441+
65442+#define BEGIN_LOCKS(x) \
65443+ DISABLE_PREEMPT(); \
65444+ rcu_read_lock(); \
65445+ read_lock(&tasklist_lock); \
65446+ read_lock(&grsec_exec_file_lock); \
65447+ if (x != GR_DO_AUDIT) \
65448+ spin_lock(&grsec_alert_lock); \
65449+ else \
65450+ spin_lock(&grsec_audit_lock)
65451+
65452+#define END_LOCKS(x) \
65453+ if (x != GR_DO_AUDIT) \
65454+ spin_unlock(&grsec_alert_lock); \
65455+ else \
65456+ spin_unlock(&grsec_audit_lock); \
65457+ read_unlock(&grsec_exec_file_lock); \
65458+ read_unlock(&tasklist_lock); \
65459+ rcu_read_unlock(); \
65460+ ENABLE_PREEMPT(); \
65461+ if (x == GR_DONT_AUDIT) \
65462+ gr_handle_alertkill(current)
65463+
65464+enum {
65465+ FLOODING,
65466+ NO_FLOODING
65467+};
65468+
65469+extern char *gr_alert_log_fmt;
65470+extern char *gr_audit_log_fmt;
65471+extern char *gr_alert_log_buf;
65472+extern char *gr_audit_log_buf;
65473+
65474+static int gr_log_start(int audit)
65475+{
65476+ char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
65477+ char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
65478+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65479+#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
65480+ unsigned long curr_secs = get_seconds();
65481+
65482+ if (audit == GR_DO_AUDIT)
65483+ goto set_fmt;
65484+
65485+ if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
65486+ grsec_alert_wtime = curr_secs;
65487+ grsec_alert_fyet = 0;
65488+ } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
65489+ && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
65490+ grsec_alert_fyet++;
65491+ } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
65492+ grsec_alert_wtime = curr_secs;
65493+ grsec_alert_fyet++;
65494+ printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
65495+ return FLOODING;
65496+ }
65497+ else return FLOODING;
65498+
65499+set_fmt:
65500+#endif
65501+ memset(buf, 0, PAGE_SIZE);
65502+ if (current->signal->curr_ip && gr_acl_is_enabled()) {
65503+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
65504+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65505+ } else if (current->signal->curr_ip) {
65506+ sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
65507+ snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
65508+ } else if (gr_acl_is_enabled()) {
65509+ sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
65510+ snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
65511+ } else {
65512+ sprintf(fmt, "%s%s", loglevel, "grsec: ");
65513+ strcpy(buf, fmt);
65514+ }
65515+
65516+ return NO_FLOODING;
65517+}
65518+
65519+static void gr_log_middle(int audit, const char *msg, va_list ap)
65520+ __attribute__ ((format (printf, 2, 0)));
65521+
65522+static void gr_log_middle(int audit, const char *msg, va_list ap)
65523+{
65524+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65525+ unsigned int len = strlen(buf);
65526+
65527+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65528+
65529+ return;
65530+}
65531+
65532+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65533+ __attribute__ ((format (printf, 2, 3)));
65534+
65535+static void gr_log_middle_varargs(int audit, const char *msg, ...)
65536+{
65537+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65538+ unsigned int len = strlen(buf);
65539+ va_list ap;
65540+
65541+ va_start(ap, msg);
65542+ vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
65543+ va_end(ap);
65544+
65545+ return;
65546+}
65547+
65548+static void gr_log_end(int audit, int append_default)
65549+{
65550+ char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
65551+ if (append_default) {
65552+ struct task_struct *task = current;
65553+ struct task_struct *parent = task->real_parent;
65554+ const struct cred *cred = __task_cred(task);
65555+ const struct cred *pcred = __task_cred(parent);
65556+ unsigned int len = strlen(buf);
65557+
65558+ 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));
65559+ }
65560+
65561+ printk("%s\n", buf);
65562+
65563+ return;
65564+}
65565+
65566+void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
65567+{
65568+ int logtype;
65569+ char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
65570+ char *str1 = NULL, *str2 = NULL, *str3 = NULL;
65571+ void *voidptr = NULL;
65572+ int num1 = 0, num2 = 0;
65573+ unsigned long ulong1 = 0, ulong2 = 0;
65574+ struct dentry *dentry = NULL;
65575+ struct vfsmount *mnt = NULL;
65576+ struct file *file = NULL;
65577+ struct task_struct *task = NULL;
65578+ const struct cred *cred, *pcred;
65579+ va_list ap;
65580+
65581+ BEGIN_LOCKS(audit);
65582+ logtype = gr_log_start(audit);
65583+ if (logtype == FLOODING) {
65584+ END_LOCKS(audit);
65585+ return;
65586+ }
65587+ va_start(ap, argtypes);
65588+ switch (argtypes) {
65589+ case GR_TTYSNIFF:
65590+ task = va_arg(ap, struct task_struct *);
65591+ 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));
65592+ break;
65593+ case GR_SYSCTL_HIDDEN:
65594+ str1 = va_arg(ap, char *);
65595+ gr_log_middle_varargs(audit, msg, result, str1);
65596+ break;
65597+ case GR_RBAC:
65598+ dentry = va_arg(ap, struct dentry *);
65599+ mnt = va_arg(ap, struct vfsmount *);
65600+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
65601+ break;
65602+ case GR_RBAC_STR:
65603+ dentry = va_arg(ap, struct dentry *);
65604+ mnt = va_arg(ap, struct vfsmount *);
65605+ str1 = va_arg(ap, char *);
65606+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
65607+ break;
65608+ case GR_STR_RBAC:
65609+ str1 = va_arg(ap, char *);
65610+ dentry = va_arg(ap, struct dentry *);
65611+ mnt = va_arg(ap, struct vfsmount *);
65612+ gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
65613+ break;
65614+ case GR_RBAC_MODE2:
65615+ dentry = va_arg(ap, struct dentry *);
65616+ mnt = va_arg(ap, struct vfsmount *);
65617+ str1 = va_arg(ap, char *);
65618+ str2 = va_arg(ap, char *);
65619+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
65620+ break;
65621+ case GR_RBAC_MODE3:
65622+ dentry = va_arg(ap, struct dentry *);
65623+ mnt = va_arg(ap, struct vfsmount *);
65624+ str1 = va_arg(ap, char *);
65625+ str2 = va_arg(ap, char *);
65626+ str3 = va_arg(ap, char *);
65627+ gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
65628+ break;
65629+ case GR_FILENAME:
65630+ dentry = va_arg(ap, struct dentry *);
65631+ mnt = va_arg(ap, struct vfsmount *);
65632+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
65633+ break;
65634+ case GR_STR_FILENAME:
65635+ str1 = va_arg(ap, char *);
65636+ dentry = va_arg(ap, struct dentry *);
65637+ mnt = va_arg(ap, struct vfsmount *);
65638+ gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
65639+ break;
65640+ case GR_FILENAME_STR:
65641+ dentry = va_arg(ap, struct dentry *);
65642+ mnt = va_arg(ap, struct vfsmount *);
65643+ str1 = va_arg(ap, char *);
65644+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
65645+ break;
65646+ case GR_FILENAME_TWO_INT:
65647+ dentry = va_arg(ap, struct dentry *);
65648+ mnt = va_arg(ap, struct vfsmount *);
65649+ num1 = va_arg(ap, int);
65650+ num2 = va_arg(ap, int);
65651+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
65652+ break;
65653+ case GR_FILENAME_TWO_INT_STR:
65654+ dentry = va_arg(ap, struct dentry *);
65655+ mnt = va_arg(ap, struct vfsmount *);
65656+ num1 = va_arg(ap, int);
65657+ num2 = va_arg(ap, int);
65658+ str1 = va_arg(ap, char *);
65659+ gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
65660+ break;
65661+ case GR_TEXTREL:
65662+ file = va_arg(ap, struct file *);
65663+ ulong1 = va_arg(ap, unsigned long);
65664+ ulong2 = va_arg(ap, unsigned long);
65665+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
65666+ break;
65667+ case GR_PTRACE:
65668+ task = va_arg(ap, struct task_struct *);
65669+ 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));
65670+ break;
65671+ case GR_RESOURCE:
65672+ task = va_arg(ap, struct task_struct *);
65673+ cred = __task_cred(task);
65674+ pcred = __task_cred(task->real_parent);
65675+ ulong1 = va_arg(ap, unsigned long);
65676+ str1 = va_arg(ap, char *);
65677+ ulong2 = va_arg(ap, unsigned long);
65678+ 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));
65679+ break;
65680+ case GR_CAP:
65681+ task = va_arg(ap, struct task_struct *);
65682+ cred = __task_cred(task);
65683+ pcred = __task_cred(task->real_parent);
65684+ str1 = va_arg(ap, char *);
65685+ 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));
65686+ break;
65687+ case GR_SIG:
65688+ str1 = va_arg(ap, char *);
65689+ voidptr = va_arg(ap, void *);
65690+ gr_log_middle_varargs(audit, msg, str1, voidptr);
65691+ break;
65692+ case GR_SIG2:
65693+ task = va_arg(ap, struct task_struct *);
65694+ cred = __task_cred(task);
65695+ pcred = __task_cred(task->real_parent);
65696+ num1 = va_arg(ap, int);
65697+ 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));
65698+ break;
65699+ case GR_CRASH1:
65700+ task = va_arg(ap, struct task_struct *);
65701+ cred = __task_cred(task);
65702+ pcred = __task_cred(task->real_parent);
65703+ ulong1 = va_arg(ap, unsigned long);
65704+ 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);
65705+ break;
65706+ case GR_CRASH2:
65707+ task = va_arg(ap, struct task_struct *);
65708+ cred = __task_cred(task);
65709+ pcred = __task_cred(task->real_parent);
65710+ ulong1 = va_arg(ap, unsigned long);
65711+ 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);
65712+ break;
65713+ case GR_RWXMAP:
65714+ file = va_arg(ap, struct file *);
65715+ gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
65716+ break;
65717+ case GR_PSACCT:
65718+ {
65719+ unsigned int wday, cday;
65720+ __u8 whr, chr;
65721+ __u8 wmin, cmin;
65722+ __u8 wsec, csec;
65723+ char cur_tty[64] = { 0 };
65724+ char parent_tty[64] = { 0 };
65725+
65726+ task = va_arg(ap, struct task_struct *);
65727+ wday = va_arg(ap, unsigned int);
65728+ cday = va_arg(ap, unsigned int);
65729+ whr = va_arg(ap, int);
65730+ chr = va_arg(ap, int);
65731+ wmin = va_arg(ap, int);
65732+ cmin = va_arg(ap, int);
65733+ wsec = va_arg(ap, int);
65734+ csec = va_arg(ap, int);
65735+ ulong1 = va_arg(ap, unsigned long);
65736+ cred = __task_cred(task);
65737+ pcred = __task_cred(task->real_parent);
65738+
65739+ 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));
65740+ }
65741+ break;
65742+ default:
65743+ gr_log_middle(audit, msg, ap);
65744+ }
65745+ va_end(ap);
65746+ // these don't need DEFAULTSECARGS printed on the end
65747+ if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
65748+ gr_log_end(audit, 0);
65749+ else
65750+ gr_log_end(audit, 1);
65751+ END_LOCKS(audit);
65752+}
65753diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
65754new file mode 100644
65755index 0000000..f536303
65756--- /dev/null
65757+++ b/grsecurity/grsec_mem.c
65758@@ -0,0 +1,40 @@
65759+#include <linux/kernel.h>
65760+#include <linux/sched.h>
65761+#include <linux/mm.h>
65762+#include <linux/mman.h>
65763+#include <linux/grinternal.h>
65764+
65765+void
65766+gr_handle_ioperm(void)
65767+{
65768+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
65769+ return;
65770+}
65771+
65772+void
65773+gr_handle_iopl(void)
65774+{
65775+ gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
65776+ return;
65777+}
65778+
65779+void
65780+gr_handle_mem_readwrite(u64 from, u64 to)
65781+{
65782+ gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
65783+ return;
65784+}
65785+
65786+void
65787+gr_handle_vm86(void)
65788+{
65789+ gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
65790+ return;
65791+}
65792+
65793+void
65794+gr_log_badprocpid(const char *entry)
65795+{
65796+ gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
65797+ return;
65798+}
65799diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
65800new file mode 100644
65801index 0000000..2131422
65802--- /dev/null
65803+++ b/grsecurity/grsec_mount.c
65804@@ -0,0 +1,62 @@
65805+#include <linux/kernel.h>
65806+#include <linux/sched.h>
65807+#include <linux/mount.h>
65808+#include <linux/grsecurity.h>
65809+#include <linux/grinternal.h>
65810+
65811+void
65812+gr_log_remount(const char *devname, const int retval)
65813+{
65814+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65815+ if (grsec_enable_mount && (retval >= 0))
65816+ gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
65817+#endif
65818+ return;
65819+}
65820+
65821+void
65822+gr_log_unmount(const char *devname, const int retval)
65823+{
65824+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65825+ if (grsec_enable_mount && (retval >= 0))
65826+ gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
65827+#endif
65828+ return;
65829+}
65830+
65831+void
65832+gr_log_mount(const char *from, const char *to, const int retval)
65833+{
65834+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65835+ if (grsec_enable_mount && (retval >= 0))
65836+ gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
65837+#endif
65838+ return;
65839+}
65840+
65841+int
65842+gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
65843+{
65844+#ifdef CONFIG_GRKERNSEC_ROFS
65845+ if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
65846+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
65847+ return -EPERM;
65848+ } else
65849+ return 0;
65850+#endif
65851+ return 0;
65852+}
65853+
65854+int
65855+gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
65856+{
65857+#ifdef CONFIG_GRKERNSEC_ROFS
65858+ if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
65859+ dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
65860+ gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
65861+ return -EPERM;
65862+ } else
65863+ return 0;
65864+#endif
65865+ return 0;
65866+}
65867diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
65868new file mode 100644
65869index 0000000..a3b12a0
65870--- /dev/null
65871+++ b/grsecurity/grsec_pax.c
65872@@ -0,0 +1,36 @@
65873+#include <linux/kernel.h>
65874+#include <linux/sched.h>
65875+#include <linux/mm.h>
65876+#include <linux/file.h>
65877+#include <linux/grinternal.h>
65878+#include <linux/grsecurity.h>
65879+
65880+void
65881+gr_log_textrel(struct vm_area_struct * vma)
65882+{
65883+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65884+ if (grsec_enable_audit_textrel)
65885+ gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
65886+#endif
65887+ return;
65888+}
65889+
65890+void
65891+gr_log_rwxmmap(struct file *file)
65892+{
65893+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65894+ if (grsec_enable_log_rwxmaps)
65895+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
65896+#endif
65897+ return;
65898+}
65899+
65900+void
65901+gr_log_rwxmprotect(struct file *file)
65902+{
65903+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65904+ if (grsec_enable_log_rwxmaps)
65905+ gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
65906+#endif
65907+ return;
65908+}
65909diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
65910new file mode 100644
65911index 0000000..f7f29aa
65912--- /dev/null
65913+++ b/grsecurity/grsec_ptrace.c
65914@@ -0,0 +1,30 @@
65915+#include <linux/kernel.h>
65916+#include <linux/sched.h>
65917+#include <linux/grinternal.h>
65918+#include <linux/security.h>
65919+
65920+void
65921+gr_audit_ptrace(struct task_struct *task)
65922+{
65923+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65924+ if (grsec_enable_audit_ptrace)
65925+ gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
65926+#endif
65927+ return;
65928+}
65929+
65930+int
65931+gr_ptrace_readexec(struct file *file, int unsafe_flags)
65932+{
65933+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65934+ const struct dentry *dentry = file->f_path.dentry;
65935+ const struct vfsmount *mnt = file->f_path.mnt;
65936+
65937+ if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
65938+ (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
65939+ gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
65940+ return -EACCES;
65941+ }
65942+#endif
65943+ return 0;
65944+}
65945diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
65946new file mode 100644
65947index 0000000..e09715a
65948--- /dev/null
65949+++ b/grsecurity/grsec_sig.c
65950@@ -0,0 +1,222 @@
65951+#include <linux/kernel.h>
65952+#include <linux/sched.h>
65953+#include <linux/delay.h>
65954+#include <linux/grsecurity.h>
65955+#include <linux/grinternal.h>
65956+#include <linux/hardirq.h>
65957+
65958+char *signames[] = {
65959+ [SIGSEGV] = "Segmentation fault",
65960+ [SIGILL] = "Illegal instruction",
65961+ [SIGABRT] = "Abort",
65962+ [SIGBUS] = "Invalid alignment/Bus error"
65963+};
65964+
65965+void
65966+gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
65967+{
65968+#ifdef CONFIG_GRKERNSEC_SIGNAL
65969+ if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
65970+ (sig == SIGABRT) || (sig == SIGBUS))) {
65971+ if (task_pid_nr(t) == task_pid_nr(current)) {
65972+ gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
65973+ } else {
65974+ gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
65975+ }
65976+ }
65977+#endif
65978+ return;
65979+}
65980+
65981+int
65982+gr_handle_signal(const struct task_struct *p, const int sig)
65983+{
65984+#ifdef CONFIG_GRKERNSEC
65985+ /* ignore the 0 signal for protected task checks */
65986+ if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
65987+ gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
65988+ return -EPERM;
65989+ } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
65990+ return -EPERM;
65991+ }
65992+#endif
65993+ return 0;
65994+}
65995+
65996+#ifdef CONFIG_GRKERNSEC
65997+extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
65998+
65999+int gr_fake_force_sig(int sig, struct task_struct *t)
66000+{
66001+ unsigned long int flags;
66002+ int ret, blocked, ignored;
66003+ struct k_sigaction *action;
66004+
66005+ spin_lock_irqsave(&t->sighand->siglock, flags);
66006+ action = &t->sighand->action[sig-1];
66007+ ignored = action->sa.sa_handler == SIG_IGN;
66008+ blocked = sigismember(&t->blocked, sig);
66009+ if (blocked || ignored) {
66010+ action->sa.sa_handler = SIG_DFL;
66011+ if (blocked) {
66012+ sigdelset(&t->blocked, sig);
66013+ recalc_sigpending_and_wake(t);
66014+ }
66015+ }
66016+ if (action->sa.sa_handler == SIG_DFL)
66017+ t->signal->flags &= ~SIGNAL_UNKILLABLE;
66018+ ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
66019+
66020+ spin_unlock_irqrestore(&t->sighand->siglock, flags);
66021+
66022+ return ret;
66023+}
66024+#endif
66025+
66026+#ifdef CONFIG_GRKERNSEC_BRUTE
66027+#define GR_USER_BAN_TIME (15 * 60)
66028+#define GR_DAEMON_BRUTE_TIME (30 * 60)
66029+
66030+static int __get_dumpable(unsigned long mm_flags)
66031+{
66032+ int ret;
66033+
66034+ ret = mm_flags & MMF_DUMPABLE_MASK;
66035+ return (ret >= 2) ? 2 : ret;
66036+}
66037+#endif
66038+
66039+void gr_handle_brute_attach(unsigned long mm_flags)
66040+{
66041+#ifdef CONFIG_GRKERNSEC_BRUTE
66042+ struct task_struct *p = current;
66043+ kuid_t uid = GLOBAL_ROOT_UID;
66044+ int daemon = 0;
66045+
66046+ if (!grsec_enable_brute)
66047+ return;
66048+
66049+ rcu_read_lock();
66050+ read_lock(&tasklist_lock);
66051+ read_lock(&grsec_exec_file_lock);
66052+ if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
66053+ p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
66054+ p->real_parent->brute = 1;
66055+ daemon = 1;
66056+ } else {
66057+ const struct cred *cred = __task_cred(p), *cred2;
66058+ struct task_struct *tsk, *tsk2;
66059+
66060+ if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
66061+ struct user_struct *user;
66062+
66063+ uid = cred->uid;
66064+
66065+ /* this is put upon execution past expiration */
66066+ user = find_user(uid);
66067+ if (user == NULL)
66068+ goto unlock;
66069+ user->banned = 1;
66070+ user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
66071+ if (user->ban_expires == ~0UL)
66072+ user->ban_expires--;
66073+
66074+ do_each_thread(tsk2, tsk) {
66075+ cred2 = __task_cred(tsk);
66076+ if (tsk != p && uid_eq(cred2->uid, uid))
66077+ gr_fake_force_sig(SIGKILL, tsk);
66078+ } while_each_thread(tsk2, tsk);
66079+ }
66080+ }
66081+unlock:
66082+ read_unlock(&grsec_exec_file_lock);
66083+ read_unlock(&tasklist_lock);
66084+ rcu_read_unlock();
66085+
66086+ if (gr_is_global_nonroot(uid))
66087+ printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
66088+ GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
66089+ else if (daemon)
66090+ gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
66091+
66092+#endif
66093+ return;
66094+}
66095+
66096+void gr_handle_brute_check(void)
66097+{
66098+#ifdef CONFIG_GRKERNSEC_BRUTE
66099+ struct task_struct *p = current;
66100+
66101+ if (unlikely(p->brute)) {
66102+ if (!grsec_enable_brute)
66103+ p->brute = 0;
66104+ else if (time_before(get_seconds(), p->brute_expires))
66105+ msleep(30 * 1000);
66106+ }
66107+#endif
66108+ return;
66109+}
66110+
66111+void gr_handle_kernel_exploit(void)
66112+{
66113+#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
66114+ const struct cred *cred;
66115+ struct task_struct *tsk, *tsk2;
66116+ struct user_struct *user;
66117+ kuid_t uid;
66118+
66119+ if (in_irq() || in_serving_softirq() || in_nmi())
66120+ panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
66121+
66122+ uid = current_uid();
66123+
66124+ if (gr_is_global_root(uid))
66125+ panic("grsec: halting the system due to suspicious kernel crash caused by root");
66126+ else {
66127+ /* kill all the processes of this user, hold a reference
66128+ to their creds struct, and prevent them from creating
66129+ another process until system reset
66130+ */
66131+ printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
66132+ GR_GLOBAL_UID(uid));
66133+ /* we intentionally leak this ref */
66134+ user = get_uid(current->cred->user);
66135+ if (user) {
66136+ user->banned = 1;
66137+ user->ban_expires = ~0UL;
66138+ }
66139+
66140+ read_lock(&tasklist_lock);
66141+ do_each_thread(tsk2, tsk) {
66142+ cred = __task_cred(tsk);
66143+ if (uid_eq(cred->uid, uid))
66144+ gr_fake_force_sig(SIGKILL, tsk);
66145+ } while_each_thread(tsk2, tsk);
66146+ read_unlock(&tasklist_lock);
66147+ }
66148+#endif
66149+}
66150+
66151+int __gr_process_user_ban(struct user_struct *user)
66152+{
66153+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66154+ if (unlikely(user->banned)) {
66155+ if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
66156+ user->banned = 0;
66157+ user->ban_expires = 0;
66158+ free_uid(user);
66159+ } else
66160+ return -EPERM;
66161+ }
66162+#endif
66163+ return 0;
66164+}
66165+
66166+int gr_process_user_ban(void)
66167+{
66168+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
66169+ return __gr_process_user_ban(current->cred->user);
66170+#endif
66171+ return 0;
66172+}
66173diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
66174new file mode 100644
66175index 0000000..4030d57
66176--- /dev/null
66177+++ b/grsecurity/grsec_sock.c
66178@@ -0,0 +1,244 @@
66179+#include <linux/kernel.h>
66180+#include <linux/module.h>
66181+#include <linux/sched.h>
66182+#include <linux/file.h>
66183+#include <linux/net.h>
66184+#include <linux/in.h>
66185+#include <linux/ip.h>
66186+#include <net/sock.h>
66187+#include <net/inet_sock.h>
66188+#include <linux/grsecurity.h>
66189+#include <linux/grinternal.h>
66190+#include <linux/gracl.h>
66191+
66192+extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
66193+extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
66194+
66195+EXPORT_SYMBOL(gr_search_udp_recvmsg);
66196+EXPORT_SYMBOL(gr_search_udp_sendmsg);
66197+
66198+#ifdef CONFIG_UNIX_MODULE
66199+EXPORT_SYMBOL(gr_acl_handle_unix);
66200+EXPORT_SYMBOL(gr_acl_handle_mknod);
66201+EXPORT_SYMBOL(gr_handle_chroot_unix);
66202+EXPORT_SYMBOL(gr_handle_create);
66203+#endif
66204+
66205+#ifdef CONFIG_GRKERNSEC
66206+#define gr_conn_table_size 32749
66207+struct conn_table_entry {
66208+ struct conn_table_entry *next;
66209+ struct signal_struct *sig;
66210+};
66211+
66212+struct conn_table_entry *gr_conn_table[gr_conn_table_size];
66213+DEFINE_SPINLOCK(gr_conn_table_lock);
66214+
66215+extern const char * gr_socktype_to_name(unsigned char type);
66216+extern const char * gr_proto_to_name(unsigned char proto);
66217+extern const char * gr_sockfamily_to_name(unsigned char family);
66218+
66219+static __inline__ int
66220+conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
66221+{
66222+ return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
66223+}
66224+
66225+static __inline__ int
66226+conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
66227+ __u16 sport, __u16 dport)
66228+{
66229+ if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
66230+ sig->gr_sport == sport && sig->gr_dport == dport))
66231+ return 1;
66232+ else
66233+ return 0;
66234+}
66235+
66236+static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
66237+{
66238+ struct conn_table_entry **match;
66239+ unsigned int index;
66240+
66241+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66242+ sig->gr_sport, sig->gr_dport,
66243+ gr_conn_table_size);
66244+
66245+ newent->sig = sig;
66246+
66247+ match = &gr_conn_table[index];
66248+ newent->next = *match;
66249+ *match = newent;
66250+
66251+ return;
66252+}
66253+
66254+static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
66255+{
66256+ struct conn_table_entry *match, *last = NULL;
66257+ unsigned int index;
66258+
66259+ index = conn_hash(sig->gr_saddr, sig->gr_daddr,
66260+ sig->gr_sport, sig->gr_dport,
66261+ gr_conn_table_size);
66262+
66263+ match = gr_conn_table[index];
66264+ while (match && !conn_match(match->sig,
66265+ sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
66266+ sig->gr_dport)) {
66267+ last = match;
66268+ match = match->next;
66269+ }
66270+
66271+ if (match) {
66272+ if (last)
66273+ last->next = match->next;
66274+ else
66275+ gr_conn_table[index] = NULL;
66276+ kfree(match);
66277+ }
66278+
66279+ return;
66280+}
66281+
66282+static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
66283+ __u16 sport, __u16 dport)
66284+{
66285+ struct conn_table_entry *match;
66286+ unsigned int index;
66287+
66288+ index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
66289+
66290+ match = gr_conn_table[index];
66291+ while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
66292+ match = match->next;
66293+
66294+ if (match)
66295+ return match->sig;
66296+ else
66297+ return NULL;
66298+}
66299+
66300+#endif
66301+
66302+void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
66303+{
66304+#ifdef CONFIG_GRKERNSEC
66305+ struct signal_struct *sig = task->signal;
66306+ struct conn_table_entry *newent;
66307+
66308+ newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
66309+ if (newent == NULL)
66310+ return;
66311+ /* no bh lock needed since we are called with bh disabled */
66312+ spin_lock(&gr_conn_table_lock);
66313+ gr_del_task_from_ip_table_nolock(sig);
66314+ sig->gr_saddr = inet->inet_rcv_saddr;
66315+ sig->gr_daddr = inet->inet_daddr;
66316+ sig->gr_sport = inet->inet_sport;
66317+ sig->gr_dport = inet->inet_dport;
66318+ gr_add_to_task_ip_table_nolock(sig, newent);
66319+ spin_unlock(&gr_conn_table_lock);
66320+#endif
66321+ return;
66322+}
66323+
66324+void gr_del_task_from_ip_table(struct task_struct *task)
66325+{
66326+#ifdef CONFIG_GRKERNSEC
66327+ spin_lock_bh(&gr_conn_table_lock);
66328+ gr_del_task_from_ip_table_nolock(task->signal);
66329+ spin_unlock_bh(&gr_conn_table_lock);
66330+#endif
66331+ return;
66332+}
66333+
66334+void
66335+gr_attach_curr_ip(const struct sock *sk)
66336+{
66337+#ifdef CONFIG_GRKERNSEC
66338+ struct signal_struct *p, *set;
66339+ const struct inet_sock *inet = inet_sk(sk);
66340+
66341+ if (unlikely(sk->sk_protocol != IPPROTO_TCP))
66342+ return;
66343+
66344+ set = current->signal;
66345+
66346+ spin_lock_bh(&gr_conn_table_lock);
66347+ p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
66348+ inet->inet_dport, inet->inet_sport);
66349+ if (unlikely(p != NULL)) {
66350+ set->curr_ip = p->curr_ip;
66351+ set->used_accept = 1;
66352+ gr_del_task_from_ip_table_nolock(p);
66353+ spin_unlock_bh(&gr_conn_table_lock);
66354+ return;
66355+ }
66356+ spin_unlock_bh(&gr_conn_table_lock);
66357+
66358+ set->curr_ip = inet->inet_daddr;
66359+ set->used_accept = 1;
66360+#endif
66361+ return;
66362+}
66363+
66364+int
66365+gr_handle_sock_all(const int family, const int type, const int protocol)
66366+{
66367+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66368+ if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
66369+ (family != AF_UNIX)) {
66370+ if (family == AF_INET)
66371+ gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
66372+ else
66373+ gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
66374+ return -EACCES;
66375+ }
66376+#endif
66377+ return 0;
66378+}
66379+
66380+int
66381+gr_handle_sock_server(const struct sockaddr *sck)
66382+{
66383+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66384+ if (grsec_enable_socket_server &&
66385+ in_group_p(grsec_socket_server_gid) &&
66386+ sck && (sck->sa_family != AF_UNIX) &&
66387+ (sck->sa_family != AF_LOCAL)) {
66388+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66389+ return -EACCES;
66390+ }
66391+#endif
66392+ return 0;
66393+}
66394+
66395+int
66396+gr_handle_sock_server_other(const struct sock *sck)
66397+{
66398+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66399+ if (grsec_enable_socket_server &&
66400+ in_group_p(grsec_socket_server_gid) &&
66401+ sck && (sck->sk_family != AF_UNIX) &&
66402+ (sck->sk_family != AF_LOCAL)) {
66403+ gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
66404+ return -EACCES;
66405+ }
66406+#endif
66407+ return 0;
66408+}
66409+
66410+int
66411+gr_handle_sock_client(const struct sockaddr *sck)
66412+{
66413+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66414+ if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
66415+ sck && (sck->sa_family != AF_UNIX) &&
66416+ (sck->sa_family != AF_LOCAL)) {
66417+ gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
66418+ return -EACCES;
66419+ }
66420+#endif
66421+ return 0;
66422+}
66423diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
66424new file mode 100644
66425index 0000000..f55ef0f
66426--- /dev/null
66427+++ b/grsecurity/grsec_sysctl.c
66428@@ -0,0 +1,469 @@
66429+#include <linux/kernel.h>
66430+#include <linux/sched.h>
66431+#include <linux/sysctl.h>
66432+#include <linux/grsecurity.h>
66433+#include <linux/grinternal.h>
66434+
66435+int
66436+gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
66437+{
66438+#ifdef CONFIG_GRKERNSEC_SYSCTL
66439+ if (dirname == NULL || name == NULL)
66440+ return 0;
66441+ if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
66442+ gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
66443+ return -EACCES;
66444+ }
66445+#endif
66446+ return 0;
66447+}
66448+
66449+#ifdef CONFIG_GRKERNSEC_ROFS
66450+static int __maybe_unused one = 1;
66451+#endif
66452+
66453+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
66454+struct ctl_table grsecurity_table[] = {
66455+#ifdef CONFIG_GRKERNSEC_SYSCTL
66456+#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
66457+#ifdef CONFIG_GRKERNSEC_IO
66458+ {
66459+ .procname = "disable_priv_io",
66460+ .data = &grsec_disable_privio,
66461+ .maxlen = sizeof(int),
66462+ .mode = 0600,
66463+ .proc_handler = &proc_dointvec,
66464+ },
66465+#endif
66466+#endif
66467+#ifdef CONFIG_GRKERNSEC_LINK
66468+ {
66469+ .procname = "linking_restrictions",
66470+ .data = &grsec_enable_link,
66471+ .maxlen = sizeof(int),
66472+ .mode = 0600,
66473+ .proc_handler = &proc_dointvec,
66474+ },
66475+#endif
66476+#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
66477+ {
66478+ .procname = "enforce_symlinksifowner",
66479+ .data = &grsec_enable_symlinkown,
66480+ .maxlen = sizeof(int),
66481+ .mode = 0600,
66482+ .proc_handler = &proc_dointvec,
66483+ },
66484+ {
66485+ .procname = "symlinkown_gid",
66486+ .data = &grsec_symlinkown_gid,
66487+ .maxlen = sizeof(int),
66488+ .mode = 0600,
66489+ .proc_handler = &proc_dointvec,
66490+ },
66491+#endif
66492+#ifdef CONFIG_GRKERNSEC_BRUTE
66493+ {
66494+ .procname = "deter_bruteforce",
66495+ .data = &grsec_enable_brute,
66496+ .maxlen = sizeof(int),
66497+ .mode = 0600,
66498+ .proc_handler = &proc_dointvec,
66499+ },
66500+#endif
66501+#ifdef CONFIG_GRKERNSEC_FIFO
66502+ {
66503+ .procname = "fifo_restrictions",
66504+ .data = &grsec_enable_fifo,
66505+ .maxlen = sizeof(int),
66506+ .mode = 0600,
66507+ .proc_handler = &proc_dointvec,
66508+ },
66509+#endif
66510+#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
66511+ {
66512+ .procname = "ptrace_readexec",
66513+ .data = &grsec_enable_ptrace_readexec,
66514+ .maxlen = sizeof(int),
66515+ .mode = 0600,
66516+ .proc_handler = &proc_dointvec,
66517+ },
66518+#endif
66519+#ifdef CONFIG_GRKERNSEC_SETXID
66520+ {
66521+ .procname = "consistent_setxid",
66522+ .data = &grsec_enable_setxid,
66523+ .maxlen = sizeof(int),
66524+ .mode = 0600,
66525+ .proc_handler = &proc_dointvec,
66526+ },
66527+#endif
66528+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
66529+ {
66530+ .procname = "ip_blackhole",
66531+ .data = &grsec_enable_blackhole,
66532+ .maxlen = sizeof(int),
66533+ .mode = 0600,
66534+ .proc_handler = &proc_dointvec,
66535+ },
66536+ {
66537+ .procname = "lastack_retries",
66538+ .data = &grsec_lastack_retries,
66539+ .maxlen = sizeof(int),
66540+ .mode = 0600,
66541+ .proc_handler = &proc_dointvec,
66542+ },
66543+#endif
66544+#ifdef CONFIG_GRKERNSEC_EXECLOG
66545+ {
66546+ .procname = "exec_logging",
66547+ .data = &grsec_enable_execlog,
66548+ .maxlen = sizeof(int),
66549+ .mode = 0600,
66550+ .proc_handler = &proc_dointvec,
66551+ },
66552+#endif
66553+#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
66554+ {
66555+ .procname = "rwxmap_logging",
66556+ .data = &grsec_enable_log_rwxmaps,
66557+ .maxlen = sizeof(int),
66558+ .mode = 0600,
66559+ .proc_handler = &proc_dointvec,
66560+ },
66561+#endif
66562+#ifdef CONFIG_GRKERNSEC_SIGNAL
66563+ {
66564+ .procname = "signal_logging",
66565+ .data = &grsec_enable_signal,
66566+ .maxlen = sizeof(int),
66567+ .mode = 0600,
66568+ .proc_handler = &proc_dointvec,
66569+ },
66570+#endif
66571+#ifdef CONFIG_GRKERNSEC_FORKFAIL
66572+ {
66573+ .procname = "forkfail_logging",
66574+ .data = &grsec_enable_forkfail,
66575+ .maxlen = sizeof(int),
66576+ .mode = 0600,
66577+ .proc_handler = &proc_dointvec,
66578+ },
66579+#endif
66580+#ifdef CONFIG_GRKERNSEC_TIME
66581+ {
66582+ .procname = "timechange_logging",
66583+ .data = &grsec_enable_time,
66584+ .maxlen = sizeof(int),
66585+ .mode = 0600,
66586+ .proc_handler = &proc_dointvec,
66587+ },
66588+#endif
66589+#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
66590+ {
66591+ .procname = "chroot_deny_shmat",
66592+ .data = &grsec_enable_chroot_shmat,
66593+ .maxlen = sizeof(int),
66594+ .mode = 0600,
66595+ .proc_handler = &proc_dointvec,
66596+ },
66597+#endif
66598+#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
66599+ {
66600+ .procname = "chroot_deny_unix",
66601+ .data = &grsec_enable_chroot_unix,
66602+ .maxlen = sizeof(int),
66603+ .mode = 0600,
66604+ .proc_handler = &proc_dointvec,
66605+ },
66606+#endif
66607+#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
66608+ {
66609+ .procname = "chroot_deny_mount",
66610+ .data = &grsec_enable_chroot_mount,
66611+ .maxlen = sizeof(int),
66612+ .mode = 0600,
66613+ .proc_handler = &proc_dointvec,
66614+ },
66615+#endif
66616+#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
66617+ {
66618+ .procname = "chroot_deny_fchdir",
66619+ .data = &grsec_enable_chroot_fchdir,
66620+ .maxlen = sizeof(int),
66621+ .mode = 0600,
66622+ .proc_handler = &proc_dointvec,
66623+ },
66624+#endif
66625+#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
66626+ {
66627+ .procname = "chroot_deny_chroot",
66628+ .data = &grsec_enable_chroot_double,
66629+ .maxlen = sizeof(int),
66630+ .mode = 0600,
66631+ .proc_handler = &proc_dointvec,
66632+ },
66633+#endif
66634+#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
66635+ {
66636+ .procname = "chroot_deny_pivot",
66637+ .data = &grsec_enable_chroot_pivot,
66638+ .maxlen = sizeof(int),
66639+ .mode = 0600,
66640+ .proc_handler = &proc_dointvec,
66641+ },
66642+#endif
66643+#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
66644+ {
66645+ .procname = "chroot_enforce_chdir",
66646+ .data = &grsec_enable_chroot_chdir,
66647+ .maxlen = sizeof(int),
66648+ .mode = 0600,
66649+ .proc_handler = &proc_dointvec,
66650+ },
66651+#endif
66652+#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
66653+ {
66654+ .procname = "chroot_deny_chmod",
66655+ .data = &grsec_enable_chroot_chmod,
66656+ .maxlen = sizeof(int),
66657+ .mode = 0600,
66658+ .proc_handler = &proc_dointvec,
66659+ },
66660+#endif
66661+#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
66662+ {
66663+ .procname = "chroot_deny_mknod",
66664+ .data = &grsec_enable_chroot_mknod,
66665+ .maxlen = sizeof(int),
66666+ .mode = 0600,
66667+ .proc_handler = &proc_dointvec,
66668+ },
66669+#endif
66670+#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
66671+ {
66672+ .procname = "chroot_restrict_nice",
66673+ .data = &grsec_enable_chroot_nice,
66674+ .maxlen = sizeof(int),
66675+ .mode = 0600,
66676+ .proc_handler = &proc_dointvec,
66677+ },
66678+#endif
66679+#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
66680+ {
66681+ .procname = "chroot_execlog",
66682+ .data = &grsec_enable_chroot_execlog,
66683+ .maxlen = sizeof(int),
66684+ .mode = 0600,
66685+ .proc_handler = &proc_dointvec,
66686+ },
66687+#endif
66688+#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
66689+ {
66690+ .procname = "chroot_caps",
66691+ .data = &grsec_enable_chroot_caps,
66692+ .maxlen = sizeof(int),
66693+ .mode = 0600,
66694+ .proc_handler = &proc_dointvec,
66695+ },
66696+#endif
66697+#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
66698+ {
66699+ .procname = "chroot_deny_sysctl",
66700+ .data = &grsec_enable_chroot_sysctl,
66701+ .maxlen = sizeof(int),
66702+ .mode = 0600,
66703+ .proc_handler = &proc_dointvec,
66704+ },
66705+#endif
66706+#ifdef CONFIG_GRKERNSEC_TPE
66707+ {
66708+ .procname = "tpe",
66709+ .data = &grsec_enable_tpe,
66710+ .maxlen = sizeof(int),
66711+ .mode = 0600,
66712+ .proc_handler = &proc_dointvec,
66713+ },
66714+ {
66715+ .procname = "tpe_gid",
66716+ .data = &grsec_tpe_gid,
66717+ .maxlen = sizeof(int),
66718+ .mode = 0600,
66719+ .proc_handler = &proc_dointvec,
66720+ },
66721+#endif
66722+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66723+ {
66724+ .procname = "tpe_invert",
66725+ .data = &grsec_enable_tpe_invert,
66726+ .maxlen = sizeof(int),
66727+ .mode = 0600,
66728+ .proc_handler = &proc_dointvec,
66729+ },
66730+#endif
66731+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66732+ {
66733+ .procname = "tpe_restrict_all",
66734+ .data = &grsec_enable_tpe_all,
66735+ .maxlen = sizeof(int),
66736+ .mode = 0600,
66737+ .proc_handler = &proc_dointvec,
66738+ },
66739+#endif
66740+#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
66741+ {
66742+ .procname = "socket_all",
66743+ .data = &grsec_enable_socket_all,
66744+ .maxlen = sizeof(int),
66745+ .mode = 0600,
66746+ .proc_handler = &proc_dointvec,
66747+ },
66748+ {
66749+ .procname = "socket_all_gid",
66750+ .data = &grsec_socket_all_gid,
66751+ .maxlen = sizeof(int),
66752+ .mode = 0600,
66753+ .proc_handler = &proc_dointvec,
66754+ },
66755+#endif
66756+#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
66757+ {
66758+ .procname = "socket_client",
66759+ .data = &grsec_enable_socket_client,
66760+ .maxlen = sizeof(int),
66761+ .mode = 0600,
66762+ .proc_handler = &proc_dointvec,
66763+ },
66764+ {
66765+ .procname = "socket_client_gid",
66766+ .data = &grsec_socket_client_gid,
66767+ .maxlen = sizeof(int),
66768+ .mode = 0600,
66769+ .proc_handler = &proc_dointvec,
66770+ },
66771+#endif
66772+#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
66773+ {
66774+ .procname = "socket_server",
66775+ .data = &grsec_enable_socket_server,
66776+ .maxlen = sizeof(int),
66777+ .mode = 0600,
66778+ .proc_handler = &proc_dointvec,
66779+ },
66780+ {
66781+ .procname = "socket_server_gid",
66782+ .data = &grsec_socket_server_gid,
66783+ .maxlen = sizeof(int),
66784+ .mode = 0600,
66785+ .proc_handler = &proc_dointvec,
66786+ },
66787+#endif
66788+#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
66789+ {
66790+ .procname = "audit_group",
66791+ .data = &grsec_enable_group,
66792+ .maxlen = sizeof(int),
66793+ .mode = 0600,
66794+ .proc_handler = &proc_dointvec,
66795+ },
66796+ {
66797+ .procname = "audit_gid",
66798+ .data = &grsec_audit_gid,
66799+ .maxlen = sizeof(int),
66800+ .mode = 0600,
66801+ .proc_handler = &proc_dointvec,
66802+ },
66803+#endif
66804+#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
66805+ {
66806+ .procname = "audit_chdir",
66807+ .data = &grsec_enable_chdir,
66808+ .maxlen = sizeof(int),
66809+ .mode = 0600,
66810+ .proc_handler = &proc_dointvec,
66811+ },
66812+#endif
66813+#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
66814+ {
66815+ .procname = "audit_mount",
66816+ .data = &grsec_enable_mount,
66817+ .maxlen = sizeof(int),
66818+ .mode = 0600,
66819+ .proc_handler = &proc_dointvec,
66820+ },
66821+#endif
66822+#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
66823+ {
66824+ .procname = "audit_textrel",
66825+ .data = &grsec_enable_audit_textrel,
66826+ .maxlen = sizeof(int),
66827+ .mode = 0600,
66828+ .proc_handler = &proc_dointvec,
66829+ },
66830+#endif
66831+#ifdef CONFIG_GRKERNSEC_DMESG
66832+ {
66833+ .procname = "dmesg",
66834+ .data = &grsec_enable_dmesg,
66835+ .maxlen = sizeof(int),
66836+ .mode = 0600,
66837+ .proc_handler = &proc_dointvec,
66838+ },
66839+#endif
66840+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
66841+ {
66842+ .procname = "chroot_findtask",
66843+ .data = &grsec_enable_chroot_findtask,
66844+ .maxlen = sizeof(int),
66845+ .mode = 0600,
66846+ .proc_handler = &proc_dointvec,
66847+ },
66848+#endif
66849+#ifdef CONFIG_GRKERNSEC_RESLOG
66850+ {
66851+ .procname = "resource_logging",
66852+ .data = &grsec_resource_logging,
66853+ .maxlen = sizeof(int),
66854+ .mode = 0600,
66855+ .proc_handler = &proc_dointvec,
66856+ },
66857+#endif
66858+#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
66859+ {
66860+ .procname = "audit_ptrace",
66861+ .data = &grsec_enable_audit_ptrace,
66862+ .maxlen = sizeof(int),
66863+ .mode = 0600,
66864+ .proc_handler = &proc_dointvec,
66865+ },
66866+#endif
66867+#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
66868+ {
66869+ .procname = "harden_ptrace",
66870+ .data = &grsec_enable_harden_ptrace,
66871+ .maxlen = sizeof(int),
66872+ .mode = 0600,
66873+ .proc_handler = &proc_dointvec,
66874+ },
66875+#endif
66876+ {
66877+ .procname = "grsec_lock",
66878+ .data = &grsec_lock,
66879+ .maxlen = sizeof(int),
66880+ .mode = 0600,
66881+ .proc_handler = &proc_dointvec,
66882+ },
66883+#endif
66884+#ifdef CONFIG_GRKERNSEC_ROFS
66885+ {
66886+ .procname = "romount_protect",
66887+ .data = &grsec_enable_rofs,
66888+ .maxlen = sizeof(int),
66889+ .mode = 0600,
66890+ .proc_handler = &proc_dointvec_minmax,
66891+ .extra1 = &one,
66892+ .extra2 = &one,
66893+ },
66894+#endif
66895+ { }
66896+};
66897+#endif
66898diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
66899new file mode 100644
66900index 0000000..0dc13c3
66901--- /dev/null
66902+++ b/grsecurity/grsec_time.c
66903@@ -0,0 +1,16 @@
66904+#include <linux/kernel.h>
66905+#include <linux/sched.h>
66906+#include <linux/grinternal.h>
66907+#include <linux/module.h>
66908+
66909+void
66910+gr_log_timechange(void)
66911+{
66912+#ifdef CONFIG_GRKERNSEC_TIME
66913+ if (grsec_enable_time)
66914+ gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
66915+#endif
66916+ return;
66917+}
66918+
66919+EXPORT_SYMBOL(gr_log_timechange);
66920diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
66921new file mode 100644
66922index 0000000..ee57dcf
66923--- /dev/null
66924+++ b/grsecurity/grsec_tpe.c
66925@@ -0,0 +1,73 @@
66926+#include <linux/kernel.h>
66927+#include <linux/sched.h>
66928+#include <linux/file.h>
66929+#include <linux/fs.h>
66930+#include <linux/grinternal.h>
66931+
66932+extern int gr_acl_tpe_check(void);
66933+
66934+int
66935+gr_tpe_allow(const struct file *file)
66936+{
66937+#ifdef CONFIG_GRKERNSEC
66938+ struct inode *inode = file->f_path.dentry->d_parent->d_inode;
66939+ const struct cred *cred = current_cred();
66940+ char *msg = NULL;
66941+ char *msg2 = NULL;
66942+
66943+ // never restrict root
66944+ if (gr_is_global_root(cred->uid))
66945+ return 1;
66946+
66947+ if (grsec_enable_tpe) {
66948+#ifdef CONFIG_GRKERNSEC_TPE_INVERT
66949+ if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
66950+ msg = "not being in trusted group";
66951+ else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
66952+ msg = "being in untrusted group";
66953+#else
66954+ if (in_group_p(grsec_tpe_gid))
66955+ msg = "being in untrusted group";
66956+#endif
66957+ }
66958+ if (!msg && gr_acl_tpe_check())
66959+ msg = "being in untrusted role";
66960+
66961+ // not in any affected group/role
66962+ if (!msg)
66963+ goto next_check;
66964+
66965+ if (gr_is_global_nonroot(inode->i_uid))
66966+ msg2 = "file in non-root-owned directory";
66967+ else if (inode->i_mode & S_IWOTH)
66968+ msg2 = "file in world-writable directory";
66969+ else if (inode->i_mode & S_IWGRP)
66970+ msg2 = "file in group-writable directory";
66971+
66972+ if (msg && msg2) {
66973+ char fullmsg[70] = {0};
66974+ snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
66975+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
66976+ return 0;
66977+ }
66978+ msg = NULL;
66979+next_check:
66980+#ifdef CONFIG_GRKERNSEC_TPE_ALL
66981+ if (!grsec_enable_tpe || !grsec_enable_tpe_all)
66982+ return 1;
66983+
66984+ if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
66985+ msg = "directory not owned by user";
66986+ else if (inode->i_mode & S_IWOTH)
66987+ msg = "file in world-writable directory";
66988+ else if (inode->i_mode & S_IWGRP)
66989+ msg = "file in group-writable directory";
66990+
66991+ if (msg) {
66992+ gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
66993+ return 0;
66994+ }
66995+#endif
66996+#endif
66997+ return 1;
66998+}
66999diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
67000new file mode 100644
67001index 0000000..9f7b1ac
67002--- /dev/null
67003+++ b/grsecurity/grsum.c
67004@@ -0,0 +1,61 @@
67005+#include <linux/err.h>
67006+#include <linux/kernel.h>
67007+#include <linux/sched.h>
67008+#include <linux/mm.h>
67009+#include <linux/scatterlist.h>
67010+#include <linux/crypto.h>
67011+#include <linux/gracl.h>
67012+
67013+
67014+#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
67015+#error "crypto and sha256 must be built into the kernel"
67016+#endif
67017+
67018+int
67019+chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
67020+{
67021+ char *p;
67022+ struct crypto_hash *tfm;
67023+ struct hash_desc desc;
67024+ struct scatterlist sg;
67025+ unsigned char temp_sum[GR_SHA_LEN];
67026+ volatile int retval = 0;
67027+ volatile int dummy = 0;
67028+ unsigned int i;
67029+
67030+ sg_init_table(&sg, 1);
67031+
67032+ tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
67033+ if (IS_ERR(tfm)) {
67034+ /* should never happen, since sha256 should be built in */
67035+ return 1;
67036+ }
67037+
67038+ desc.tfm = tfm;
67039+ desc.flags = 0;
67040+
67041+ crypto_hash_init(&desc);
67042+
67043+ p = salt;
67044+ sg_set_buf(&sg, p, GR_SALT_LEN);
67045+ crypto_hash_update(&desc, &sg, sg.length);
67046+
67047+ p = entry->pw;
67048+ sg_set_buf(&sg, p, strlen(p));
67049+
67050+ crypto_hash_update(&desc, &sg, sg.length);
67051+
67052+ crypto_hash_final(&desc, temp_sum);
67053+
67054+ memset(entry->pw, 0, GR_PW_LEN);
67055+
67056+ for (i = 0; i < GR_SHA_LEN; i++)
67057+ if (sum[i] != temp_sum[i])
67058+ retval = 1;
67059+ else
67060+ dummy = 1; // waste a cycle
67061+
67062+ crypto_free_hash(tfm);
67063+
67064+ return retval;
67065+}
67066diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
67067index 77ff547..181834f 100644
67068--- a/include/asm-generic/4level-fixup.h
67069+++ b/include/asm-generic/4level-fixup.h
67070@@ -13,8 +13,10 @@
67071 #define pmd_alloc(mm, pud, address) \
67072 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
67073 NULL: pmd_offset(pud, address))
67074+#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
67075
67076 #define pud_alloc(mm, pgd, address) (pgd)
67077+#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
67078 #define pud_offset(pgd, start) (pgd)
67079 #define pud_none(pud) 0
67080 #define pud_bad(pud) 0
67081diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
67082index b7babf0..04ad282 100644
67083--- a/include/asm-generic/atomic-long.h
67084+++ b/include/asm-generic/atomic-long.h
67085@@ -22,6 +22,12 @@
67086
67087 typedef atomic64_t atomic_long_t;
67088
67089+#ifdef CONFIG_PAX_REFCOUNT
67090+typedef atomic64_unchecked_t atomic_long_unchecked_t;
67091+#else
67092+typedef atomic64_t atomic_long_unchecked_t;
67093+#endif
67094+
67095 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
67096
67097 static inline long atomic_long_read(atomic_long_t *l)
67098@@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67099 return (long)atomic64_read(v);
67100 }
67101
67102+#ifdef CONFIG_PAX_REFCOUNT
67103+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67104+{
67105+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67106+
67107+ return (long)atomic64_read_unchecked(v);
67108+}
67109+#endif
67110+
67111 static inline void atomic_long_set(atomic_long_t *l, long i)
67112 {
67113 atomic64_t *v = (atomic64_t *)l;
67114@@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67115 atomic64_set(v, i);
67116 }
67117
67118+#ifdef CONFIG_PAX_REFCOUNT
67119+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67120+{
67121+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67122+
67123+ atomic64_set_unchecked(v, i);
67124+}
67125+#endif
67126+
67127 static inline void atomic_long_inc(atomic_long_t *l)
67128 {
67129 atomic64_t *v = (atomic64_t *)l;
67130@@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67131 atomic64_inc(v);
67132 }
67133
67134+#ifdef CONFIG_PAX_REFCOUNT
67135+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67136+{
67137+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67138+
67139+ atomic64_inc_unchecked(v);
67140+}
67141+#endif
67142+
67143 static inline void atomic_long_dec(atomic_long_t *l)
67144 {
67145 atomic64_t *v = (atomic64_t *)l;
67146@@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67147 atomic64_dec(v);
67148 }
67149
67150+#ifdef CONFIG_PAX_REFCOUNT
67151+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67152+{
67153+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67154+
67155+ atomic64_dec_unchecked(v);
67156+}
67157+#endif
67158+
67159 static inline void atomic_long_add(long i, atomic_long_t *l)
67160 {
67161 atomic64_t *v = (atomic64_t *)l;
67162@@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67163 atomic64_add(i, v);
67164 }
67165
67166+#ifdef CONFIG_PAX_REFCOUNT
67167+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67168+{
67169+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67170+
67171+ atomic64_add_unchecked(i, v);
67172+}
67173+#endif
67174+
67175 static inline void atomic_long_sub(long i, atomic_long_t *l)
67176 {
67177 atomic64_t *v = (atomic64_t *)l;
67178@@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67179 atomic64_sub(i, v);
67180 }
67181
67182+#ifdef CONFIG_PAX_REFCOUNT
67183+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67184+{
67185+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67186+
67187+ atomic64_sub_unchecked(i, v);
67188+}
67189+#endif
67190+
67191 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67192 {
67193 atomic64_t *v = (atomic64_t *)l;
67194@@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67195 return (long)atomic64_add_return(i, v);
67196 }
67197
67198+#ifdef CONFIG_PAX_REFCOUNT
67199+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67200+{
67201+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67202+
67203+ return (long)atomic64_add_return_unchecked(i, v);
67204+}
67205+#endif
67206+
67207 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67208 {
67209 atomic64_t *v = (atomic64_t *)l;
67210@@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67211 return (long)atomic64_inc_return(v);
67212 }
67213
67214+#ifdef CONFIG_PAX_REFCOUNT
67215+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67216+{
67217+ atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
67218+
67219+ return (long)atomic64_inc_return_unchecked(v);
67220+}
67221+#endif
67222+
67223 static inline long atomic_long_dec_return(atomic_long_t *l)
67224 {
67225 atomic64_t *v = (atomic64_t *)l;
67226@@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67227
67228 typedef atomic_t atomic_long_t;
67229
67230+#ifdef CONFIG_PAX_REFCOUNT
67231+typedef atomic_unchecked_t atomic_long_unchecked_t;
67232+#else
67233+typedef atomic_t atomic_long_unchecked_t;
67234+#endif
67235+
67236 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
67237 static inline long atomic_long_read(atomic_long_t *l)
67238 {
67239@@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
67240 return (long)atomic_read(v);
67241 }
67242
67243+#ifdef CONFIG_PAX_REFCOUNT
67244+static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
67245+{
67246+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67247+
67248+ return (long)atomic_read_unchecked(v);
67249+}
67250+#endif
67251+
67252 static inline void atomic_long_set(atomic_long_t *l, long i)
67253 {
67254 atomic_t *v = (atomic_t *)l;
67255@@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
67256 atomic_set(v, i);
67257 }
67258
67259+#ifdef CONFIG_PAX_REFCOUNT
67260+static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
67261+{
67262+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67263+
67264+ atomic_set_unchecked(v, i);
67265+}
67266+#endif
67267+
67268 static inline void atomic_long_inc(atomic_long_t *l)
67269 {
67270 atomic_t *v = (atomic_t *)l;
67271@@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
67272 atomic_inc(v);
67273 }
67274
67275+#ifdef CONFIG_PAX_REFCOUNT
67276+static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
67277+{
67278+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67279+
67280+ atomic_inc_unchecked(v);
67281+}
67282+#endif
67283+
67284 static inline void atomic_long_dec(atomic_long_t *l)
67285 {
67286 atomic_t *v = (atomic_t *)l;
67287@@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
67288 atomic_dec(v);
67289 }
67290
67291+#ifdef CONFIG_PAX_REFCOUNT
67292+static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
67293+{
67294+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67295+
67296+ atomic_dec_unchecked(v);
67297+}
67298+#endif
67299+
67300 static inline void atomic_long_add(long i, atomic_long_t *l)
67301 {
67302 atomic_t *v = (atomic_t *)l;
67303@@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
67304 atomic_add(i, v);
67305 }
67306
67307+#ifdef CONFIG_PAX_REFCOUNT
67308+static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
67309+{
67310+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67311+
67312+ atomic_add_unchecked(i, v);
67313+}
67314+#endif
67315+
67316 static inline void atomic_long_sub(long i, atomic_long_t *l)
67317 {
67318 atomic_t *v = (atomic_t *)l;
67319@@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
67320 atomic_sub(i, v);
67321 }
67322
67323+#ifdef CONFIG_PAX_REFCOUNT
67324+static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
67325+{
67326+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67327+
67328+ atomic_sub_unchecked(i, v);
67329+}
67330+#endif
67331+
67332 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
67333 {
67334 atomic_t *v = (atomic_t *)l;
67335@@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
67336 return (long)atomic_add_return(i, v);
67337 }
67338
67339+#ifdef CONFIG_PAX_REFCOUNT
67340+static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
67341+{
67342+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67343+
67344+ return (long)atomic_add_return_unchecked(i, v);
67345+}
67346+
67347+#endif
67348+
67349 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
67350 {
67351 atomic_t *v = (atomic_t *)l;
67352@@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
67353 return (long)atomic_inc_return(v);
67354 }
67355
67356+#ifdef CONFIG_PAX_REFCOUNT
67357+static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
67358+{
67359+ atomic_unchecked_t *v = (atomic_unchecked_t *)l;
67360+
67361+ return (long)atomic_inc_return_unchecked(v);
67362+}
67363+#endif
67364+
67365 static inline long atomic_long_dec_return(atomic_long_t *l)
67366 {
67367 atomic_t *v = (atomic_t *)l;
67368@@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
67369
67370 #endif /* BITS_PER_LONG == 64 */
67371
67372+#ifdef CONFIG_PAX_REFCOUNT
67373+static inline void pax_refcount_needs_these_functions(void)
67374+{
67375+ atomic_read_unchecked((atomic_unchecked_t *)NULL);
67376+ atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
67377+ atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
67378+ atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
67379+ atomic_inc_unchecked((atomic_unchecked_t *)NULL);
67380+ (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
67381+ atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
67382+ atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
67383+ atomic_dec_unchecked((atomic_unchecked_t *)NULL);
67384+ atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
67385+ (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
67386+#ifdef CONFIG_X86
67387+ atomic_clear_mask_unchecked(0, NULL);
67388+ atomic_set_mask_unchecked(0, NULL);
67389+#endif
67390+
67391+ atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
67392+ atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
67393+ atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
67394+ atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
67395+ atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
67396+ atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
67397+ atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
67398+ atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
67399+}
67400+#else
67401+#define atomic_read_unchecked(v) atomic_read(v)
67402+#define atomic_set_unchecked(v, i) atomic_set((v), (i))
67403+#define atomic_add_unchecked(i, v) atomic_add((i), (v))
67404+#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
67405+#define atomic_inc_unchecked(v) atomic_inc(v)
67406+#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
67407+#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
67408+#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
67409+#define atomic_dec_unchecked(v) atomic_dec(v)
67410+#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
67411+#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
67412+#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
67413+#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
67414+
67415+#define atomic_long_read_unchecked(v) atomic_long_read(v)
67416+#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
67417+#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
67418+#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
67419+#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
67420+#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
67421+#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
67422+#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
67423+#endif
67424+
67425 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
67426diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
67427index 33bd2de..f31bff97 100644
67428--- a/include/asm-generic/atomic.h
67429+++ b/include/asm-generic/atomic.h
67430@@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
67431 * Atomically clears the bits set in @mask from @v
67432 */
67433 #ifndef atomic_clear_mask
67434-static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
67435+static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
67436 {
67437 unsigned long flags;
67438
67439diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
67440index b18ce4f..2ee2843 100644
67441--- a/include/asm-generic/atomic64.h
67442+++ b/include/asm-generic/atomic64.h
67443@@ -16,6 +16,8 @@ typedef struct {
67444 long long counter;
67445 } atomic64_t;
67446
67447+typedef atomic64_t atomic64_unchecked_t;
67448+
67449 #define ATOMIC64_INIT(i) { (i) }
67450
67451 extern long long atomic64_read(const atomic64_t *v);
67452@@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
67453 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
67454 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
67455
67456+#define atomic64_read_unchecked(v) atomic64_read(v)
67457+#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
67458+#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
67459+#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
67460+#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
67461+#define atomic64_inc_unchecked(v) atomic64_inc(v)
67462+#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
67463+#define atomic64_dec_unchecked(v) atomic64_dec(v)
67464+#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
67465+
67466 #endif /* _ASM_GENERIC_ATOMIC64_H */
67467diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
67468index 1bfcfe5..e04c5c9 100644
67469--- a/include/asm-generic/cache.h
67470+++ b/include/asm-generic/cache.h
67471@@ -6,7 +6,7 @@
67472 * cache lines need to provide their own cache.h.
67473 */
67474
67475-#define L1_CACHE_SHIFT 5
67476-#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
67477+#define L1_CACHE_SHIFT 5UL
67478+#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
67479
67480 #endif /* __ASM_GENERIC_CACHE_H */
67481diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
67482index 0d68a1e..b74a761 100644
67483--- a/include/asm-generic/emergency-restart.h
67484+++ b/include/asm-generic/emergency-restart.h
67485@@ -1,7 +1,7 @@
67486 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
67487 #define _ASM_GENERIC_EMERGENCY_RESTART_H
67488
67489-static inline void machine_emergency_restart(void)
67490+static inline __noreturn void machine_emergency_restart(void)
67491 {
67492 machine_restart(NULL);
67493 }
67494diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
67495index 90f99c7..00ce236 100644
67496--- a/include/asm-generic/kmap_types.h
67497+++ b/include/asm-generic/kmap_types.h
67498@@ -2,9 +2,9 @@
67499 #define _ASM_GENERIC_KMAP_TYPES_H
67500
67501 #ifdef __WITH_KM_FENCE
67502-# define KM_TYPE_NR 41
67503+# define KM_TYPE_NR 42
67504 #else
67505-# define KM_TYPE_NR 20
67506+# define KM_TYPE_NR 21
67507 #endif
67508
67509 #endif
67510diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
67511index 9ceb03b..62b0b8f 100644
67512--- a/include/asm-generic/local.h
67513+++ b/include/asm-generic/local.h
67514@@ -23,24 +23,37 @@ typedef struct
67515 atomic_long_t a;
67516 } local_t;
67517
67518+typedef struct {
67519+ atomic_long_unchecked_t a;
67520+} local_unchecked_t;
67521+
67522 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
67523
67524 #define local_read(l) atomic_long_read(&(l)->a)
67525+#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
67526 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
67527+#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
67528 #define local_inc(l) atomic_long_inc(&(l)->a)
67529+#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
67530 #define local_dec(l) atomic_long_dec(&(l)->a)
67531+#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
67532 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
67533+#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
67534 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
67535+#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
67536
67537 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
67538 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
67539 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
67540 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
67541 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
67542+#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
67543 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
67544 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
67545+#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
67546
67547 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67548+#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
67549 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
67550 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
67551 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
67552diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
67553index 725612b..9cc513a 100644
67554--- a/include/asm-generic/pgtable-nopmd.h
67555+++ b/include/asm-generic/pgtable-nopmd.h
67556@@ -1,14 +1,19 @@
67557 #ifndef _PGTABLE_NOPMD_H
67558 #define _PGTABLE_NOPMD_H
67559
67560-#ifndef __ASSEMBLY__
67561-
67562 #include <asm-generic/pgtable-nopud.h>
67563
67564-struct mm_struct;
67565-
67566 #define __PAGETABLE_PMD_FOLDED
67567
67568+#define PMD_SHIFT PUD_SHIFT
67569+#define PTRS_PER_PMD 1
67570+#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
67571+#define PMD_MASK (~(PMD_SIZE-1))
67572+
67573+#ifndef __ASSEMBLY__
67574+
67575+struct mm_struct;
67576+
67577 /*
67578 * Having the pmd type consist of a pud gets the size right, and allows
67579 * us to conceptually access the pud entry that this pmd is folded into
67580@@ -16,11 +21,6 @@ struct mm_struct;
67581 */
67582 typedef struct { pud_t pud; } pmd_t;
67583
67584-#define PMD_SHIFT PUD_SHIFT
67585-#define PTRS_PER_PMD 1
67586-#define PMD_SIZE (1UL << PMD_SHIFT)
67587-#define PMD_MASK (~(PMD_SIZE-1))
67588-
67589 /*
67590 * The "pud_xxx()" functions here are trivial for a folded two-level
67591 * setup: the pmd is never bad, and a pmd always exists (as it's folded
67592diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
67593index 810431d..0ec4804f 100644
67594--- a/include/asm-generic/pgtable-nopud.h
67595+++ b/include/asm-generic/pgtable-nopud.h
67596@@ -1,10 +1,15 @@
67597 #ifndef _PGTABLE_NOPUD_H
67598 #define _PGTABLE_NOPUD_H
67599
67600-#ifndef __ASSEMBLY__
67601-
67602 #define __PAGETABLE_PUD_FOLDED
67603
67604+#define PUD_SHIFT PGDIR_SHIFT
67605+#define PTRS_PER_PUD 1
67606+#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
67607+#define PUD_MASK (~(PUD_SIZE-1))
67608+
67609+#ifndef __ASSEMBLY__
67610+
67611 /*
67612 * Having the pud type consist of a pgd gets the size right, and allows
67613 * us to conceptually access the pgd entry that this pud is folded into
67614@@ -12,11 +17,6 @@
67615 */
67616 typedef struct { pgd_t pgd; } pud_t;
67617
67618-#define PUD_SHIFT PGDIR_SHIFT
67619-#define PTRS_PER_PUD 1
67620-#define PUD_SIZE (1UL << PUD_SHIFT)
67621-#define PUD_MASK (~(PUD_SIZE-1))
67622-
67623 /*
67624 * The "pgd_xxx()" functions here are trivial for a folded two-level
67625 * setup: the pud is never bad, and a pud always exists (as it's folded
67626@@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
67627 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
67628
67629 #define pgd_populate(mm, pgd, pud) do { } while (0)
67630+#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
67631 /*
67632 * (puds are folded into pgds so this doesn't get actually called,
67633 * but the define is needed for a generic inline function.)
67634diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
67635index a59ff51..2594a70 100644
67636--- a/include/asm-generic/pgtable.h
67637+++ b/include/asm-generic/pgtable.h
67638@@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
67639 }
67640 #endif /* CONFIG_NUMA_BALANCING */
67641
67642+#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
67643+static inline unsigned long pax_open_kernel(void) { return 0; }
67644+#endif
67645+
67646+#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
67647+static inline unsigned long pax_close_kernel(void) { return 0; }
67648+#endif
67649+
67650 #endif /* CONFIG_MMU */
67651
67652 #endif /* !__ASSEMBLY__ */
67653diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
67654index afa12c7..99d4da0 100644
67655--- a/include/asm-generic/vmlinux.lds.h
67656+++ b/include/asm-generic/vmlinux.lds.h
67657@@ -245,6 +245,7 @@
67658 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
67659 VMLINUX_SYMBOL(__start_rodata) = .; \
67660 *(.rodata) *(.rodata.*) \
67661+ *(.data..read_only) \
67662 *(__vermagic) /* Kernel version magic */ \
67663 . = ALIGN(8); \
67664 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
67665@@ -755,17 +756,18 @@
67666 * section in the linker script will go there too. @phdr should have
67667 * a leading colon.
67668 *
67669- * Note that this macros defines __per_cpu_load as an absolute symbol.
67670+ * Note that this macros defines per_cpu_load as an absolute symbol.
67671 * If there is no need to put the percpu section at a predetermined
67672 * address, use PERCPU_SECTION.
67673 */
67674 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
67675- VMLINUX_SYMBOL(__per_cpu_load) = .; \
67676- .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
67677+ per_cpu_load = .; \
67678+ .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
67679 - LOAD_OFFSET) { \
67680+ VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
67681 PERCPU_INPUT(cacheline) \
67682 } phdr \
67683- . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
67684+ . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
67685
67686 /**
67687 * PERCPU_SECTION - define output section for percpu area, simple version
67688diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
67689index 418d270..bfd2794 100644
67690--- a/include/crypto/algapi.h
67691+++ b/include/crypto/algapi.h
67692@@ -34,7 +34,7 @@ struct crypto_type {
67693 unsigned int maskclear;
67694 unsigned int maskset;
67695 unsigned int tfmsize;
67696-};
67697+} __do_const;
67698
67699 struct crypto_instance {
67700 struct crypto_alg alg;
67701diff --git a/include/drm/drmP.h b/include/drm/drmP.h
67702index f1ce786..086a7a5 100644
67703--- a/include/drm/drmP.h
67704+++ b/include/drm/drmP.h
67705@@ -72,6 +72,7 @@
67706 #include <linux/workqueue.h>
67707 #include <linux/poll.h>
67708 #include <asm/pgalloc.h>
67709+#include <asm/local.h>
67710 #include <drm/drm.h>
67711 #include <drm/drm_sarea.h>
67712
67713@@ -296,10 +297,12 @@ do { \
67714 * \param cmd command.
67715 * \param arg argument.
67716 */
67717-typedef int drm_ioctl_t(struct drm_device *dev, void *data,
67718+typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
67719+ struct drm_file *file_priv);
67720+typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
67721 struct drm_file *file_priv);
67722
67723-typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67724+typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
67725 unsigned long arg);
67726
67727 #define DRM_IOCTL_NR(n) _IOC_NR(n)
67728@@ -314,9 +317,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
67729 struct drm_ioctl_desc {
67730 unsigned int cmd;
67731 int flags;
67732- drm_ioctl_t *func;
67733+ drm_ioctl_t func;
67734 unsigned int cmd_drv;
67735-};
67736+} __do_const;
67737
67738 /**
67739 * Creates a driver or general drm_ioctl_desc array entry for the given
67740@@ -1014,7 +1017,7 @@ struct drm_info_list {
67741 int (*show)(struct seq_file*, void*); /** show callback */
67742 u32 driver_features; /**< Required driver features for this entry */
67743 void *data;
67744-};
67745+} __do_const;
67746
67747 /**
67748 * debugfs node structure. This structure represents a debugfs file.
67749@@ -1087,7 +1090,7 @@ struct drm_device {
67750
67751 /** \name Usage Counters */
67752 /*@{ */
67753- int open_count; /**< Outstanding files open */
67754+ local_t open_count; /**< Outstanding files open */
67755 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
67756 atomic_t vma_count; /**< Outstanding vma areas open */
67757 int buf_use; /**< Buffers in use -- cannot alloc */
67758@@ -1098,7 +1101,7 @@ struct drm_device {
67759 /*@{ */
67760 unsigned long counters;
67761 enum drm_stat_type types[15];
67762- atomic_t counts[15];
67763+ atomic_unchecked_t counts[15];
67764 /*@} */
67765
67766 struct list_head filelist;
67767diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
67768index f43d556..94d9343 100644
67769--- a/include/drm/drm_crtc_helper.h
67770+++ b/include/drm/drm_crtc_helper.h
67771@@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
67772 struct drm_connector *connector);
67773 /* disable encoder when not in use - more explicit than dpms off */
67774 void (*disable)(struct drm_encoder *encoder);
67775-};
67776+} __no_const;
67777
67778 /**
67779 * drm_connector_helper_funcs - helper operations for connectors
67780diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
67781index 72dcbe8..8db58d7 100644
67782--- a/include/drm/ttm/ttm_memory.h
67783+++ b/include/drm/ttm/ttm_memory.h
67784@@ -48,7 +48,7 @@
67785
67786 struct ttm_mem_shrink {
67787 int (*do_shrink) (struct ttm_mem_shrink *);
67788-};
67789+} __no_const;
67790
67791 /**
67792 * struct ttm_mem_global - Global memory accounting structure.
67793diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
67794index 4b840e8..155d235 100644
67795--- a/include/keys/asymmetric-subtype.h
67796+++ b/include/keys/asymmetric-subtype.h
67797@@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
67798 /* Verify the signature on a key of this subtype (optional) */
67799 int (*verify_signature)(const struct key *key,
67800 const struct public_key_signature *sig);
67801-};
67802+} __do_const;
67803
67804 /**
67805 * asymmetric_key_subtype - Get the subtype from an asymmetric key
67806diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
67807index c1da539..1dcec55 100644
67808--- a/include/linux/atmdev.h
67809+++ b/include/linux/atmdev.h
67810@@ -28,7 +28,7 @@ struct compat_atm_iobuf {
67811 #endif
67812
67813 struct k_atm_aal_stats {
67814-#define __HANDLE_ITEM(i) atomic_t i
67815+#define __HANDLE_ITEM(i) atomic_unchecked_t i
67816 __AAL_STAT_ITEMS
67817 #undef __HANDLE_ITEM
67818 };
67819@@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
67820 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
67821 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
67822 struct module *owner;
67823-};
67824+} __do_const ;
67825
67826 struct atmphy_ops {
67827 int (*start)(struct atm_dev *dev);
67828diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
67829index c3a0914..ec5d48a 100644
67830--- a/include/linux/binfmts.h
67831+++ b/include/linux/binfmts.h
67832@@ -73,8 +73,9 @@ struct linux_binfmt {
67833 int (*load_binary)(struct linux_binprm *);
67834 int (*load_shlib)(struct file *);
67835 int (*core_dump)(struct coredump_params *cprm);
67836+ void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
67837 unsigned long min_coredump; /* minimal dump size */
67838-};
67839+} __do_const;
67840
67841 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
67842
67843diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
67844index 33f358f..7f2c27f 100644
67845--- a/include/linux/blkdev.h
67846+++ b/include/linux/blkdev.h
67847@@ -1499,7 +1499,7 @@ struct block_device_operations {
67848 /* this callback is with swap_lock and sometimes page table lock held */
67849 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
67850 struct module *owner;
67851-};
67852+} __do_const;
67853
67854 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
67855 unsigned long);
67856diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
67857index 7c2e030..b72475d 100644
67858--- a/include/linux/blktrace_api.h
67859+++ b/include/linux/blktrace_api.h
67860@@ -23,7 +23,7 @@ struct blk_trace {
67861 struct dentry *dir;
67862 struct dentry *dropped_file;
67863 struct dentry *msg_file;
67864- atomic_t dropped;
67865+ atomic_unchecked_t dropped;
67866 };
67867
67868 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
67869diff --git a/include/linux/cache.h b/include/linux/cache.h
67870index 4c57065..4307975 100644
67871--- a/include/linux/cache.h
67872+++ b/include/linux/cache.h
67873@@ -16,6 +16,10 @@
67874 #define __read_mostly
67875 #endif
67876
67877+#ifndef __read_only
67878+#define __read_only __read_mostly
67879+#endif
67880+
67881 #ifndef ____cacheline_aligned
67882 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
67883 #endif
67884diff --git a/include/linux/capability.h b/include/linux/capability.h
67885index d9a4f7f4..19f77d6 100644
67886--- a/include/linux/capability.h
67887+++ b/include/linux/capability.h
67888@@ -213,8 +213,13 @@ extern bool ns_capable(struct user_namespace *ns, int cap);
67889 extern bool nsown_capable(int cap);
67890 extern bool inode_capable(const struct inode *inode, int cap);
67891 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
67892+extern bool capable_nolog(int cap);
67893+extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
67894+extern bool inode_capable_nolog(const struct inode *inode, int cap);
67895
67896 /* audit system wants to get cap info from files as well */
67897 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
67898
67899+extern int is_privileged_binary(const struct dentry *dentry);
67900+
67901 #endif /* !_LINUX_CAPABILITY_H */
67902diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
67903index 8609d57..86e4d79 100644
67904--- a/include/linux/cdrom.h
67905+++ b/include/linux/cdrom.h
67906@@ -87,7 +87,6 @@ struct cdrom_device_ops {
67907
67908 /* driver specifications */
67909 const int capability; /* capability flags */
67910- int n_minors; /* number of active minor devices */
67911 /* handle uniform packets for scsi type devices (scsi,atapi) */
67912 int (*generic_packet) (struct cdrom_device_info *,
67913 struct packet_command *);
67914diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
67915index 42e55de..1cd0e66 100644
67916--- a/include/linux/cleancache.h
67917+++ b/include/linux/cleancache.h
67918@@ -31,7 +31,7 @@ struct cleancache_ops {
67919 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
67920 void (*invalidate_inode)(int, struct cleancache_filekey);
67921 void (*invalidate_fs)(int);
67922-};
67923+} __no_const;
67924
67925 extern struct cleancache_ops
67926 cleancache_register_ops(struct cleancache_ops *ops);
67927diff --git a/include/linux/compat.h b/include/linux/compat.h
67928index 377cd8c..2479845 100644
67929--- a/include/linux/compat.h
67930+++ b/include/linux/compat.h
67931@@ -332,14 +332,14 @@ long compat_sys_msgsnd(int first, int second, int third, void __user *uptr);
67932 long compat_sys_msgrcv(int first, int second, int msgtyp, int third,
67933 int version, void __user *uptr);
67934 long compat_sys_shmat(int first, int second, compat_uptr_t third, int version,
67935- void __user *uptr);
67936+ void __user *uptr) __intentional_overflow(0);
67937 #else
67938 long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
67939 long compat_sys_msgsnd(int msqid, struct compat_msgbuf __user *msgp,
67940 compat_ssize_t msgsz, int msgflg);
67941 long compat_sys_msgrcv(int msqid, struct compat_msgbuf __user *msgp,
67942 compat_ssize_t msgsz, long msgtyp, int msgflg);
67943-long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
67944+long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
67945 #endif
67946 long compat_sys_msgctl(int first, int second, void __user *uptr);
67947 long compat_sys_shmctl(int first, int second, void __user *uptr);
67948@@ -442,7 +442,7 @@ extern int compat_ptrace_request(struct task_struct *child,
67949 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
67950 compat_ulong_t addr, compat_ulong_t data);
67951 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
67952- compat_long_t addr, compat_long_t data);
67953+ compat_ulong_t addr, compat_ulong_t data);
67954
67955 /*
67956 * epoll (fs/eventpoll.c) compat bits follow ...
67957diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
67958index 68b162d..660f5f0 100644
67959--- a/include/linux/compiler-gcc4.h
67960+++ b/include/linux/compiler-gcc4.h
67961@@ -39,9 +39,29 @@
67962 # define __compiletime_warning(message) __attribute__((warning(message)))
67963 # define __compiletime_error(message) __attribute__((error(message)))
67964 #endif /* __CHECKER__ */
67965+
67966+#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
67967+#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
67968+#define __bos0(ptr) __bos((ptr), 0)
67969+#define __bos1(ptr) __bos((ptr), 1)
67970 #endif /* GCC_VERSION >= 40300 */
67971
67972 #if GCC_VERSION >= 40500
67973+
67974+#ifdef CONSTIFY_PLUGIN
67975+#define __no_const __attribute__((no_const))
67976+#define __do_const __attribute__((do_const))
67977+#endif
67978+
67979+#ifdef SIZE_OVERFLOW_PLUGIN
67980+#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
67981+#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
67982+#endif
67983+
67984+#ifdef LATENT_ENTROPY_PLUGIN
67985+#define __latent_entropy __attribute__((latent_entropy))
67986+#endif
67987+
67988 /*
67989 * Mark a position in code as unreachable. This can be used to
67990 * suppress control flow warnings after asm blocks that transfer
67991diff --git a/include/linux/compiler.h b/include/linux/compiler.h
67992index 10b8f23..5e0b083 100644
67993--- a/include/linux/compiler.h
67994+++ b/include/linux/compiler.h
67995@@ -5,11 +5,14 @@
67996
67997 #ifdef __CHECKER__
67998 # define __user __attribute__((noderef, address_space(1)))
67999+# define __force_user __force __user
68000 # define __kernel __attribute__((address_space(0)))
68001+# define __force_kernel __force __kernel
68002 # define __safe __attribute__((safe))
68003 # define __force __attribute__((force))
68004 # define __nocast __attribute__((nocast))
68005 # define __iomem __attribute__((noderef, address_space(2)))
68006+# define __force_iomem __force __iomem
68007 # define __must_hold(x) __attribute__((context(x,1,1)))
68008 # define __acquires(x) __attribute__((context(x,0,1)))
68009 # define __releases(x) __attribute__((context(x,1,0)))
68010@@ -17,20 +20,37 @@
68011 # define __release(x) __context__(x,-1)
68012 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
68013 # define __percpu __attribute__((noderef, address_space(3)))
68014+# define __force_percpu __force __percpu
68015 #ifdef CONFIG_SPARSE_RCU_POINTER
68016 # define __rcu __attribute__((noderef, address_space(4)))
68017+# define __force_rcu __force __rcu
68018 #else
68019 # define __rcu
68020+# define __force_rcu
68021 #endif
68022 extern void __chk_user_ptr(const volatile void __user *);
68023 extern void __chk_io_ptr(const volatile void __iomem *);
68024 #else
68025-# define __user
68026-# define __kernel
68027+# ifdef CHECKER_PLUGIN
68028+//# define __user
68029+//# define __force_user
68030+//# define __kernel
68031+//# define __force_kernel
68032+# else
68033+# ifdef STRUCTLEAK_PLUGIN
68034+# define __user __attribute__((user))
68035+# else
68036+# define __user
68037+# endif
68038+# define __force_user
68039+# define __kernel
68040+# define __force_kernel
68041+# endif
68042 # define __safe
68043 # define __force
68044 # define __nocast
68045 # define __iomem
68046+# define __force_iomem
68047 # define __chk_user_ptr(x) (void)0
68048 # define __chk_io_ptr(x) (void)0
68049 # define __builtin_warning(x, y...) (1)
68050@@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
68051 # define __release(x) (void)0
68052 # define __cond_lock(x,c) (c)
68053 # define __percpu
68054+# define __force_percpu
68055 # define __rcu
68056+# define __force_rcu
68057 #endif
68058
68059 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
68060@@ -275,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68061 # define __attribute_const__ /* unimplemented */
68062 #endif
68063
68064+#ifndef __no_const
68065+# define __no_const
68066+#endif
68067+
68068+#ifndef __do_const
68069+# define __do_const
68070+#endif
68071+
68072+#ifndef __size_overflow
68073+# define __size_overflow(...)
68074+#endif
68075+
68076+#ifndef __intentional_overflow
68077+# define __intentional_overflow(...)
68078+#endif
68079+
68080+#ifndef __latent_entropy
68081+# define __latent_entropy
68082+#endif
68083+
68084 /*
68085 * Tell gcc if a function is cold. The compiler will assume any path
68086 * directly leading to the call is unlikely.
68087@@ -284,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68088 #define __cold
68089 #endif
68090
68091+#ifndef __alloc_size
68092+#define __alloc_size(...)
68093+#endif
68094+
68095+#ifndef __bos
68096+#define __bos(ptr, arg)
68097+#endif
68098+
68099+#ifndef __bos0
68100+#define __bos0(ptr)
68101+#endif
68102+
68103+#ifndef __bos1
68104+#define __bos1(ptr)
68105+#endif
68106+
68107 /* Simple shorthand for a section definition */
68108 #ifndef __section
68109 # define __section(S) __attribute__ ((__section__(#S)))
68110@@ -349,6 +407,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
68111 * use is to mediate communication between process-level code and irq/NMI
68112 * handlers, all running on the same CPU.
68113 */
68114-#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
68115+#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
68116+#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
68117
68118 #endif /* __LINUX_COMPILER_H */
68119diff --git a/include/linux/completion.h b/include/linux/completion.h
68120index 33f0280..35c6568 100644
68121--- a/include/linux/completion.h
68122+++ b/include/linux/completion.h
68123@@ -79,15 +79,15 @@ static inline void init_completion(struct completion *x)
68124 extern void wait_for_completion(struct completion *);
68125 extern void wait_for_completion_io(struct completion *);
68126 extern int wait_for_completion_interruptible(struct completion *x);
68127-extern int wait_for_completion_killable(struct completion *x);
68128+extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
68129 extern unsigned long wait_for_completion_timeout(struct completion *x,
68130 unsigned long timeout);
68131 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
68132 unsigned long timeout);
68133 extern long wait_for_completion_interruptible_timeout(
68134- struct completion *x, unsigned long timeout);
68135+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68136 extern long wait_for_completion_killable_timeout(
68137- struct completion *x, unsigned long timeout);
68138+ struct completion *x, unsigned long timeout) __intentional_overflow(-1);
68139 extern bool try_wait_for_completion(struct completion *x);
68140 extern bool completion_done(struct completion *x);
68141
68142diff --git a/include/linux/configfs.h b/include/linux/configfs.h
68143index 34025df..d94bbbc 100644
68144--- a/include/linux/configfs.h
68145+++ b/include/linux/configfs.h
68146@@ -125,7 +125,7 @@ struct configfs_attribute {
68147 const char *ca_name;
68148 struct module *ca_owner;
68149 umode_t ca_mode;
68150-};
68151+} __do_const;
68152
68153 /*
68154 * Users often need to create attribute structures for their configurable
68155diff --git a/include/linux/cpu.h b/include/linux/cpu.h
68156index 714e792..e6130d9 100644
68157--- a/include/linux/cpu.h
68158+++ b/include/linux/cpu.h
68159@@ -115,7 +115,7 @@ enum {
68160 /* Need to know about CPUs going up/down? */
68161 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
68162 #define cpu_notifier(fn, pri) { \
68163- static struct notifier_block fn##_nb __cpuinitdata = \
68164+ static struct notifier_block fn##_nb = \
68165 { .notifier_call = fn, .priority = pri }; \
68166 register_cpu_notifier(&fn##_nb); \
68167 }
68168diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
68169index a22944c..4e695fe 100644
68170--- a/include/linux/cpufreq.h
68171+++ b/include/linux/cpufreq.h
68172@@ -252,7 +252,7 @@ struct cpufreq_driver {
68173 int (*suspend) (struct cpufreq_policy *policy);
68174 int (*resume) (struct cpufreq_policy *policy);
68175 struct freq_attr **attr;
68176-};
68177+} __do_const;
68178
68179 /* flags */
68180
68181@@ -311,6 +311,7 @@ struct global_attr {
68182 ssize_t (*store)(struct kobject *a, struct attribute *b,
68183 const char *c, size_t count);
68184 };
68185+typedef struct global_attr __no_const global_attr_no_const;
68186
68187 #define define_one_global_ro(_name) \
68188 static struct global_attr _name = \
68189diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
68190index 480c14d..552896f 100644
68191--- a/include/linux/cpuidle.h
68192+++ b/include/linux/cpuidle.h
68193@@ -52,7 +52,8 @@ struct cpuidle_state {
68194 int index);
68195
68196 int (*enter_dead) (struct cpuidle_device *dev, int index);
68197-};
68198+} __do_const;
68199+typedef struct cpuidle_state __no_const cpuidle_state_no_const;
68200
68201 /* Idle State Flags */
68202 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
68203@@ -194,7 +195,7 @@ struct cpuidle_governor {
68204 void (*reflect) (struct cpuidle_device *dev, int index);
68205
68206 struct module *owner;
68207-};
68208+} __do_const;
68209
68210 #ifdef CONFIG_CPU_IDLE
68211
68212diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
68213index 0325602..5e9feff 100644
68214--- a/include/linux/cpumask.h
68215+++ b/include/linux/cpumask.h
68216@@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68217 }
68218
68219 /* Valid inputs for n are -1 and 0. */
68220-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68221+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68222 {
68223 return n+1;
68224 }
68225
68226-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68227+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68228 {
68229 return n+1;
68230 }
68231
68232-static inline unsigned int cpumask_next_and(int n,
68233+static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
68234 const struct cpumask *srcp,
68235 const struct cpumask *andp)
68236 {
68237@@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
68238 *
68239 * Returns >= nr_cpu_ids if no further cpus set.
68240 */
68241-static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68242+static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
68243 {
68244 /* -1 is a legal arg here. */
68245 if (n != -1)
68246@@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
68247 *
68248 * Returns >= nr_cpu_ids if no further cpus unset.
68249 */
68250-static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68251+static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
68252 {
68253 /* -1 is a legal arg here. */
68254 if (n != -1)
68255@@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
68256 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
68257 }
68258
68259-int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
68260+int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
68261 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
68262
68263 /**
68264diff --git a/include/linux/cred.h b/include/linux/cred.h
68265index 04421e8..6bce4ef 100644
68266--- a/include/linux/cred.h
68267+++ b/include/linux/cred.h
68268@@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
68269 static inline void validate_process_creds(void)
68270 {
68271 }
68272+static inline void validate_task_creds(struct task_struct *task)
68273+{
68274+}
68275 #endif
68276
68277 /**
68278diff --git a/include/linux/crypto.h b/include/linux/crypto.h
68279index b92eadf..b4ecdc1 100644
68280--- a/include/linux/crypto.h
68281+++ b/include/linux/crypto.h
68282@@ -373,7 +373,7 @@ struct cipher_tfm {
68283 const u8 *key, unsigned int keylen);
68284 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68285 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
68286-};
68287+} __no_const;
68288
68289 struct hash_tfm {
68290 int (*init)(struct hash_desc *desc);
68291@@ -394,13 +394,13 @@ struct compress_tfm {
68292 int (*cot_decompress)(struct crypto_tfm *tfm,
68293 const u8 *src, unsigned int slen,
68294 u8 *dst, unsigned int *dlen);
68295-};
68296+} __no_const;
68297
68298 struct rng_tfm {
68299 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
68300 unsigned int dlen);
68301 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
68302-};
68303+} __no_const;
68304
68305 #define crt_ablkcipher crt_u.ablkcipher
68306 #define crt_aead crt_u.aead
68307diff --git a/include/linux/ctype.h b/include/linux/ctype.h
68308index 8acfe31..6ffccd63 100644
68309--- a/include/linux/ctype.h
68310+++ b/include/linux/ctype.h
68311@@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
68312 * Fast implementation of tolower() for internal usage. Do not use in your
68313 * code.
68314 */
68315-static inline char _tolower(const char c)
68316+static inline unsigned char _tolower(const unsigned char c)
68317 {
68318 return c | 0x20;
68319 }
68320diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
68321index 7925bf0..d5143d2 100644
68322--- a/include/linux/decompress/mm.h
68323+++ b/include/linux/decompress/mm.h
68324@@ -77,7 +77,7 @@ static void free(void *where)
68325 * warnings when not needed (indeed large_malloc / large_free are not
68326 * needed by inflate */
68327
68328-#define malloc(a) kmalloc(a, GFP_KERNEL)
68329+#define malloc(a) kmalloc((a), GFP_KERNEL)
68330 #define free(a) kfree(a)
68331
68332 #define large_malloc(a) vmalloc(a)
68333diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
68334index fe8c447..bdc1f33 100644
68335--- a/include/linux/devfreq.h
68336+++ b/include/linux/devfreq.h
68337@@ -114,7 +114,7 @@ struct devfreq_governor {
68338 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
68339 int (*event_handler)(struct devfreq *devfreq,
68340 unsigned int event, void *data);
68341-};
68342+} __do_const;
68343
68344 /**
68345 * struct devfreq - Device devfreq structure
68346diff --git a/include/linux/device.h b/include/linux/device.h
68347index 9d6464e..8a5cc92 100644
68348--- a/include/linux/device.h
68349+++ b/include/linux/device.h
68350@@ -295,7 +295,7 @@ struct subsys_interface {
68351 struct list_head node;
68352 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
68353 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
68354-};
68355+} __do_const;
68356
68357 int subsys_interface_register(struct subsys_interface *sif);
68358 void subsys_interface_unregister(struct subsys_interface *sif);
68359@@ -475,7 +475,7 @@ struct device_type {
68360 void (*release)(struct device *dev);
68361
68362 const struct dev_pm_ops *pm;
68363-};
68364+} __do_const;
68365
68366 /* interface for exporting device attributes */
68367 struct device_attribute {
68368@@ -485,11 +485,12 @@ struct device_attribute {
68369 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
68370 const char *buf, size_t count);
68371 };
68372+typedef struct device_attribute __no_const device_attribute_no_const;
68373
68374 struct dev_ext_attribute {
68375 struct device_attribute attr;
68376 void *var;
68377-};
68378+} __do_const;
68379
68380 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
68381 char *buf);
68382diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
68383index 94af418..b1ca7a2 100644
68384--- a/include/linux/dma-mapping.h
68385+++ b/include/linux/dma-mapping.h
68386@@ -54,7 +54,7 @@ struct dma_map_ops {
68387 u64 (*get_required_mask)(struct device *dev);
68388 #endif
68389 int is_phys;
68390-};
68391+} __do_const;
68392
68393 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
68394
68395diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
68396index 91ac8da..a841318 100644
68397--- a/include/linux/dmaengine.h
68398+++ b/include/linux/dmaengine.h
68399@@ -1034,9 +1034,9 @@ struct dma_pinned_list {
68400 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
68401 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
68402
68403-dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68404+dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
68405 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
68406-dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68407+dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
68408 struct dma_pinned_list *pinned_list, struct page *page,
68409 unsigned int offset, size_t len);
68410
68411diff --git a/include/linux/efi.h b/include/linux/efi.h
68412index 3d7df3d..301f024 100644
68413--- a/include/linux/efi.h
68414+++ b/include/linux/efi.h
68415@@ -740,6 +740,7 @@ struct efivar_operations {
68416 efi_set_variable_t *set_variable;
68417 efi_query_variable_store_t *query_variable_store;
68418 };
68419+typedef struct efivar_operations __no_const efivar_operations_no_const;
68420
68421 struct efivars {
68422 /*
68423diff --git a/include/linux/elf.h b/include/linux/elf.h
68424index 40a3c0e..4c45a38 100644
68425--- a/include/linux/elf.h
68426+++ b/include/linux/elf.h
68427@@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
68428 #define elf_note elf32_note
68429 #define elf_addr_t Elf32_Off
68430 #define Elf_Half Elf32_Half
68431+#define elf_dyn Elf32_Dyn
68432
68433 #else
68434
68435@@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
68436 #define elf_note elf64_note
68437 #define elf_addr_t Elf64_Off
68438 #define Elf_Half Elf64_Half
68439+#define elf_dyn Elf64_Dyn
68440
68441 #endif
68442
68443diff --git a/include/linux/err.h b/include/linux/err.h
68444index f2edce2..cc2082c 100644
68445--- a/include/linux/err.h
68446+++ b/include/linux/err.h
68447@@ -19,12 +19,12 @@
68448
68449 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
68450
68451-static inline void * __must_check ERR_PTR(long error)
68452+static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
68453 {
68454 return (void *) error;
68455 }
68456
68457-static inline long __must_check PTR_ERR(const void *ptr)
68458+static inline long __must_check __intentional_overflow(-1) PTR_ERR(const void *ptr)
68459 {
68460 return (long) ptr;
68461 }
68462diff --git a/include/linux/extcon.h b/include/linux/extcon.h
68463index fcb51c8..bdafcf6 100644
68464--- a/include/linux/extcon.h
68465+++ b/include/linux/extcon.h
68466@@ -134,7 +134,7 @@ struct extcon_dev {
68467 /* /sys/class/extcon/.../mutually_exclusive/... */
68468 struct attribute_group attr_g_muex;
68469 struct attribute **attrs_muex;
68470- struct device_attribute *d_attrs_muex;
68471+ device_attribute_no_const *d_attrs_muex;
68472 };
68473
68474 /**
68475diff --git a/include/linux/fb.h b/include/linux/fb.h
68476index 58b9860..58e5516 100644
68477--- a/include/linux/fb.h
68478+++ b/include/linux/fb.h
68479@@ -304,7 +304,7 @@ struct fb_ops {
68480 /* called at KDB enter and leave time to prepare the console */
68481 int (*fb_debug_enter)(struct fb_info *info);
68482 int (*fb_debug_leave)(struct fb_info *info);
68483-};
68484+} __do_const;
68485
68486 #ifdef CONFIG_FB_TILEBLITTING
68487 #define FB_TILE_CURSOR_NONE 0
68488diff --git a/include/linux/filter.h b/include/linux/filter.h
68489index c45eabc..baa0be5 100644
68490--- a/include/linux/filter.h
68491+++ b/include/linux/filter.h
68492@@ -20,6 +20,7 @@ struct compat_sock_fprog {
68493
68494 struct sk_buff;
68495 struct sock;
68496+struct bpf_jit_work;
68497
68498 struct sk_filter
68499 {
68500@@ -27,6 +28,9 @@ struct sk_filter
68501 unsigned int len; /* Number of filter blocks */
68502 unsigned int (*bpf_func)(const struct sk_buff *skb,
68503 const struct sock_filter *filter);
68504+#ifdef CONFIG_BPF_JIT
68505+ struct bpf_jit_work *work;
68506+#endif
68507 struct rcu_head rcu;
68508 struct sock_filter insns[0];
68509 };
68510diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
68511index 3044254..9767f41 100644
68512--- a/include/linux/frontswap.h
68513+++ b/include/linux/frontswap.h
68514@@ -11,7 +11,7 @@ struct frontswap_ops {
68515 int (*load)(unsigned, pgoff_t, struct page *);
68516 void (*invalidate_page)(unsigned, pgoff_t);
68517 void (*invalidate_area)(unsigned);
68518-};
68519+} __no_const;
68520
68521 extern bool frontswap_enabled;
68522 extern struct frontswap_ops
68523diff --git a/include/linux/fs.h b/include/linux/fs.h
68524index 2c28271..8d3d74c 100644
68525--- a/include/linux/fs.h
68526+++ b/include/linux/fs.h
68527@@ -1541,7 +1541,8 @@ struct file_operations {
68528 long (*fallocate)(struct file *file, int mode, loff_t offset,
68529 loff_t len);
68530 int (*show_fdinfo)(struct seq_file *m, struct file *f);
68531-};
68532+} __do_const;
68533+typedef struct file_operations __no_const file_operations_no_const;
68534
68535 struct inode_operations {
68536 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
68537@@ -2672,4 +2673,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
68538 inode->i_flags |= S_NOSEC;
68539 }
68540
68541+static inline bool is_sidechannel_device(const struct inode *inode)
68542+{
68543+#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
68544+ umode_t mode = inode->i_mode;
68545+ return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
68546+#else
68547+ return false;
68548+#endif
68549+}
68550+
68551 #endif /* _LINUX_FS_H */
68552diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
68553index 2b93a9a..855d94a 100644
68554--- a/include/linux/fs_struct.h
68555+++ b/include/linux/fs_struct.h
68556@@ -6,7 +6,7 @@
68557 #include <linux/seqlock.h>
68558
68559 struct fs_struct {
68560- int users;
68561+ atomic_t users;
68562 spinlock_t lock;
68563 seqcount_t seq;
68564 int umask;
68565diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
68566index 5dfa0aa..6acf322 100644
68567--- a/include/linux/fscache-cache.h
68568+++ b/include/linux/fscache-cache.h
68569@@ -112,7 +112,7 @@ struct fscache_operation {
68570 fscache_operation_release_t release;
68571 };
68572
68573-extern atomic_t fscache_op_debug_id;
68574+extern atomic_unchecked_t fscache_op_debug_id;
68575 extern void fscache_op_work_func(struct work_struct *work);
68576
68577 extern void fscache_enqueue_operation(struct fscache_operation *);
68578@@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
68579 INIT_WORK(&op->work, fscache_op_work_func);
68580 atomic_set(&op->usage, 1);
68581 op->state = FSCACHE_OP_ST_INITIALISED;
68582- op->debug_id = atomic_inc_return(&fscache_op_debug_id);
68583+ op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
68584 op->processor = processor;
68585 op->release = release;
68586 INIT_LIST_HEAD(&op->pend_link);
68587diff --git a/include/linux/fscache.h b/include/linux/fscache.h
68588index 7a08623..4c07b0f 100644
68589--- a/include/linux/fscache.h
68590+++ b/include/linux/fscache.h
68591@@ -152,7 +152,7 @@ struct fscache_cookie_def {
68592 * - this is mandatory for any object that may have data
68593 */
68594 void (*now_uncached)(void *cookie_netfs_data);
68595-};
68596+} __do_const;
68597
68598 /*
68599 * fscache cached network filesystem type
68600diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
68601index a78680a..87bd73e 100644
68602--- a/include/linux/fsnotify.h
68603+++ b/include/linux/fsnotify.h
68604@@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
68605 struct inode *inode = path->dentry->d_inode;
68606 __u32 mask = FS_ACCESS;
68607
68608+ if (is_sidechannel_device(inode))
68609+ return;
68610+
68611 if (S_ISDIR(inode->i_mode))
68612 mask |= FS_ISDIR;
68613
68614@@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
68615 struct inode *inode = path->dentry->d_inode;
68616 __u32 mask = FS_MODIFY;
68617
68618+ if (is_sidechannel_device(inode))
68619+ return;
68620+
68621 if (S_ISDIR(inode->i_mode))
68622 mask |= FS_ISDIR;
68623
68624@@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
68625 */
68626 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
68627 {
68628- return kstrdup(name, GFP_KERNEL);
68629+ return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
68630 }
68631
68632 /*
68633diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
68634index 13a54d0..c6ce2a7 100644
68635--- a/include/linux/ftrace_event.h
68636+++ b/include/linux/ftrace_event.h
68637@@ -274,7 +274,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
68638 extern int trace_add_event_call(struct ftrace_event_call *call);
68639 extern void trace_remove_event_call(struct ftrace_event_call *call);
68640
68641-#define is_signed_type(type) (((type)(-1)) < (type)0)
68642+#define is_signed_type(type) (((type)(-1)) < (type)1)
68643
68644 int trace_set_clr_event(const char *system, const char *event, int set);
68645
68646diff --git a/include/linux/genhd.h b/include/linux/genhd.h
68647index 9f3c275..911b591 100644
68648--- a/include/linux/genhd.h
68649+++ b/include/linux/genhd.h
68650@@ -194,7 +194,7 @@ struct gendisk {
68651 struct kobject *slave_dir;
68652
68653 struct timer_rand_state *random;
68654- atomic_t sync_io; /* RAID */
68655+ atomic_unchecked_t sync_io; /* RAID */
68656 struct disk_events *ev;
68657 #ifdef CONFIG_BLK_DEV_INTEGRITY
68658 struct blk_integrity *integrity;
68659diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
68660index 023bc34..b02b46a 100644
68661--- a/include/linux/genl_magic_func.h
68662+++ b/include/linux/genl_magic_func.h
68663@@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
68664 },
68665
68666 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
68667-static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
68668+static struct genl_ops ZZZ_genl_ops[] = {
68669 #include GENL_MAGIC_INCLUDE_FILE
68670 };
68671
68672diff --git a/include/linux/gfp.h b/include/linux/gfp.h
68673index 0f615eb..5c3832f 100644
68674--- a/include/linux/gfp.h
68675+++ b/include/linux/gfp.h
68676@@ -35,6 +35,13 @@ struct vm_area_struct;
68677 #define ___GFP_NO_KSWAPD 0x400000u
68678 #define ___GFP_OTHER_NODE 0x800000u
68679 #define ___GFP_WRITE 0x1000000u
68680+
68681+#ifdef CONFIG_PAX_USERCOPY_SLABS
68682+#define ___GFP_USERCOPY 0x2000000u
68683+#else
68684+#define ___GFP_USERCOPY 0
68685+#endif
68686+
68687 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
68688
68689 /*
68690@@ -92,6 +99,7 @@ struct vm_area_struct;
68691 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
68692 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
68693 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
68694+#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
68695
68696 /*
68697 * This may seem redundant, but it's a way of annotating false positives vs.
68698@@ -99,7 +107,7 @@ struct vm_area_struct;
68699 */
68700 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
68701
68702-#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
68703+#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
68704 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
68705
68706 /* This equals 0, but use constants in case they ever change */
68707@@ -153,6 +161,8 @@ struct vm_area_struct;
68708 /* 4GB DMA on some platforms */
68709 #define GFP_DMA32 __GFP_DMA32
68710
68711+#define GFP_USERCOPY __GFP_USERCOPY
68712+
68713 /* Convert GFP flags to their corresponding migrate type */
68714 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
68715 {
68716diff --git a/include/linux/gracl.h b/include/linux/gracl.h
68717new file mode 100644
68718index 0000000..ebe6d72
68719--- /dev/null
68720+++ b/include/linux/gracl.h
68721@@ -0,0 +1,319 @@
68722+#ifndef GR_ACL_H
68723+#define GR_ACL_H
68724+
68725+#include <linux/grdefs.h>
68726+#include <linux/resource.h>
68727+#include <linux/capability.h>
68728+#include <linux/dcache.h>
68729+#include <asm/resource.h>
68730+
68731+/* Major status information */
68732+
68733+#define GR_VERSION "grsecurity 2.9.1"
68734+#define GRSECURITY_VERSION 0x2901
68735+
68736+enum {
68737+ GR_SHUTDOWN = 0,
68738+ GR_ENABLE = 1,
68739+ GR_SPROLE = 2,
68740+ GR_RELOAD = 3,
68741+ GR_SEGVMOD = 4,
68742+ GR_STATUS = 5,
68743+ GR_UNSPROLE = 6,
68744+ GR_PASSSET = 7,
68745+ GR_SPROLEPAM = 8,
68746+};
68747+
68748+/* Password setup definitions
68749+ * kernel/grhash.c */
68750+enum {
68751+ GR_PW_LEN = 128,
68752+ GR_SALT_LEN = 16,
68753+ GR_SHA_LEN = 32,
68754+};
68755+
68756+enum {
68757+ GR_SPROLE_LEN = 64,
68758+};
68759+
68760+enum {
68761+ GR_NO_GLOB = 0,
68762+ GR_REG_GLOB,
68763+ GR_CREATE_GLOB
68764+};
68765+
68766+#define GR_NLIMITS 32
68767+
68768+/* Begin Data Structures */
68769+
68770+struct sprole_pw {
68771+ unsigned char *rolename;
68772+ unsigned char salt[GR_SALT_LEN];
68773+ unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
68774+};
68775+
68776+struct name_entry {
68777+ __u32 key;
68778+ ino_t inode;
68779+ dev_t device;
68780+ char *name;
68781+ __u16 len;
68782+ __u8 deleted;
68783+ struct name_entry *prev;
68784+ struct name_entry *next;
68785+};
68786+
68787+struct inodev_entry {
68788+ struct name_entry *nentry;
68789+ struct inodev_entry *prev;
68790+ struct inodev_entry *next;
68791+};
68792+
68793+struct acl_role_db {
68794+ struct acl_role_label **r_hash;
68795+ __u32 r_size;
68796+};
68797+
68798+struct inodev_db {
68799+ struct inodev_entry **i_hash;
68800+ __u32 i_size;
68801+};
68802+
68803+struct name_db {
68804+ struct name_entry **n_hash;
68805+ __u32 n_size;
68806+};
68807+
68808+struct crash_uid {
68809+ uid_t uid;
68810+ unsigned long expires;
68811+};
68812+
68813+struct gr_hash_struct {
68814+ void **table;
68815+ void **nametable;
68816+ void *first;
68817+ __u32 table_size;
68818+ __u32 used_size;
68819+ int type;
68820+};
68821+
68822+/* Userspace Grsecurity ACL data structures */
68823+
68824+struct acl_subject_label {
68825+ char *filename;
68826+ ino_t inode;
68827+ dev_t device;
68828+ __u32 mode;
68829+ kernel_cap_t cap_mask;
68830+ kernel_cap_t cap_lower;
68831+ kernel_cap_t cap_invert_audit;
68832+
68833+ struct rlimit res[GR_NLIMITS];
68834+ __u32 resmask;
68835+
68836+ __u8 user_trans_type;
68837+ __u8 group_trans_type;
68838+ uid_t *user_transitions;
68839+ gid_t *group_transitions;
68840+ __u16 user_trans_num;
68841+ __u16 group_trans_num;
68842+
68843+ __u32 sock_families[2];
68844+ __u32 ip_proto[8];
68845+ __u32 ip_type;
68846+ struct acl_ip_label **ips;
68847+ __u32 ip_num;
68848+ __u32 inaddr_any_override;
68849+
68850+ __u32 crashes;
68851+ unsigned long expires;
68852+
68853+ struct acl_subject_label *parent_subject;
68854+ struct gr_hash_struct *hash;
68855+ struct acl_subject_label *prev;
68856+ struct acl_subject_label *next;
68857+
68858+ struct acl_object_label **obj_hash;
68859+ __u32 obj_hash_size;
68860+ __u16 pax_flags;
68861+};
68862+
68863+struct role_allowed_ip {
68864+ __u32 addr;
68865+ __u32 netmask;
68866+
68867+ struct role_allowed_ip *prev;
68868+ struct role_allowed_ip *next;
68869+};
68870+
68871+struct role_transition {
68872+ char *rolename;
68873+
68874+ struct role_transition *prev;
68875+ struct role_transition *next;
68876+};
68877+
68878+struct acl_role_label {
68879+ char *rolename;
68880+ uid_t uidgid;
68881+ __u16 roletype;
68882+
68883+ __u16 auth_attempts;
68884+ unsigned long expires;
68885+
68886+ struct acl_subject_label *root_label;
68887+ struct gr_hash_struct *hash;
68888+
68889+ struct acl_role_label *prev;
68890+ struct acl_role_label *next;
68891+
68892+ struct role_transition *transitions;
68893+ struct role_allowed_ip *allowed_ips;
68894+ uid_t *domain_children;
68895+ __u16 domain_child_num;
68896+
68897+ umode_t umask;
68898+
68899+ struct acl_subject_label **subj_hash;
68900+ __u32 subj_hash_size;
68901+};
68902+
68903+struct user_acl_role_db {
68904+ struct acl_role_label **r_table;
68905+ __u32 num_pointers; /* Number of allocations to track */
68906+ __u32 num_roles; /* Number of roles */
68907+ __u32 num_domain_children; /* Number of domain children */
68908+ __u32 num_subjects; /* Number of subjects */
68909+ __u32 num_objects; /* Number of objects */
68910+};
68911+
68912+struct acl_object_label {
68913+ char *filename;
68914+ ino_t inode;
68915+ dev_t device;
68916+ __u32 mode;
68917+
68918+ struct acl_subject_label *nested;
68919+ struct acl_object_label *globbed;
68920+
68921+ /* next two structures not used */
68922+
68923+ struct acl_object_label *prev;
68924+ struct acl_object_label *next;
68925+};
68926+
68927+struct acl_ip_label {
68928+ char *iface;
68929+ __u32 addr;
68930+ __u32 netmask;
68931+ __u16 low, high;
68932+ __u8 mode;
68933+ __u32 type;
68934+ __u32 proto[8];
68935+
68936+ /* next two structures not used */
68937+
68938+ struct acl_ip_label *prev;
68939+ struct acl_ip_label *next;
68940+};
68941+
68942+struct gr_arg {
68943+ struct user_acl_role_db role_db;
68944+ unsigned char pw[GR_PW_LEN];
68945+ unsigned char salt[GR_SALT_LEN];
68946+ unsigned char sum[GR_SHA_LEN];
68947+ unsigned char sp_role[GR_SPROLE_LEN];
68948+ struct sprole_pw *sprole_pws;
68949+ dev_t segv_device;
68950+ ino_t segv_inode;
68951+ uid_t segv_uid;
68952+ __u16 num_sprole_pws;
68953+ __u16 mode;
68954+};
68955+
68956+struct gr_arg_wrapper {
68957+ struct gr_arg *arg;
68958+ __u32 version;
68959+ __u32 size;
68960+};
68961+
68962+struct subject_map {
68963+ struct acl_subject_label *user;
68964+ struct acl_subject_label *kernel;
68965+ struct subject_map *prev;
68966+ struct subject_map *next;
68967+};
68968+
68969+struct acl_subj_map_db {
68970+ struct subject_map **s_hash;
68971+ __u32 s_size;
68972+};
68973+
68974+/* End Data Structures Section */
68975+
68976+/* Hash functions generated by empirical testing by Brad Spengler
68977+ Makes good use of the low bits of the inode. Generally 0-1 times
68978+ in loop for successful match. 0-3 for unsuccessful match.
68979+ Shift/add algorithm with modulus of table size and an XOR*/
68980+
68981+static __inline__ unsigned int
68982+gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
68983+{
68984+ return ((((uid + type) << (16 + type)) ^ uid) % sz);
68985+}
68986+
68987+ static __inline__ unsigned int
68988+gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
68989+{
68990+ return ((const unsigned long)userp % sz);
68991+}
68992+
68993+static __inline__ unsigned int
68994+gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
68995+{
68996+ return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
68997+}
68998+
68999+static __inline__ unsigned int
69000+gr_nhash(const char *name, const __u16 len, const unsigned int sz)
69001+{
69002+ return full_name_hash((const unsigned char *)name, len) % sz;
69003+}
69004+
69005+#define FOR_EACH_ROLE_START(role) \
69006+ role = role_list; \
69007+ while (role) {
69008+
69009+#define FOR_EACH_ROLE_END(role) \
69010+ role = role->prev; \
69011+ }
69012+
69013+#define FOR_EACH_SUBJECT_START(role,subj,iter) \
69014+ subj = NULL; \
69015+ iter = 0; \
69016+ while (iter < role->subj_hash_size) { \
69017+ if (subj == NULL) \
69018+ subj = role->subj_hash[iter]; \
69019+ if (subj == NULL) { \
69020+ iter++; \
69021+ continue; \
69022+ }
69023+
69024+#define FOR_EACH_SUBJECT_END(subj,iter) \
69025+ subj = subj->next; \
69026+ if (subj == NULL) \
69027+ iter++; \
69028+ }
69029+
69030+
69031+#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
69032+ subj = role->hash->first; \
69033+ while (subj != NULL) {
69034+
69035+#define FOR_EACH_NESTED_SUBJECT_END(subj) \
69036+ subj = subj->next; \
69037+ }
69038+
69039+#endif
69040+
69041diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
69042new file mode 100644
69043index 0000000..323ecf2
69044--- /dev/null
69045+++ b/include/linux/gralloc.h
69046@@ -0,0 +1,9 @@
69047+#ifndef __GRALLOC_H
69048+#define __GRALLOC_H
69049+
69050+void acl_free_all(void);
69051+int acl_alloc_stack_init(unsigned long size);
69052+void *acl_alloc(unsigned long len);
69053+void *acl_alloc_num(unsigned long num, unsigned long len);
69054+
69055+#endif
69056diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
69057new file mode 100644
69058index 0000000..be66033
69059--- /dev/null
69060+++ b/include/linux/grdefs.h
69061@@ -0,0 +1,140 @@
69062+#ifndef GRDEFS_H
69063+#define GRDEFS_H
69064+
69065+/* Begin grsecurity status declarations */
69066+
69067+enum {
69068+ GR_READY = 0x01,
69069+ GR_STATUS_INIT = 0x00 // disabled state
69070+};
69071+
69072+/* Begin ACL declarations */
69073+
69074+/* Role flags */
69075+
69076+enum {
69077+ GR_ROLE_USER = 0x0001,
69078+ GR_ROLE_GROUP = 0x0002,
69079+ GR_ROLE_DEFAULT = 0x0004,
69080+ GR_ROLE_SPECIAL = 0x0008,
69081+ GR_ROLE_AUTH = 0x0010,
69082+ GR_ROLE_NOPW = 0x0020,
69083+ GR_ROLE_GOD = 0x0040,
69084+ GR_ROLE_LEARN = 0x0080,
69085+ GR_ROLE_TPE = 0x0100,
69086+ GR_ROLE_DOMAIN = 0x0200,
69087+ GR_ROLE_PAM = 0x0400,
69088+ GR_ROLE_PERSIST = 0x0800
69089+};
69090+
69091+/* ACL Subject and Object mode flags */
69092+enum {
69093+ GR_DELETED = 0x80000000
69094+};
69095+
69096+/* ACL Object-only mode flags */
69097+enum {
69098+ GR_READ = 0x00000001,
69099+ GR_APPEND = 0x00000002,
69100+ GR_WRITE = 0x00000004,
69101+ GR_EXEC = 0x00000008,
69102+ GR_FIND = 0x00000010,
69103+ GR_INHERIT = 0x00000020,
69104+ GR_SETID = 0x00000040,
69105+ GR_CREATE = 0x00000080,
69106+ GR_DELETE = 0x00000100,
69107+ GR_LINK = 0x00000200,
69108+ GR_AUDIT_READ = 0x00000400,
69109+ GR_AUDIT_APPEND = 0x00000800,
69110+ GR_AUDIT_WRITE = 0x00001000,
69111+ GR_AUDIT_EXEC = 0x00002000,
69112+ GR_AUDIT_FIND = 0x00004000,
69113+ GR_AUDIT_INHERIT= 0x00008000,
69114+ GR_AUDIT_SETID = 0x00010000,
69115+ GR_AUDIT_CREATE = 0x00020000,
69116+ GR_AUDIT_DELETE = 0x00040000,
69117+ GR_AUDIT_LINK = 0x00080000,
69118+ GR_PTRACERD = 0x00100000,
69119+ GR_NOPTRACE = 0x00200000,
69120+ GR_SUPPRESS = 0x00400000,
69121+ GR_NOLEARN = 0x00800000,
69122+ GR_INIT_TRANSFER= 0x01000000
69123+};
69124+
69125+#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
69126+ GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
69127+ GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
69128+
69129+/* ACL subject-only mode flags */
69130+enum {
69131+ GR_KILL = 0x00000001,
69132+ GR_VIEW = 0x00000002,
69133+ GR_PROTECTED = 0x00000004,
69134+ GR_LEARN = 0x00000008,
69135+ GR_OVERRIDE = 0x00000010,
69136+ /* just a placeholder, this mode is only used in userspace */
69137+ GR_DUMMY = 0x00000020,
69138+ GR_PROTSHM = 0x00000040,
69139+ GR_KILLPROC = 0x00000080,
69140+ GR_KILLIPPROC = 0x00000100,
69141+ /* just a placeholder, this mode is only used in userspace */
69142+ GR_NOTROJAN = 0x00000200,
69143+ GR_PROTPROCFD = 0x00000400,
69144+ GR_PROCACCT = 0x00000800,
69145+ GR_RELAXPTRACE = 0x00001000,
69146+ //GR_NESTED = 0x00002000,
69147+ GR_INHERITLEARN = 0x00004000,
69148+ GR_PROCFIND = 0x00008000,
69149+ GR_POVERRIDE = 0x00010000,
69150+ GR_KERNELAUTH = 0x00020000,
69151+ GR_ATSECURE = 0x00040000,
69152+ GR_SHMEXEC = 0x00080000
69153+};
69154+
69155+enum {
69156+ GR_PAX_ENABLE_SEGMEXEC = 0x0001,
69157+ GR_PAX_ENABLE_PAGEEXEC = 0x0002,
69158+ GR_PAX_ENABLE_MPROTECT = 0x0004,
69159+ GR_PAX_ENABLE_RANDMMAP = 0x0008,
69160+ GR_PAX_ENABLE_EMUTRAMP = 0x0010,
69161+ GR_PAX_DISABLE_SEGMEXEC = 0x0100,
69162+ GR_PAX_DISABLE_PAGEEXEC = 0x0200,
69163+ GR_PAX_DISABLE_MPROTECT = 0x0400,
69164+ GR_PAX_DISABLE_RANDMMAP = 0x0800,
69165+ GR_PAX_DISABLE_EMUTRAMP = 0x1000,
69166+};
69167+
69168+enum {
69169+ GR_ID_USER = 0x01,
69170+ GR_ID_GROUP = 0x02,
69171+};
69172+
69173+enum {
69174+ GR_ID_ALLOW = 0x01,
69175+ GR_ID_DENY = 0x02,
69176+};
69177+
69178+#define GR_CRASH_RES 31
69179+#define GR_UIDTABLE_MAX 500
69180+
69181+/* begin resource learning section */
69182+enum {
69183+ GR_RLIM_CPU_BUMP = 60,
69184+ GR_RLIM_FSIZE_BUMP = 50000,
69185+ GR_RLIM_DATA_BUMP = 10000,
69186+ GR_RLIM_STACK_BUMP = 1000,
69187+ GR_RLIM_CORE_BUMP = 10000,
69188+ GR_RLIM_RSS_BUMP = 500000,
69189+ GR_RLIM_NPROC_BUMP = 1,
69190+ GR_RLIM_NOFILE_BUMP = 5,
69191+ GR_RLIM_MEMLOCK_BUMP = 50000,
69192+ GR_RLIM_AS_BUMP = 500000,
69193+ GR_RLIM_LOCKS_BUMP = 2,
69194+ GR_RLIM_SIGPENDING_BUMP = 5,
69195+ GR_RLIM_MSGQUEUE_BUMP = 10000,
69196+ GR_RLIM_NICE_BUMP = 1,
69197+ GR_RLIM_RTPRIO_BUMP = 1,
69198+ GR_RLIM_RTTIME_BUMP = 1000000
69199+};
69200+
69201+#endif
69202diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
69203new file mode 100644
69204index 0000000..5402bce
69205--- /dev/null
69206+++ b/include/linux/grinternal.h
69207@@ -0,0 +1,215 @@
69208+#ifndef __GRINTERNAL_H
69209+#define __GRINTERNAL_H
69210+
69211+#ifdef CONFIG_GRKERNSEC
69212+
69213+#include <linux/fs.h>
69214+#include <linux/mnt_namespace.h>
69215+#include <linux/nsproxy.h>
69216+#include <linux/gracl.h>
69217+#include <linux/grdefs.h>
69218+#include <linux/grmsg.h>
69219+
69220+void gr_add_learn_entry(const char *fmt, ...)
69221+ __attribute__ ((format (printf, 1, 2)));
69222+__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
69223+ const struct vfsmount *mnt);
69224+__u32 gr_check_create(const struct dentry *new_dentry,
69225+ const struct dentry *parent,
69226+ const struct vfsmount *mnt, const __u32 mode);
69227+int gr_check_protected_task(const struct task_struct *task);
69228+__u32 to_gr_audit(const __u32 reqmode);
69229+int gr_set_acls(const int type);
69230+int gr_apply_subject_to_task(struct task_struct *task);
69231+int gr_acl_is_enabled(void);
69232+char gr_roletype_to_char(void);
69233+
69234+void gr_handle_alertkill(struct task_struct *task);
69235+char *gr_to_filename(const struct dentry *dentry,
69236+ const struct vfsmount *mnt);
69237+char *gr_to_filename1(const struct dentry *dentry,
69238+ const struct vfsmount *mnt);
69239+char *gr_to_filename2(const struct dentry *dentry,
69240+ const struct vfsmount *mnt);
69241+char *gr_to_filename3(const struct dentry *dentry,
69242+ const struct vfsmount *mnt);
69243+
69244+extern int grsec_enable_ptrace_readexec;
69245+extern int grsec_enable_harden_ptrace;
69246+extern int grsec_enable_link;
69247+extern int grsec_enable_fifo;
69248+extern int grsec_enable_execve;
69249+extern int grsec_enable_shm;
69250+extern int grsec_enable_execlog;
69251+extern int grsec_enable_signal;
69252+extern int grsec_enable_audit_ptrace;
69253+extern int grsec_enable_forkfail;
69254+extern int grsec_enable_time;
69255+extern int grsec_enable_rofs;
69256+extern int grsec_enable_chroot_shmat;
69257+extern int grsec_enable_chroot_mount;
69258+extern int grsec_enable_chroot_double;
69259+extern int grsec_enable_chroot_pivot;
69260+extern int grsec_enable_chroot_chdir;
69261+extern int grsec_enable_chroot_chmod;
69262+extern int grsec_enable_chroot_mknod;
69263+extern int grsec_enable_chroot_fchdir;
69264+extern int grsec_enable_chroot_nice;
69265+extern int grsec_enable_chroot_execlog;
69266+extern int grsec_enable_chroot_caps;
69267+extern int grsec_enable_chroot_sysctl;
69268+extern int grsec_enable_chroot_unix;
69269+extern int grsec_enable_symlinkown;
69270+extern kgid_t grsec_symlinkown_gid;
69271+extern int grsec_enable_tpe;
69272+extern kgid_t grsec_tpe_gid;
69273+extern int grsec_enable_tpe_all;
69274+extern int grsec_enable_tpe_invert;
69275+extern int grsec_enable_socket_all;
69276+extern kgid_t grsec_socket_all_gid;
69277+extern int grsec_enable_socket_client;
69278+extern kgid_t grsec_socket_client_gid;
69279+extern int grsec_enable_socket_server;
69280+extern kgid_t grsec_socket_server_gid;
69281+extern kgid_t grsec_audit_gid;
69282+extern int grsec_enable_group;
69283+extern int grsec_enable_audit_textrel;
69284+extern int grsec_enable_log_rwxmaps;
69285+extern int grsec_enable_mount;
69286+extern int grsec_enable_chdir;
69287+extern int grsec_resource_logging;
69288+extern int grsec_enable_blackhole;
69289+extern int grsec_lastack_retries;
69290+extern int grsec_enable_brute;
69291+extern int grsec_lock;
69292+
69293+extern spinlock_t grsec_alert_lock;
69294+extern unsigned long grsec_alert_wtime;
69295+extern unsigned long grsec_alert_fyet;
69296+
69297+extern spinlock_t grsec_audit_lock;
69298+
69299+extern rwlock_t grsec_exec_file_lock;
69300+
69301+#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
69302+ gr_to_filename2((tsk)->exec_file->f_path.dentry, \
69303+ (tsk)->exec_file->f_path.mnt) : "/")
69304+
69305+#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
69306+ gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
69307+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69308+
69309+#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
69310+ gr_to_filename((tsk)->exec_file->f_path.dentry, \
69311+ (tsk)->exec_file->f_path.mnt) : "/")
69312+
69313+#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
69314+ gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
69315+ (tsk)->real_parent->exec_file->f_path.mnt) : "/")
69316+
69317+#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
69318+
69319+#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
69320+
69321+#define GR_CHROOT_CAPS {{ \
69322+ CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
69323+ CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
69324+ CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
69325+ CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
69326+ CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
69327+ CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
69328+ CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
69329+
69330+#define security_learn(normal_msg,args...) \
69331+({ \
69332+ read_lock(&grsec_exec_file_lock); \
69333+ gr_add_learn_entry(normal_msg "\n", ## args); \
69334+ read_unlock(&grsec_exec_file_lock); \
69335+})
69336+
69337+enum {
69338+ GR_DO_AUDIT,
69339+ GR_DONT_AUDIT,
69340+ /* used for non-audit messages that we shouldn't kill the task on */
69341+ GR_DONT_AUDIT_GOOD
69342+};
69343+
69344+enum {
69345+ GR_TTYSNIFF,
69346+ GR_RBAC,
69347+ GR_RBAC_STR,
69348+ GR_STR_RBAC,
69349+ GR_RBAC_MODE2,
69350+ GR_RBAC_MODE3,
69351+ GR_FILENAME,
69352+ GR_SYSCTL_HIDDEN,
69353+ GR_NOARGS,
69354+ GR_ONE_INT,
69355+ GR_ONE_INT_TWO_STR,
69356+ GR_ONE_STR,
69357+ GR_STR_INT,
69358+ GR_TWO_STR_INT,
69359+ GR_TWO_INT,
69360+ GR_TWO_U64,
69361+ GR_THREE_INT,
69362+ GR_FIVE_INT_TWO_STR,
69363+ GR_TWO_STR,
69364+ GR_THREE_STR,
69365+ GR_FOUR_STR,
69366+ GR_STR_FILENAME,
69367+ GR_FILENAME_STR,
69368+ GR_FILENAME_TWO_INT,
69369+ GR_FILENAME_TWO_INT_STR,
69370+ GR_TEXTREL,
69371+ GR_PTRACE,
69372+ GR_RESOURCE,
69373+ GR_CAP,
69374+ GR_SIG,
69375+ GR_SIG2,
69376+ GR_CRASH1,
69377+ GR_CRASH2,
69378+ GR_PSACCT,
69379+ GR_RWXMAP
69380+};
69381+
69382+#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
69383+#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
69384+#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
69385+#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
69386+#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
69387+#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
69388+#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)
69389+#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
69390+#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
69391+#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
69392+#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
69393+#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
69394+#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
69395+#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
69396+#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
69397+#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
69398+#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)
69399+#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
69400+#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
69401+#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
69402+#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
69403+#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
69404+#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
69405+#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
69406+#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)
69407+#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
69408+#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
69409+#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
69410+#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
69411+#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
69412+#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
69413+#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
69414+#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
69415+#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)
69416+#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
69417+
69418+void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
69419+
69420+#endif
69421+
69422+#endif
69423diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
69424new file mode 100644
69425index 0000000..2bd4c8d
69426--- /dev/null
69427+++ b/include/linux/grmsg.h
69428@@ -0,0 +1,111 @@
69429+#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"
69430+#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"
69431+#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
69432+#define GR_STOPMOD_MSG "denied modification of module state by "
69433+#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
69434+#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
69435+#define GR_IOPERM_MSG "denied use of ioperm() by "
69436+#define GR_IOPL_MSG "denied use of iopl() by "
69437+#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
69438+#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
69439+#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
69440+#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
69441+#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
69442+#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"
69443+#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"
69444+#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
69445+#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
69446+#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
69447+#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
69448+#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
69449+#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
69450+#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
69451+#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
69452+#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
69453+#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
69454+#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
69455+#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
69456+#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
69457+#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
69458+#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
69459+#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
69460+#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
69461+#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
69462+#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
69463+#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
69464+#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
69465+#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
69466+#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
69467+#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
69468+#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
69469+#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
69470+#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
69471+#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
69472+#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
69473+#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
69474+#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
69475+#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
69476+#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
69477+#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
69478+#define GR_INITF_ACL_MSG "init_variables() failed %s by "
69479+#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"
69480+#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
69481+#define GR_SHUTS_ACL_MSG "shutdown auth success for "
69482+#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
69483+#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
69484+#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
69485+#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
69486+#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
69487+#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
69488+#define GR_ENABLEF_ACL_MSG "unable to load %s for "
69489+#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
69490+#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
69491+#define GR_RELOADF_ACL_MSG "failed reload of %s for "
69492+#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
69493+#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
69494+#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
69495+#define GR_SPROLEF_ACL_MSG "special role %s failure for "
69496+#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
69497+#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
69498+#define GR_INVMODE_ACL_MSG "invalid mode %d by "
69499+#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
69500+#define GR_FAILFORK_MSG "failed fork with errno %s by "
69501+#define GR_NICE_CHROOT_MSG "denied priority change by "
69502+#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
69503+#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
69504+#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
69505+#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
69506+#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
69507+#define GR_TIME_MSG "time set by "
69508+#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
69509+#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
69510+#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
69511+#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
69512+#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
69513+#define GR_BIND_MSG "denied bind() by "
69514+#define GR_CONNECT_MSG "denied connect() by "
69515+#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
69516+#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
69517+#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"
69518+#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
69519+#define GR_CAP_ACL_MSG "use of %s denied for "
69520+#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
69521+#define GR_CAP_ACL_MSG2 "use of %s permitted for "
69522+#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
69523+#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
69524+#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
69525+#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
69526+#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
69527+#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
69528+#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
69529+#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
69530+#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
69531+#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
69532+#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
69533+#define GR_VM86_MSG "denied use of vm86 by "
69534+#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
69535+#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
69536+#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
69537+#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
69538+#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
69539+#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 "
69540diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
69541new file mode 100644
69542index 0000000..d7ef0ac
69543--- /dev/null
69544+++ b/include/linux/grsecurity.h
69545@@ -0,0 +1,242 @@
69546+#ifndef GR_SECURITY_H
69547+#define GR_SECURITY_H
69548+#include <linux/fs.h>
69549+#include <linux/fs_struct.h>
69550+#include <linux/binfmts.h>
69551+#include <linux/gracl.h>
69552+
69553+/* notify of brain-dead configs */
69554+#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69555+#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
69556+#endif
69557+#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
69558+#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
69559+#endif
69560+#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
69561+#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
69562+#endif
69563+#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
69564+#error "CONFIG_PAX enabled, but no PaX options are enabled."
69565+#endif
69566+
69567+void gr_handle_brute_attach(unsigned long mm_flags);
69568+void gr_handle_brute_check(void);
69569+void gr_handle_kernel_exploit(void);
69570+int gr_process_user_ban(void);
69571+
69572+char gr_roletype_to_char(void);
69573+
69574+int gr_acl_enable_at_secure(void);
69575+
69576+int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
69577+int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
69578+
69579+void gr_del_task_from_ip_table(struct task_struct *p);
69580+
69581+int gr_pid_is_chrooted(struct task_struct *p);
69582+int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
69583+int gr_handle_chroot_nice(void);
69584+int gr_handle_chroot_sysctl(const int op);
69585+int gr_handle_chroot_setpriority(struct task_struct *p,
69586+ const int niceval);
69587+int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
69588+int gr_handle_chroot_chroot(const struct dentry *dentry,
69589+ const struct vfsmount *mnt);
69590+void gr_handle_chroot_chdir(const struct path *path);
69591+int gr_handle_chroot_chmod(const struct dentry *dentry,
69592+ const struct vfsmount *mnt, const int mode);
69593+int gr_handle_chroot_mknod(const struct dentry *dentry,
69594+ const struct vfsmount *mnt, const int mode);
69595+int gr_handle_chroot_mount(const struct dentry *dentry,
69596+ const struct vfsmount *mnt,
69597+ const char *dev_name);
69598+int gr_handle_chroot_pivot(void);
69599+int gr_handle_chroot_unix(const pid_t pid);
69600+
69601+int gr_handle_rawio(const struct inode *inode);
69602+
69603+void gr_handle_ioperm(void);
69604+void gr_handle_iopl(void);
69605+
69606+umode_t gr_acl_umask(void);
69607+
69608+int gr_tpe_allow(const struct file *file);
69609+
69610+void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
69611+void gr_clear_chroot_entries(struct task_struct *task);
69612+
69613+void gr_log_forkfail(const int retval);
69614+void gr_log_timechange(void);
69615+void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
69616+void gr_log_chdir(const struct dentry *dentry,
69617+ const struct vfsmount *mnt);
69618+void gr_log_chroot_exec(const struct dentry *dentry,
69619+ const struct vfsmount *mnt);
69620+void gr_log_remount(const char *devname, const int retval);
69621+void gr_log_unmount(const char *devname, const int retval);
69622+void gr_log_mount(const char *from, const char *to, const int retval);
69623+void gr_log_textrel(struct vm_area_struct *vma);
69624+void gr_log_rwxmmap(struct file *file);
69625+void gr_log_rwxmprotect(struct file *file);
69626+
69627+int gr_handle_follow_link(const struct inode *parent,
69628+ const struct inode *inode,
69629+ const struct dentry *dentry,
69630+ const struct vfsmount *mnt);
69631+int gr_handle_fifo(const struct dentry *dentry,
69632+ const struct vfsmount *mnt,
69633+ const struct dentry *dir, const int flag,
69634+ const int acc_mode);
69635+int gr_handle_hardlink(const struct dentry *dentry,
69636+ const struct vfsmount *mnt,
69637+ struct inode *inode,
69638+ const int mode, const struct filename *to);
69639+
69640+int gr_is_capable(const int cap);
69641+int gr_is_capable_nolog(const int cap);
69642+int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
69643+int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
69644+
69645+void gr_copy_label(struct task_struct *tsk);
69646+void gr_handle_crash(struct task_struct *task, const int sig);
69647+int gr_handle_signal(const struct task_struct *p, const int sig);
69648+int gr_check_crash_uid(const kuid_t uid);
69649+int gr_check_protected_task(const struct task_struct *task);
69650+int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
69651+int gr_acl_handle_mmap(const struct file *file,
69652+ const unsigned long prot);
69653+int gr_acl_handle_mprotect(const struct file *file,
69654+ const unsigned long prot);
69655+int gr_check_hidden_task(const struct task_struct *tsk);
69656+__u32 gr_acl_handle_truncate(const struct dentry *dentry,
69657+ const struct vfsmount *mnt);
69658+__u32 gr_acl_handle_utime(const struct dentry *dentry,
69659+ const struct vfsmount *mnt);
69660+__u32 gr_acl_handle_access(const struct dentry *dentry,
69661+ const struct vfsmount *mnt, const int fmode);
69662+__u32 gr_acl_handle_chmod(const struct dentry *dentry,
69663+ const struct vfsmount *mnt, umode_t *mode);
69664+__u32 gr_acl_handle_chown(const struct dentry *dentry,
69665+ const struct vfsmount *mnt);
69666+__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
69667+ const struct vfsmount *mnt);
69668+int gr_handle_ptrace(struct task_struct *task, const long request);
69669+int gr_handle_proc_ptrace(struct task_struct *task);
69670+__u32 gr_acl_handle_execve(const struct dentry *dentry,
69671+ const struct vfsmount *mnt);
69672+int gr_check_crash_exec(const struct file *filp);
69673+int gr_acl_is_enabled(void);
69674+void gr_set_kernel_label(struct task_struct *task);
69675+void gr_set_role_label(struct task_struct *task, const kuid_t uid,
69676+ const kgid_t gid);
69677+int gr_set_proc_label(const struct dentry *dentry,
69678+ const struct vfsmount *mnt,
69679+ const int unsafe_flags);
69680+__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
69681+ const struct vfsmount *mnt);
69682+__u32 gr_acl_handle_open(const struct dentry *dentry,
69683+ const struct vfsmount *mnt, int acc_mode);
69684+__u32 gr_acl_handle_creat(const struct dentry *dentry,
69685+ const struct dentry *p_dentry,
69686+ const struct vfsmount *p_mnt,
69687+ int open_flags, int acc_mode, const int imode);
69688+void gr_handle_create(const struct dentry *dentry,
69689+ const struct vfsmount *mnt);
69690+void gr_handle_proc_create(const struct dentry *dentry,
69691+ const struct inode *inode);
69692+__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
69693+ const struct dentry *parent_dentry,
69694+ const struct vfsmount *parent_mnt,
69695+ const int mode);
69696+__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
69697+ const struct dentry *parent_dentry,
69698+ const struct vfsmount *parent_mnt);
69699+__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
69700+ const struct vfsmount *mnt);
69701+void gr_handle_delete(const ino_t ino, const dev_t dev);
69702+__u32 gr_acl_handle_unlink(const struct dentry *dentry,
69703+ const struct vfsmount *mnt);
69704+__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
69705+ const struct dentry *parent_dentry,
69706+ const struct vfsmount *parent_mnt,
69707+ const struct filename *from);
69708+__u32 gr_acl_handle_link(const struct dentry *new_dentry,
69709+ const struct dentry *parent_dentry,
69710+ const struct vfsmount *parent_mnt,
69711+ const struct dentry *old_dentry,
69712+ const struct vfsmount *old_mnt, const struct filename *to);
69713+int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
69714+int gr_acl_handle_rename(struct dentry *new_dentry,
69715+ struct dentry *parent_dentry,
69716+ const struct vfsmount *parent_mnt,
69717+ struct dentry *old_dentry,
69718+ struct inode *old_parent_inode,
69719+ struct vfsmount *old_mnt, const struct filename *newname);
69720+void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69721+ struct dentry *old_dentry,
69722+ struct dentry *new_dentry,
69723+ struct vfsmount *mnt, const __u8 replace);
69724+__u32 gr_check_link(const struct dentry *new_dentry,
69725+ const struct dentry *parent_dentry,
69726+ const struct vfsmount *parent_mnt,
69727+ const struct dentry *old_dentry,
69728+ const struct vfsmount *old_mnt);
69729+int gr_acl_handle_filldir(const struct file *file, const char *name,
69730+ const unsigned int namelen, const ino_t ino);
69731+
69732+__u32 gr_acl_handle_unix(const struct dentry *dentry,
69733+ const struct vfsmount *mnt);
69734+void gr_acl_handle_exit(void);
69735+void gr_acl_handle_psacct(struct task_struct *task, const long code);
69736+int gr_acl_handle_procpidmem(const struct task_struct *task);
69737+int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
69738+int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
69739+void gr_audit_ptrace(struct task_struct *task);
69740+dev_t gr_get_dev_from_dentry(struct dentry *dentry);
69741+void gr_put_exec_file(struct task_struct *task);
69742+
69743+int gr_ptrace_readexec(struct file *file, int unsafe_flags);
69744+
69745+#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
69746+extern void gr_learn_resource(const struct task_struct *task, const int res,
69747+ const unsigned long wanted, const int gt);
69748+#else
69749+static inline void gr_learn_resource(const struct task_struct *task, const int res,
69750+ const unsigned long wanted, const int gt)
69751+{
69752+}
69753+#endif
69754+
69755+#ifdef CONFIG_GRKERNSEC_RESLOG
69756+extern void gr_log_resource(const struct task_struct *task, const int res,
69757+ const unsigned long wanted, const int gt);
69758+#else
69759+static inline void gr_log_resource(const struct task_struct *task, const int res,
69760+ const unsigned long wanted, const int gt)
69761+{
69762+}
69763+#endif
69764+
69765+#ifdef CONFIG_GRKERNSEC
69766+void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
69767+void gr_handle_vm86(void);
69768+void gr_handle_mem_readwrite(u64 from, u64 to);
69769+
69770+void gr_log_badprocpid(const char *entry);
69771+
69772+extern int grsec_enable_dmesg;
69773+extern int grsec_disable_privio;
69774+
69775+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
69776+extern kgid_t grsec_proc_gid;
69777+#endif
69778+
69779+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
69780+extern int grsec_enable_chroot_findtask;
69781+#endif
69782+#ifdef CONFIG_GRKERNSEC_SETXID
69783+extern int grsec_enable_setxid;
69784+#endif
69785+#endif
69786+
69787+#endif
69788diff --git a/include/linux/grsock.h b/include/linux/grsock.h
69789new file mode 100644
69790index 0000000..e7ffaaf
69791--- /dev/null
69792+++ b/include/linux/grsock.h
69793@@ -0,0 +1,19 @@
69794+#ifndef __GRSOCK_H
69795+#define __GRSOCK_H
69796+
69797+extern void gr_attach_curr_ip(const struct sock *sk);
69798+extern int gr_handle_sock_all(const int family, const int type,
69799+ const int protocol);
69800+extern int gr_handle_sock_server(const struct sockaddr *sck);
69801+extern int gr_handle_sock_server_other(const struct sock *sck);
69802+extern int gr_handle_sock_client(const struct sockaddr *sck);
69803+extern int gr_search_connect(struct socket * sock,
69804+ struct sockaddr_in * addr);
69805+extern int gr_search_bind(struct socket * sock,
69806+ struct sockaddr_in * addr);
69807+extern int gr_search_listen(struct socket * sock);
69808+extern int gr_search_accept(struct socket * sock);
69809+extern int gr_search_socket(const int domain, const int type,
69810+ const int protocol);
69811+
69812+#endif
69813diff --git a/include/linux/highmem.h b/include/linux/highmem.h
69814index 7fb31da..08b5114 100644
69815--- a/include/linux/highmem.h
69816+++ b/include/linux/highmem.h
69817@@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
69818 kunmap_atomic(kaddr);
69819 }
69820
69821+static inline void sanitize_highpage(struct page *page)
69822+{
69823+ void *kaddr;
69824+ unsigned long flags;
69825+
69826+ local_irq_save(flags);
69827+ kaddr = kmap_atomic(page);
69828+ clear_page(kaddr);
69829+ kunmap_atomic(kaddr);
69830+ local_irq_restore(flags);
69831+}
69832+
69833 static inline void zero_user_segments(struct page *page,
69834 unsigned start1, unsigned end1,
69835 unsigned start2, unsigned end2)
69836diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
69837index 1c7b89a..7f52502 100644
69838--- a/include/linux/hwmon-sysfs.h
69839+++ b/include/linux/hwmon-sysfs.h
69840@@ -25,7 +25,8 @@
69841 struct sensor_device_attribute{
69842 struct device_attribute dev_attr;
69843 int index;
69844-};
69845+} __do_const;
69846+typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
69847 #define to_sensor_dev_attr(_dev_attr) \
69848 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
69849
69850@@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
69851 struct device_attribute dev_attr;
69852 u8 index;
69853 u8 nr;
69854-};
69855+} __do_const;
69856 #define to_sensor_dev_attr_2(_dev_attr) \
69857 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
69858
69859diff --git a/include/linux/i2c.h b/include/linux/i2c.h
69860index d0c4db7..61b3577 100644
69861--- a/include/linux/i2c.h
69862+++ b/include/linux/i2c.h
69863@@ -369,6 +369,7 @@ struct i2c_algorithm {
69864 /* To determine what the adapter supports */
69865 u32 (*functionality) (struct i2c_adapter *);
69866 };
69867+typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
69868
69869 /*
69870 * i2c_adapter is the structure used to identify a physical i2c bus along
69871diff --git a/include/linux/i2o.h b/include/linux/i2o.h
69872index d23c3c2..eb63c81 100644
69873--- a/include/linux/i2o.h
69874+++ b/include/linux/i2o.h
69875@@ -565,7 +565,7 @@ struct i2o_controller {
69876 struct i2o_device *exec; /* Executive */
69877 #if BITS_PER_LONG == 64
69878 spinlock_t context_list_lock; /* lock for context_list */
69879- atomic_t context_list_counter; /* needed for unique contexts */
69880+ atomic_unchecked_t context_list_counter; /* needed for unique contexts */
69881 struct list_head context_list; /* list of context id's
69882 and pointers */
69883 #endif
69884diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
69885index aff7ad8..3942bbd 100644
69886--- a/include/linux/if_pppox.h
69887+++ b/include/linux/if_pppox.h
69888@@ -76,7 +76,7 @@ struct pppox_proto {
69889 int (*ioctl)(struct socket *sock, unsigned int cmd,
69890 unsigned long arg);
69891 struct module *owner;
69892-};
69893+} __do_const;
69894
69895 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
69896 extern void unregister_pppox_proto(int proto_num);
69897diff --git a/include/linux/init.h b/include/linux/init.h
69898index 8618147..0821126 100644
69899--- a/include/linux/init.h
69900+++ b/include/linux/init.h
69901@@ -39,9 +39,36 @@
69902 * Also note, that this data cannot be "const".
69903 */
69904
69905+#ifdef MODULE
69906+#define add_init_latent_entropy
69907+#define add_devinit_latent_entropy
69908+#define add_cpuinit_latent_entropy
69909+#define add_meminit_latent_entropy
69910+#else
69911+#define add_init_latent_entropy __latent_entropy
69912+
69913+#ifdef CONFIG_HOTPLUG
69914+#define add_devinit_latent_entropy
69915+#else
69916+#define add_devinit_latent_entropy __latent_entropy
69917+#endif
69918+
69919+#ifdef CONFIG_HOTPLUG_CPU
69920+#define add_cpuinit_latent_entropy
69921+#else
69922+#define add_cpuinit_latent_entropy __latent_entropy
69923+#endif
69924+
69925+#ifdef CONFIG_MEMORY_HOTPLUG
69926+#define add_meminit_latent_entropy
69927+#else
69928+#define add_meminit_latent_entropy __latent_entropy
69929+#endif
69930+#endif
69931+
69932 /* These are for everybody (although not all archs will actually
69933 discard it in modules) */
69934-#define __init __section(.init.text) __cold notrace
69935+#define __init __section(.init.text) __cold notrace add_init_latent_entropy
69936 #define __initdata __section(.init.data)
69937 #define __initconst __constsection(.init.rodata)
69938 #define __exitdata __section(.exit.data)
69939@@ -94,7 +121,7 @@
69940 #define __exit __section(.exit.text) __exitused __cold notrace
69941
69942 /* Used for HOTPLUG_CPU */
69943-#define __cpuinit __section(.cpuinit.text) __cold notrace
69944+#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
69945 #define __cpuinitdata __section(.cpuinit.data)
69946 #define __cpuinitconst __constsection(.cpuinit.rodata)
69947 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
69948@@ -102,7 +129,7 @@
69949 #define __cpuexitconst __constsection(.cpuexit.rodata)
69950
69951 /* Used for MEMORY_HOTPLUG */
69952-#define __meminit __section(.meminit.text) __cold notrace
69953+#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
69954 #define __meminitdata __section(.meminit.data)
69955 #define __meminitconst __constsection(.meminit.rodata)
69956 #define __memexit __section(.memexit.text) __exitused __cold notrace
69957diff --git a/include/linux/init_task.h b/include/linux/init_task.h
69958index 5cd0f09..c9f67cc 100644
69959--- a/include/linux/init_task.h
69960+++ b/include/linux/init_task.h
69961@@ -154,6 +154,12 @@ extern struct task_group root_task_group;
69962
69963 #define INIT_TASK_COMM "swapper"
69964
69965+#ifdef CONFIG_X86
69966+#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
69967+#else
69968+#define INIT_TASK_THREAD_INFO
69969+#endif
69970+
69971 /*
69972 * INIT_TASK is used to set up the first task table, touch at
69973 * your own risk!. Base=0, limit=0x1fffff (=2MB)
69974@@ -193,6 +199,7 @@ extern struct task_group root_task_group;
69975 RCU_POINTER_INITIALIZER(cred, &init_cred), \
69976 .comm = INIT_TASK_COMM, \
69977 .thread = INIT_THREAD, \
69978+ INIT_TASK_THREAD_INFO \
69979 .fs = &init_fs, \
69980 .files = &init_files, \
69981 .signal = &init_signals, \
69982diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
69983index 5fa5afe..ac55b25 100644
69984--- a/include/linux/interrupt.h
69985+++ b/include/linux/interrupt.h
69986@@ -430,7 +430,7 @@ enum
69987 /* map softirq index to softirq name. update 'softirq_to_name' in
69988 * kernel/softirq.c when adding a new softirq.
69989 */
69990-extern char *softirq_to_name[NR_SOFTIRQS];
69991+extern const char * const softirq_to_name[NR_SOFTIRQS];
69992
69993 /* softirq mask and active fields moved to irq_cpustat_t in
69994 * asm/hardirq.h to get better cache usage. KAO
69995@@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
69996
69997 struct softirq_action
69998 {
69999- void (*action)(struct softirq_action *);
70000-};
70001+ void (*action)(void);
70002+} __no_const;
70003
70004 asmlinkage void do_softirq(void);
70005 asmlinkage void __do_softirq(void);
70006-extern void open_softirq(int nr, void (*action)(struct softirq_action *));
70007+extern void open_softirq(int nr, void (*action)(void));
70008 extern void softirq_init(void);
70009 extern void __raise_softirq_irqoff(unsigned int nr);
70010
70011diff --git a/include/linux/iommu.h b/include/linux/iommu.h
70012index ba3b8a9..7e14ed8 100644
70013--- a/include/linux/iommu.h
70014+++ b/include/linux/iommu.h
70015@@ -113,7 +113,7 @@ struct iommu_ops {
70016 u32 (*domain_get_windows)(struct iommu_domain *domain);
70017
70018 unsigned long pgsize_bitmap;
70019-};
70020+} __do_const;
70021
70022 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
70023 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
70024diff --git a/include/linux/ioport.h b/include/linux/ioport.h
70025index 85ac9b9b..e5759ab 100644
70026--- a/include/linux/ioport.h
70027+++ b/include/linux/ioport.h
70028@@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
70029 int adjust_resource(struct resource *res, resource_size_t start,
70030 resource_size_t size);
70031 resource_size_t resource_alignment(struct resource *res);
70032-static inline resource_size_t resource_size(const struct resource *res)
70033+static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
70034 {
70035 return res->end - res->start + 1;
70036 }
70037diff --git a/include/linux/irq.h b/include/linux/irq.h
70038index bc4e066..50468a9 100644
70039--- a/include/linux/irq.h
70040+++ b/include/linux/irq.h
70041@@ -328,7 +328,8 @@ struct irq_chip {
70042 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
70043
70044 unsigned long flags;
70045-};
70046+} __do_const;
70047+typedef struct irq_chip __no_const irq_chip_no_const;
70048
70049 /*
70050 * irq_chip specific flags
70051diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
70052index 3fd8e42..a73e966 100644
70053--- a/include/linux/irqchip/arm-gic.h
70054+++ b/include/linux/irqchip/arm-gic.h
70055@@ -59,9 +59,11 @@
70056
70057 #ifndef __ASSEMBLY__
70058
70059+#include <linux/irq.h>
70060+
70061 struct device_node;
70062
70063-extern struct irq_chip gic_arch_extn;
70064+extern irq_chip_no_const gic_arch_extn;
70065
70066 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
70067 u32 offset, struct device_node *);
70068diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
70069index 6883e19..06992b1 100644
70070--- a/include/linux/kallsyms.h
70071+++ b/include/linux/kallsyms.h
70072@@ -15,7 +15,8 @@
70073
70074 struct module;
70075
70076-#ifdef CONFIG_KALLSYMS
70077+#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
70078+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
70079 /* Lookup the address for a symbol. Returns 0 if not found. */
70080 unsigned long kallsyms_lookup_name(const char *name);
70081
70082@@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
70083 /* Stupid that this does nothing, but I didn't create this mess. */
70084 #define __print_symbol(fmt, addr)
70085 #endif /*CONFIG_KALLSYMS*/
70086+#else /* when included by kallsyms.c, vsnprintf.c, or
70087+ arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
70088+extern void __print_symbol(const char *fmt, unsigned long address);
70089+extern int sprint_backtrace(char *buffer, unsigned long address);
70090+extern int sprint_symbol(char *buffer, unsigned long address);
70091+extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
70092+const char *kallsyms_lookup(unsigned long addr,
70093+ unsigned long *symbolsize,
70094+ unsigned long *offset,
70095+ char **modname, char *namebuf);
70096+#endif
70097
70098 /* This macro allows us to keep printk typechecking */
70099 static __printf(1, 2)
70100diff --git a/include/linux/key-type.h b/include/linux/key-type.h
70101index 518a53a..5e28358 100644
70102--- a/include/linux/key-type.h
70103+++ b/include/linux/key-type.h
70104@@ -125,7 +125,7 @@ struct key_type {
70105 /* internal fields */
70106 struct list_head link; /* link in types list */
70107 struct lock_class_key lock_class; /* key->sem lock class */
70108-};
70109+} __do_const;
70110
70111 extern struct key_type key_type_keyring;
70112
70113diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
70114index c6e091b..a940adf 100644
70115--- a/include/linux/kgdb.h
70116+++ b/include/linux/kgdb.h
70117@@ -52,7 +52,7 @@ extern int kgdb_connected;
70118 extern int kgdb_io_module_registered;
70119
70120 extern atomic_t kgdb_setting_breakpoint;
70121-extern atomic_t kgdb_cpu_doing_single_step;
70122+extern atomic_unchecked_t kgdb_cpu_doing_single_step;
70123
70124 extern struct task_struct *kgdb_usethread;
70125 extern struct task_struct *kgdb_contthread;
70126@@ -254,7 +254,7 @@ struct kgdb_arch {
70127 void (*correct_hw_break)(void);
70128
70129 void (*enable_nmi)(bool on);
70130-};
70131+} __do_const;
70132
70133 /**
70134 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
70135@@ -279,7 +279,7 @@ struct kgdb_io {
70136 void (*pre_exception) (void);
70137 void (*post_exception) (void);
70138 int is_console;
70139-};
70140+} __do_const;
70141
70142 extern struct kgdb_arch arch_kgdb_ops;
70143
70144diff --git a/include/linux/kmod.h b/include/linux/kmod.h
70145index 5398d58..5883a34 100644
70146--- a/include/linux/kmod.h
70147+++ b/include/linux/kmod.h
70148@@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
70149 * usually useless though. */
70150 extern __printf(2, 3)
70151 int __request_module(bool wait, const char *name, ...);
70152+extern __printf(3, 4)
70153+int ___request_module(bool wait, char *param_name, const char *name, ...);
70154 #define request_module(mod...) __request_module(true, mod)
70155 #define request_module_nowait(mod...) __request_module(false, mod)
70156 #define try_then_request_module(x, mod...) \
70157diff --git a/include/linux/kobject.h b/include/linux/kobject.h
70158index 939b112..ed6ed51 100644
70159--- a/include/linux/kobject.h
70160+++ b/include/linux/kobject.h
70161@@ -111,7 +111,7 @@ struct kobj_type {
70162 struct attribute **default_attrs;
70163 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
70164 const void *(*namespace)(struct kobject *kobj);
70165-};
70166+} __do_const;
70167
70168 struct kobj_uevent_env {
70169 char *envp[UEVENT_NUM_ENVP];
70170@@ -134,6 +134,7 @@ struct kobj_attribute {
70171 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
70172 const char *buf, size_t count);
70173 };
70174+typedef struct kobj_attribute __no_const kobj_attribute_no_const;
70175
70176 extern const struct sysfs_ops kobj_sysfs_ops;
70177
70178diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
70179index f66b065..c2c29b4 100644
70180--- a/include/linux/kobject_ns.h
70181+++ b/include/linux/kobject_ns.h
70182@@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
70183 const void *(*netlink_ns)(struct sock *sk);
70184 const void *(*initial_ns)(void);
70185 void (*drop_ns)(void *);
70186-};
70187+} __do_const;
70188
70189 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
70190 int kobj_ns_type_registered(enum kobj_ns_type type);
70191diff --git a/include/linux/kref.h b/include/linux/kref.h
70192index 7419c02..aa2f02d 100644
70193--- a/include/linux/kref.h
70194+++ b/include/linux/kref.h
70195@@ -65,7 +65,7 @@ static inline void kref_get(struct kref *kref)
70196 static inline int kref_sub(struct kref *kref, unsigned int count,
70197 void (*release)(struct kref *kref))
70198 {
70199- WARN_ON(release == NULL);
70200+ BUG_ON(release == NULL);
70201
70202 if (atomic_sub_and_test((int) count, &kref->refcount)) {
70203 release(kref);
70204diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
70205index c139582..0b5b102 100644
70206--- a/include/linux/kvm_host.h
70207+++ b/include/linux/kvm_host.h
70208@@ -424,7 +424,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
70209 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
70210 void vcpu_put(struct kvm_vcpu *vcpu);
70211
70212-int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70213+int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
70214 struct module *module);
70215 void kvm_exit(void);
70216
70217@@ -582,7 +582,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
70218 struct kvm_guest_debug *dbg);
70219 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
70220
70221-int kvm_arch_init(void *opaque);
70222+int kvm_arch_init(const void *opaque);
70223 void kvm_arch_exit(void);
70224
70225 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
70226diff --git a/include/linux/libata.h b/include/linux/libata.h
70227index eae7a05..2cdd875 100644
70228--- a/include/linux/libata.h
70229+++ b/include/linux/libata.h
70230@@ -919,7 +919,7 @@ struct ata_port_operations {
70231 * fields must be pointers.
70232 */
70233 const struct ata_port_operations *inherits;
70234-};
70235+} __do_const;
70236
70237 struct ata_port_info {
70238 unsigned long flags;
70239diff --git a/include/linux/list.h b/include/linux/list.h
70240index 6a1f8df..eaec1ff 100644
70241--- a/include/linux/list.h
70242+++ b/include/linux/list.h
70243@@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
70244 extern void list_del(struct list_head *entry);
70245 #endif
70246
70247+extern void __pax_list_add(struct list_head *new,
70248+ struct list_head *prev,
70249+ struct list_head *next);
70250+static inline void pax_list_add(struct list_head *new, struct list_head *head)
70251+{
70252+ __pax_list_add(new, head, head->next);
70253+}
70254+static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
70255+{
70256+ __pax_list_add(new, head->prev, head);
70257+}
70258+extern void pax_list_del(struct list_head *entry);
70259+
70260 /**
70261 * list_replace - replace old entry by new one
70262 * @old : the element to be replaced
70263@@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
70264 INIT_LIST_HEAD(entry);
70265 }
70266
70267+extern void pax_list_del_init(struct list_head *entry);
70268+
70269 /**
70270 * list_move - delete from one list and add as another's head
70271 * @list: the entry to move
70272diff --git a/include/linux/math64.h b/include/linux/math64.h
70273index b8ba855..0148090 100644
70274--- a/include/linux/math64.h
70275+++ b/include/linux/math64.h
70276@@ -14,7 +14,7 @@
70277 * This is commonly provided by 32bit archs to provide an optimized 64bit
70278 * divide.
70279 */
70280-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70281+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70282 {
70283 *remainder = dividend % divisor;
70284 return dividend / divisor;
70285@@ -50,7 +50,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
70286 #define div64_long(x,y) div_s64((x),(y))
70287
70288 #ifndef div_u64_rem
70289-static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70290+static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
70291 {
70292 *remainder = do_div(dividend, divisor);
70293 return dividend;
70294@@ -79,7 +79,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
70295 * divide.
70296 */
70297 #ifndef div_u64
70298-static inline u64 div_u64(u64 dividend, u32 divisor)
70299+static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
70300 {
70301 u32 remainder;
70302 return div_u64_rem(dividend, divisor, &remainder);
70303diff --git a/include/linux/mm.h b/include/linux/mm.h
70304index e2091b8..3c7b38c 100644
70305--- a/include/linux/mm.h
70306+++ b/include/linux/mm.h
70307@@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
70308 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
70309 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
70310 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
70311+
70312+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
70313+#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
70314+#endif
70315+
70316 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
70317
70318 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
70319@@ -202,8 +207,8 @@ struct vm_operations_struct {
70320 /* called by access_process_vm when get_user_pages() fails, typically
70321 * for use by special VMAs that can switch between memory and hardware
70322 */
70323- int (*access)(struct vm_area_struct *vma, unsigned long addr,
70324- void *buf, int len, int write);
70325+ ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
70326+ void *buf, size_t len, int write);
70327 #ifdef CONFIG_NUMA
70328 /*
70329 * set_policy() op must add a reference to any non-NULL @new mempolicy
70330@@ -233,6 +238,7 @@ struct vm_operations_struct {
70331 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
70332 unsigned long size, pgoff_t pgoff);
70333 };
70334+typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
70335
70336 struct mmu_gather;
70337 struct inode;
70338@@ -970,8 +976,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
70339 unsigned long *pfn);
70340 int follow_phys(struct vm_area_struct *vma, unsigned long address,
70341 unsigned int flags, unsigned long *prot, resource_size_t *phys);
70342-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70343- void *buf, int len, int write);
70344+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
70345+ void *buf, size_t len, int write);
70346
70347 static inline void unmap_shared_mapping_range(struct address_space *mapping,
70348 loff_t const holebegin, loff_t const holelen)
70349@@ -1010,9 +1016,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
70350 }
70351 #endif
70352
70353-extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
70354-extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
70355- void *buf, int len, int write);
70356+extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
70357+extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
70358+ void *buf, size_t len, int write);
70359
70360 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
70361 unsigned long start, unsigned long nr_pages,
70362@@ -1043,34 +1049,6 @@ int set_page_dirty(struct page *page);
70363 int set_page_dirty_lock(struct page *page);
70364 int clear_page_dirty_for_io(struct page *page);
70365
70366-/* Is the vma a continuation of the stack vma above it? */
70367-static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
70368-{
70369- return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
70370-}
70371-
70372-static inline int stack_guard_page_start(struct vm_area_struct *vma,
70373- unsigned long addr)
70374-{
70375- return (vma->vm_flags & VM_GROWSDOWN) &&
70376- (vma->vm_start == addr) &&
70377- !vma_growsdown(vma->vm_prev, addr);
70378-}
70379-
70380-/* Is the vma a continuation of the stack vma below it? */
70381-static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
70382-{
70383- return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
70384-}
70385-
70386-static inline int stack_guard_page_end(struct vm_area_struct *vma,
70387- unsigned long addr)
70388-{
70389- return (vma->vm_flags & VM_GROWSUP) &&
70390- (vma->vm_end == addr) &&
70391- !vma_growsup(vma->vm_next, addr);
70392-}
70393-
70394 extern pid_t
70395 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
70396
70397@@ -1173,6 +1151,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
70398 }
70399 #endif
70400
70401+#ifdef CONFIG_MMU
70402+pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
70403+#else
70404+static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
70405+{
70406+ return __pgprot(0);
70407+}
70408+#endif
70409+
70410 int vma_wants_writenotify(struct vm_area_struct *vma);
70411
70412 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
70413@@ -1191,8 +1178,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
70414 {
70415 return 0;
70416 }
70417+
70418+static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
70419+ unsigned long address)
70420+{
70421+ return 0;
70422+}
70423 #else
70424 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70425+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
70426 #endif
70427
70428 #ifdef __PAGETABLE_PMD_FOLDED
70429@@ -1201,8 +1195,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
70430 {
70431 return 0;
70432 }
70433+
70434+static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
70435+ unsigned long address)
70436+{
70437+ return 0;
70438+}
70439 #else
70440 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
70441+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
70442 #endif
70443
70444 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
70445@@ -1220,11 +1221,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
70446 NULL: pud_offset(pgd, address);
70447 }
70448
70449+static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
70450+{
70451+ return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
70452+ NULL: pud_offset(pgd, address);
70453+}
70454+
70455 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
70456 {
70457 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
70458 NULL: pmd_offset(pud, address);
70459 }
70460+
70461+static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
70462+{
70463+ return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
70464+ NULL: pmd_offset(pud, address);
70465+}
70466 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
70467
70468 #if USE_SPLIT_PTLOCKS
70469@@ -1455,6 +1468,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
70470 unsigned long len, unsigned long prot, unsigned long flags,
70471 unsigned long pgoff, unsigned long *populate);
70472 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
70473+extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
70474
70475 #ifdef CONFIG_MMU
70476 extern int __mm_populate(unsigned long addr, unsigned long len,
70477@@ -1483,10 +1497,11 @@ struct vm_unmapped_area_info {
70478 unsigned long high_limit;
70479 unsigned long align_mask;
70480 unsigned long align_offset;
70481+ unsigned long threadstack_offset;
70482 };
70483
70484-extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
70485-extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70486+extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
70487+extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
70488
70489 /*
70490 * Search for an unmapped address range.
70491@@ -1498,7 +1513,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
70492 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
70493 */
70494 static inline unsigned long
70495-vm_unmapped_area(struct vm_unmapped_area_info *info)
70496+vm_unmapped_area(const struct vm_unmapped_area_info *info)
70497 {
70498 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
70499 return unmapped_area(info);
70500@@ -1561,6 +1576,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
70501 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
70502 struct vm_area_struct **pprev);
70503
70504+extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
70505+extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
70506+extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
70507+
70508 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
70509 NULL if none. Assume start_addr < end_addr. */
70510 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
70511@@ -1589,15 +1608,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
70512 return vma;
70513 }
70514
70515-#ifdef CONFIG_MMU
70516-pgprot_t vm_get_page_prot(unsigned long vm_flags);
70517-#else
70518-static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
70519-{
70520- return __pgprot(0);
70521-}
70522-#endif
70523-
70524 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
70525 unsigned long change_prot_numa(struct vm_area_struct *vma,
70526 unsigned long start, unsigned long end);
70527@@ -1649,6 +1659,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
70528 static inline void vm_stat_account(struct mm_struct *mm,
70529 unsigned long flags, struct file *file, long pages)
70530 {
70531+
70532+#ifdef CONFIG_PAX_RANDMMAP
70533+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
70534+#endif
70535+
70536 mm->total_vm += pages;
70537 }
70538 #endif /* CONFIG_PROC_FS */
70539@@ -1725,7 +1740,7 @@ extern int unpoison_memory(unsigned long pfn);
70540 extern int sysctl_memory_failure_early_kill;
70541 extern int sysctl_memory_failure_recovery;
70542 extern void shake_page(struct page *p, int access);
70543-extern atomic_long_t num_poisoned_pages;
70544+extern atomic_long_unchecked_t num_poisoned_pages;
70545 extern int soft_offline_page(struct page *page, int flags);
70546
70547 extern void dump_page(struct page *page);
70548@@ -1756,5 +1771,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
70549 static inline bool page_is_guard(struct page *page) { return false; }
70550 #endif /* CONFIG_DEBUG_PAGEALLOC */
70551
70552+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
70553+extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
70554+#else
70555+static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
70556+#endif
70557+
70558 #endif /* __KERNEL__ */
70559 #endif /* _LINUX_MM_H */
70560diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
70561index ace9a5f..81bdb59 100644
70562--- a/include/linux/mm_types.h
70563+++ b/include/linux/mm_types.h
70564@@ -289,6 +289,8 @@ struct vm_area_struct {
70565 #ifdef CONFIG_NUMA
70566 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
70567 #endif
70568+
70569+ struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
70570 };
70571
70572 struct core_thread {
70573@@ -437,6 +439,24 @@ struct mm_struct {
70574 int first_nid;
70575 #endif
70576 struct uprobes_state uprobes_state;
70577+
70578+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
70579+ unsigned long pax_flags;
70580+#endif
70581+
70582+#ifdef CONFIG_PAX_DLRESOLVE
70583+ unsigned long call_dl_resolve;
70584+#endif
70585+
70586+#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
70587+ unsigned long call_syscall;
70588+#endif
70589+
70590+#ifdef CONFIG_PAX_ASLR
70591+ unsigned long delta_mmap; /* randomized offset */
70592+ unsigned long delta_stack; /* randomized offset */
70593+#endif
70594+
70595 };
70596
70597 /* first nid will either be a valid NID or one of these values */
70598diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
70599index c5d5278..f0b68c8 100644
70600--- a/include/linux/mmiotrace.h
70601+++ b/include/linux/mmiotrace.h
70602@@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
70603 /* Called from ioremap.c */
70604 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
70605 void __iomem *addr);
70606-extern void mmiotrace_iounmap(volatile void __iomem *addr);
70607+extern void mmiotrace_iounmap(const volatile void __iomem *addr);
70608
70609 /* For anyone to insert markers. Remember trailing newline. */
70610 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
70611@@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
70612 {
70613 }
70614
70615-static inline void mmiotrace_iounmap(volatile void __iomem *addr)
70616+static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
70617 {
70618 }
70619
70620diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
70621index c74092e..b663967 100644
70622--- a/include/linux/mmzone.h
70623+++ b/include/linux/mmzone.h
70624@@ -396,7 +396,7 @@ struct zone {
70625 unsigned long flags; /* zone flags, see below */
70626
70627 /* Zone statistics */
70628- atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70629+ atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70630
70631 /*
70632 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
70633diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
70634index 779cf7c..e6768240 100644
70635--- a/include/linux/mod_devicetable.h
70636+++ b/include/linux/mod_devicetable.h
70637@@ -12,7 +12,7 @@
70638 typedef unsigned long kernel_ulong_t;
70639 #endif
70640
70641-#define PCI_ANY_ID (~0)
70642+#define PCI_ANY_ID ((__u16)~0)
70643
70644 struct pci_device_id {
70645 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
70646@@ -138,7 +138,7 @@ struct usb_device_id {
70647 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
70648 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
70649
70650-#define HID_ANY_ID (~0)
70651+#define HID_ANY_ID (~0U)
70652 #define HID_BUS_ANY 0xffff
70653 #define HID_GROUP_ANY 0x0000
70654
70655@@ -464,7 +464,7 @@ struct dmi_system_id {
70656 const char *ident;
70657 struct dmi_strmatch matches[4];
70658 void *driver_data;
70659-};
70660+} __do_const;
70661 /*
70662 * struct dmi_device_id appears during expansion of
70663 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
70664diff --git a/include/linux/module.h b/include/linux/module.h
70665index ead1b57..81a3b6c 100644
70666--- a/include/linux/module.h
70667+++ b/include/linux/module.h
70668@@ -17,9 +17,11 @@
70669 #include <linux/moduleparam.h>
70670 #include <linux/tracepoint.h>
70671 #include <linux/export.h>
70672+#include <linux/fs.h>
70673
70674 #include <linux/percpu.h>
70675 #include <asm/module.h>
70676+#include <asm/pgtable.h>
70677
70678 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
70679 #define MODULE_SIG_STRING "~Module signature appended~\n"
70680@@ -54,12 +56,13 @@ struct module_attribute {
70681 int (*test)(struct module *);
70682 void (*free)(struct module *);
70683 };
70684+typedef struct module_attribute __no_const module_attribute_no_const;
70685
70686 struct module_version_attribute {
70687 struct module_attribute mattr;
70688 const char *module_name;
70689 const char *version;
70690-} __attribute__ ((__aligned__(sizeof(void *))));
70691+} __do_const __attribute__ ((__aligned__(sizeof(void *))));
70692
70693 extern ssize_t __modver_version_show(struct module_attribute *,
70694 struct module_kobject *, char *);
70695@@ -232,7 +235,7 @@ struct module
70696
70697 /* Sysfs stuff. */
70698 struct module_kobject mkobj;
70699- struct module_attribute *modinfo_attrs;
70700+ module_attribute_no_const *modinfo_attrs;
70701 const char *version;
70702 const char *srcversion;
70703 struct kobject *holders_dir;
70704@@ -281,19 +284,16 @@ struct module
70705 int (*init)(void);
70706
70707 /* If this is non-NULL, vfree after init() returns */
70708- void *module_init;
70709+ void *module_init_rx, *module_init_rw;
70710
70711 /* Here is the actual code + data, vfree'd on unload. */
70712- void *module_core;
70713+ void *module_core_rx, *module_core_rw;
70714
70715 /* Here are the sizes of the init and core sections */
70716- unsigned int init_size, core_size;
70717+ unsigned int init_size_rw, core_size_rw;
70718
70719 /* The size of the executable code in each section. */
70720- unsigned int init_text_size, core_text_size;
70721-
70722- /* Size of RO sections of the module (text+rodata) */
70723- unsigned int init_ro_size, core_ro_size;
70724+ unsigned int init_size_rx, core_size_rx;
70725
70726 /* Arch-specific module values */
70727 struct mod_arch_specific arch;
70728@@ -349,6 +349,10 @@ struct module
70729 #ifdef CONFIG_EVENT_TRACING
70730 struct ftrace_event_call **trace_events;
70731 unsigned int num_trace_events;
70732+ struct file_operations trace_id;
70733+ struct file_operations trace_enable;
70734+ struct file_operations trace_format;
70735+ struct file_operations trace_filter;
70736 #endif
70737 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
70738 unsigned int num_ftrace_callsites;
70739@@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
70740 bool is_module_percpu_address(unsigned long addr);
70741 bool is_module_text_address(unsigned long addr);
70742
70743+static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
70744+{
70745+
70746+#ifdef CONFIG_PAX_KERNEXEC
70747+ if (ktla_ktva(addr) >= (unsigned long)start &&
70748+ ktla_ktva(addr) < (unsigned long)start + size)
70749+ return 1;
70750+#endif
70751+
70752+ return ((void *)addr >= start && (void *)addr < start + size);
70753+}
70754+
70755+static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
70756+{
70757+ return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
70758+}
70759+
70760+static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
70761+{
70762+ return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
70763+}
70764+
70765+static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
70766+{
70767+ return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
70768+}
70769+
70770+static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
70771+{
70772+ return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
70773+}
70774+
70775 static inline int within_module_core(unsigned long addr, const struct module *mod)
70776 {
70777- return (unsigned long)mod->module_core <= addr &&
70778- addr < (unsigned long)mod->module_core + mod->core_size;
70779+ return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
70780 }
70781
70782 static inline int within_module_init(unsigned long addr, const struct module *mod)
70783 {
70784- return (unsigned long)mod->module_init <= addr &&
70785- addr < (unsigned long)mod->module_init + mod->init_size;
70786+ return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
70787 }
70788
70789 /* Search for module by name: must hold module_mutex. */
70790diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
70791index 560ca53..ef621ef 100644
70792--- a/include/linux/moduleloader.h
70793+++ b/include/linux/moduleloader.h
70794@@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
70795 sections. Returns NULL on failure. */
70796 void *module_alloc(unsigned long size);
70797
70798+#ifdef CONFIG_PAX_KERNEXEC
70799+void *module_alloc_exec(unsigned long size);
70800+#else
70801+#define module_alloc_exec(x) module_alloc(x)
70802+#endif
70803+
70804 /* Free memory returned from module_alloc. */
70805 void module_free(struct module *mod, void *module_region);
70806
70807+#ifdef CONFIG_PAX_KERNEXEC
70808+void module_free_exec(struct module *mod, void *module_region);
70809+#else
70810+#define module_free_exec(x, y) module_free((x), (y))
70811+#endif
70812+
70813 /*
70814 * Apply the given relocation to the (simplified) ELF. Return -error
70815 * or 0.
70816@@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
70817 unsigned int relsec,
70818 struct module *me)
70819 {
70820+#ifdef CONFIG_MODULES
70821 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70822+#endif
70823 return -ENOEXEC;
70824 }
70825 #endif
70826@@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
70827 unsigned int relsec,
70828 struct module *me)
70829 {
70830+#ifdef CONFIG_MODULES
70831 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
70832+#endif
70833 return -ENOEXEC;
70834 }
70835 #endif
70836diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
70837index 137b419..fe663ec 100644
70838--- a/include/linux/moduleparam.h
70839+++ b/include/linux/moduleparam.h
70840@@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
70841 * @len is usually just sizeof(string).
70842 */
70843 #define module_param_string(name, string, len, perm) \
70844- static const struct kparam_string __param_string_##name \
70845+ static const struct kparam_string __param_string_##name __used \
70846 = { len, string }; \
70847 __module_param_call(MODULE_PARAM_PREFIX, name, \
70848 &param_ops_string, \
70849@@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
70850 */
70851 #define module_param_array_named(name, array, type, nump, perm) \
70852 param_check_##type(name, &(array)[0]); \
70853- static const struct kparam_array __param_arr_##name \
70854+ static const struct kparam_array __param_arr_##name __used \
70855 = { .max = ARRAY_SIZE(array), .num = nump, \
70856 .ops = &param_ops_##type, \
70857 .elemsize = sizeof(array[0]), .elem = array }; \
70858diff --git a/include/linux/namei.h b/include/linux/namei.h
70859index 5a5ff57..5ae5070 100644
70860--- a/include/linux/namei.h
70861+++ b/include/linux/namei.h
70862@@ -19,7 +19,7 @@ struct nameidata {
70863 unsigned seq;
70864 int last_type;
70865 unsigned depth;
70866- char *saved_names[MAX_NESTED_LINKS + 1];
70867+ const char *saved_names[MAX_NESTED_LINKS + 1];
70868 };
70869
70870 /*
70871@@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
70872
70873 extern void nd_jump_link(struct nameidata *nd, struct path *path);
70874
70875-static inline void nd_set_link(struct nameidata *nd, char *path)
70876+static inline void nd_set_link(struct nameidata *nd, const char *path)
70877 {
70878 nd->saved_names[nd->depth] = path;
70879 }
70880
70881-static inline char *nd_get_link(struct nameidata *nd)
70882+static inline const char *nd_get_link(const struct nameidata *nd)
70883 {
70884 return nd->saved_names[nd->depth];
70885 }
70886diff --git a/include/linux/net.h b/include/linux/net.h
70887index aa16731..514b875 100644
70888--- a/include/linux/net.h
70889+++ b/include/linux/net.h
70890@@ -183,7 +183,7 @@ struct net_proto_family {
70891 int (*create)(struct net *net, struct socket *sock,
70892 int protocol, int kern);
70893 struct module *owner;
70894-};
70895+} __do_const;
70896
70897 struct iovec;
70898 struct kvec;
70899diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
70900index 6151e90..2e0afb0 100644
70901--- a/include/linux/netdevice.h
70902+++ b/include/linux/netdevice.h
70903@@ -1028,6 +1028,7 @@ struct net_device_ops {
70904 int (*ndo_change_carrier)(struct net_device *dev,
70905 bool new_carrier);
70906 };
70907+typedef struct net_device_ops __no_const net_device_ops_no_const;
70908
70909 /*
70910 * The DEVICE structure.
70911@@ -1094,7 +1095,7 @@ struct net_device {
70912 int iflink;
70913
70914 struct net_device_stats stats;
70915- atomic_long_t rx_dropped; /* dropped packets by core network
70916+ atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
70917 * Do not use this in drivers.
70918 */
70919
70920diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
70921index ee14284..bc65d63 100644
70922--- a/include/linux/netfilter.h
70923+++ b/include/linux/netfilter.h
70924@@ -82,7 +82,7 @@ struct nf_sockopt_ops {
70925 #endif
70926 /* Use the module struct to lock set/get code in place */
70927 struct module *owner;
70928-};
70929+} __do_const;
70930
70931 /* Function to register/unregister hook points. */
70932 int nf_register_hook(struct nf_hook_ops *reg);
70933diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
70934index 7958e84..ed74d7a 100644
70935--- a/include/linux/netfilter/ipset/ip_set.h
70936+++ b/include/linux/netfilter/ipset/ip_set.h
70937@@ -98,7 +98,7 @@ struct ip_set_type_variant {
70938 /* Return true if "b" set is the same as "a"
70939 * according to the create set parameters */
70940 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
70941-};
70942+} __do_const;
70943
70944 /* The core set type structure */
70945 struct ip_set_type {
70946diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
70947index ecbb8e4..8a1c4e1 100644
70948--- a/include/linux/netfilter/nfnetlink.h
70949+++ b/include/linux/netfilter/nfnetlink.h
70950@@ -16,7 +16,7 @@ struct nfnl_callback {
70951 const struct nlattr * const cda[]);
70952 const struct nla_policy *policy; /* netlink attribute policy */
70953 const u_int16_t attr_count; /* number of nlattr's */
70954-};
70955+} __do_const;
70956
70957 struct nfnetlink_subsystem {
70958 const char *name;
70959diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
70960new file mode 100644
70961index 0000000..33f4af8
70962--- /dev/null
70963+++ b/include/linux/netfilter/xt_gradm.h
70964@@ -0,0 +1,9 @@
70965+#ifndef _LINUX_NETFILTER_XT_GRADM_H
70966+#define _LINUX_NETFILTER_XT_GRADM_H 1
70967+
70968+struct xt_gradm_mtinfo {
70969+ __u16 flags;
70970+ __u16 invflags;
70971+};
70972+
70973+#endif
70974diff --git a/include/linux/nls.h b/include/linux/nls.h
70975index 5dc635f..35f5e11 100644
70976--- a/include/linux/nls.h
70977+++ b/include/linux/nls.h
70978@@ -31,7 +31,7 @@ struct nls_table {
70979 const unsigned char *charset2upper;
70980 struct module *owner;
70981 struct nls_table *next;
70982-};
70983+} __do_const;
70984
70985 /* this value hold the maximum octet of charset */
70986 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
70987diff --git a/include/linux/notifier.h b/include/linux/notifier.h
70988index d65746e..62e72c2 100644
70989--- a/include/linux/notifier.h
70990+++ b/include/linux/notifier.h
70991@@ -51,7 +51,8 @@ struct notifier_block {
70992 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
70993 struct notifier_block __rcu *next;
70994 int priority;
70995-};
70996+} __do_const;
70997+typedef struct notifier_block __no_const notifier_block_no_const;
70998
70999 struct atomic_notifier_head {
71000 spinlock_t lock;
71001diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
71002index a4c5624..79d6d88 100644
71003--- a/include/linux/oprofile.h
71004+++ b/include/linux/oprofile.h
71005@@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
71006 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
71007 char const * name, ulong * val);
71008
71009-/** Create a file for read-only access to an atomic_t. */
71010+/** Create a file for read-only access to an atomic_unchecked_t. */
71011 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
71012- char const * name, atomic_t * val);
71013+ char const * name, atomic_unchecked_t * val);
71014
71015 /** create a directory */
71016 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
71017diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
71018index 45fc162..01a4068 100644
71019--- a/include/linux/pci_hotplug.h
71020+++ b/include/linux/pci_hotplug.h
71021@@ -80,7 +80,8 @@ struct hotplug_slot_ops {
71022 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
71023 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
71024 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
71025-};
71026+} __do_const;
71027+typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
71028
71029 /**
71030 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
71031diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
71032index 2f522a3..494e45f 100644
71033--- a/include/linux/perf_event.h
71034+++ b/include/linux/perf_event.h
71035@@ -333,8 +333,8 @@ struct perf_event {
71036
71037 enum perf_event_active_state state;
71038 unsigned int attach_state;
71039- local64_t count;
71040- atomic64_t child_count;
71041+ local64_t count; /* PaX: fix it one day */
71042+ atomic64_unchecked_t child_count;
71043
71044 /*
71045 * These are the total time in nanoseconds that the event
71046@@ -385,8 +385,8 @@ struct perf_event {
71047 * These accumulate total time (in nanoseconds) that children
71048 * events have been enabled and running, respectively.
71049 */
71050- atomic64_t child_total_time_enabled;
71051- atomic64_t child_total_time_running;
71052+ atomic64_unchecked_t child_total_time_enabled;
71053+ atomic64_unchecked_t child_total_time_running;
71054
71055 /*
71056 * Protect attach/detach and child_list:
71057@@ -703,7 +703,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
71058 entry->ip[entry->nr++] = ip;
71059 }
71060
71061-extern int sysctl_perf_event_paranoid;
71062+extern int sysctl_perf_event_legitimately_concerned;
71063 extern int sysctl_perf_event_mlock;
71064 extern int sysctl_perf_event_sample_rate;
71065
71066@@ -711,19 +711,24 @@ extern int perf_proc_update_handler(struct ctl_table *table, int write,
71067 void __user *buffer, size_t *lenp,
71068 loff_t *ppos);
71069
71070+static inline bool perf_paranoid_any(void)
71071+{
71072+ return sysctl_perf_event_legitimately_concerned > 2;
71073+}
71074+
71075 static inline bool perf_paranoid_tracepoint_raw(void)
71076 {
71077- return sysctl_perf_event_paranoid > -1;
71078+ return sysctl_perf_event_legitimately_concerned > -1;
71079 }
71080
71081 static inline bool perf_paranoid_cpu(void)
71082 {
71083- return sysctl_perf_event_paranoid > 0;
71084+ return sysctl_perf_event_legitimately_concerned > 0;
71085 }
71086
71087 static inline bool perf_paranoid_kernel(void)
71088 {
71089- return sysctl_perf_event_paranoid > 1;
71090+ return sysctl_perf_event_legitimately_concerned > 1;
71091 }
71092
71093 extern void perf_event_init(void);
71094@@ -811,7 +816,7 @@ static inline void perf_restore_debug_store(void) { }
71095 */
71096 #define perf_cpu_notifier(fn) \
71097 do { \
71098- static struct notifier_block fn##_nb __cpuinitdata = \
71099+ static struct notifier_block fn##_nb = \
71100 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
71101 unsigned long cpu = smp_processor_id(); \
71102 unsigned long flags; \
71103@@ -830,7 +835,7 @@ do { \
71104 struct perf_pmu_events_attr {
71105 struct device_attribute attr;
71106 u64 id;
71107-};
71108+} __do_const;
71109
71110 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
71111 static struct perf_pmu_events_attr _var = { \
71112diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
71113index ad1a427..6419649 100644
71114--- a/include/linux/pipe_fs_i.h
71115+++ b/include/linux/pipe_fs_i.h
71116@@ -45,9 +45,9 @@ struct pipe_buffer {
71117 struct pipe_inode_info {
71118 wait_queue_head_t wait;
71119 unsigned int nrbufs, curbuf, buffers;
71120- unsigned int readers;
71121- unsigned int writers;
71122- unsigned int waiting_writers;
71123+ atomic_t readers;
71124+ atomic_t writers;
71125+ atomic_t waiting_writers;
71126 unsigned int r_counter;
71127 unsigned int w_counter;
71128 struct page *tmp_page;
71129diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
71130index 5f28cae..3d23723 100644
71131--- a/include/linux/platform_data/usb-ehci-s5p.h
71132+++ b/include/linux/platform_data/usb-ehci-s5p.h
71133@@ -14,7 +14,7 @@
71134 struct s5p_ehci_platdata {
71135 int (*phy_init)(struct platform_device *pdev, int type);
71136 int (*phy_exit)(struct platform_device *pdev, int type);
71137-};
71138+} __no_const;
71139
71140 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
71141
71142diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
71143index c256c59..8ea94c7 100644
71144--- a/include/linux/platform_data/usb-exynos.h
71145+++ b/include/linux/platform_data/usb-exynos.h
71146@@ -14,7 +14,7 @@
71147 struct exynos4_ohci_platdata {
71148 int (*phy_init)(struct platform_device *pdev, int type);
71149 int (*phy_exit)(struct platform_device *pdev, int type);
71150-};
71151+} __no_const;
71152
71153 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
71154
71155diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
71156index 7c1d252..c5c773e 100644
71157--- a/include/linux/pm_domain.h
71158+++ b/include/linux/pm_domain.h
71159@@ -48,7 +48,7 @@ struct gpd_dev_ops {
71160
71161 struct gpd_cpu_data {
71162 unsigned int saved_exit_latency;
71163- struct cpuidle_state *idle_state;
71164+ cpuidle_state_no_const *idle_state;
71165 };
71166
71167 struct generic_pm_domain {
71168diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
71169index 7d7e09e..8671ef8 100644
71170--- a/include/linux/pm_runtime.h
71171+++ b/include/linux/pm_runtime.h
71172@@ -104,7 +104,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
71173
71174 static inline void pm_runtime_mark_last_busy(struct device *dev)
71175 {
71176- ACCESS_ONCE(dev->power.last_busy) = jiffies;
71177+ ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
71178 }
71179
71180 #else /* !CONFIG_PM_RUNTIME */
71181diff --git a/include/linux/pnp.h b/include/linux/pnp.h
71182index 195aafc..49a7bc2 100644
71183--- a/include/linux/pnp.h
71184+++ b/include/linux/pnp.h
71185@@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
71186 struct pnp_fixup {
71187 char id[7];
71188 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
71189-};
71190+} __do_const;
71191
71192 /* config parameters */
71193 #define PNP_CONFIG_NORMAL 0x0001
71194diff --git a/include/linux/poison.h b/include/linux/poison.h
71195index 2110a81..13a11bb 100644
71196--- a/include/linux/poison.h
71197+++ b/include/linux/poison.h
71198@@ -19,8 +19,8 @@
71199 * under normal circumstances, used to verify that nobody uses
71200 * non-initialized list entries.
71201 */
71202-#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
71203-#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
71204+#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
71205+#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
71206
71207 /********** include/linux/timer.h **********/
71208 /*
71209diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
71210index c0f44c2..1572583 100644
71211--- a/include/linux/power/smartreflex.h
71212+++ b/include/linux/power/smartreflex.h
71213@@ -238,7 +238,7 @@ struct omap_sr_class_data {
71214 int (*notify)(struct omap_sr *sr, u32 status);
71215 u8 notify_flags;
71216 u8 class_type;
71217-};
71218+} __do_const;
71219
71220 /**
71221 * struct omap_sr_nvalue_table - Smartreflex n-target value info
71222diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
71223index 4ea1d37..80f4b33 100644
71224--- a/include/linux/ppp-comp.h
71225+++ b/include/linux/ppp-comp.h
71226@@ -84,7 +84,7 @@ struct compressor {
71227 struct module *owner;
71228 /* Extra skb space needed by the compressor algorithm */
71229 unsigned int comp_extra;
71230-};
71231+} __do_const;
71232
71233 /*
71234 * The return value from decompress routine is the length of the
71235diff --git a/include/linux/printk.h b/include/linux/printk.h
71236index 822171f..12b30e8 100644
71237--- a/include/linux/printk.h
71238+++ b/include/linux/printk.h
71239@@ -98,6 +98,8 @@ int no_printk(const char *fmt, ...)
71240 extern asmlinkage __printf(1, 2)
71241 void early_printk(const char *fmt, ...);
71242
71243+extern int kptr_restrict;
71244+
71245 #ifdef CONFIG_PRINTK
71246 asmlinkage __printf(5, 0)
71247 int vprintk_emit(int facility, int level,
71248@@ -132,7 +134,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
71249
71250 extern int printk_delay_msec;
71251 extern int dmesg_restrict;
71252-extern int kptr_restrict;
71253
71254 extern void wake_up_klogd(void);
71255
71256diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
71257index 94dfb2a..88b9d3b 100644
71258--- a/include/linux/proc_fs.h
71259+++ b/include/linux/proc_fs.h
71260@@ -165,6 +165,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
71261 return proc_create_data(name, mode, parent, proc_fops, NULL);
71262 }
71263
71264+static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
71265+ struct proc_dir_entry *parent, const struct file_operations *proc_fops)
71266+{
71267+#ifdef CONFIG_GRKERNSEC_PROC_USER
71268+ return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
71269+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
71270+ return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
71271+#else
71272+ return proc_create_data(name, mode, parent, proc_fops, NULL);
71273+#endif
71274+}
71275+
71276 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
71277 umode_t mode, struct proc_dir_entry *base,
71278 read_proc_t *read_proc, void * data)
71279@@ -266,7 +278,7 @@ struct proc_ns_operations {
71280 void (*put)(void *ns);
71281 int (*install)(struct nsproxy *nsproxy, void *ns);
71282 unsigned int (*inum)(void *ns);
71283-};
71284+} __do_const;
71285 extern const struct proc_ns_operations netns_operations;
71286 extern const struct proc_ns_operations utsns_operations;
71287 extern const struct proc_ns_operations ipcns_operations;
71288diff --git a/include/linux/random.h b/include/linux/random.h
71289index 347ce55..880f97c 100644
71290--- a/include/linux/random.h
71291+++ b/include/linux/random.h
71292@@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
71293 u32 prandom_u32_state(struct rnd_state *);
71294 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
71295
71296+static inline unsigned long pax_get_random_long(void)
71297+{
71298+ return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
71299+}
71300+
71301 /*
71302 * Handle minimum values for seeds
71303 */
71304diff --git a/include/linux/rculist.h b/include/linux/rculist.h
71305index 8089e35..3a0d59a 100644
71306--- a/include/linux/rculist.h
71307+++ b/include/linux/rculist.h
71308@@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
71309 struct list_head *prev, struct list_head *next);
71310 #endif
71311
71312+extern void __pax_list_add_rcu(struct list_head *new,
71313+ struct list_head *prev, struct list_head *next);
71314+
71315 /**
71316 * list_add_rcu - add a new entry to rcu-protected list
71317 * @new: new entry to be added
71318@@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
71319 __list_add_rcu(new, head, head->next);
71320 }
71321
71322+static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
71323+{
71324+ __pax_list_add_rcu(new, head, head->next);
71325+}
71326+
71327 /**
71328 * list_add_tail_rcu - add a new entry to rcu-protected list
71329 * @new: new entry to be added
71330@@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
71331 __list_add_rcu(new, head->prev, head);
71332 }
71333
71334+static inline void pax_list_add_tail_rcu(struct list_head *new,
71335+ struct list_head *head)
71336+{
71337+ __pax_list_add_rcu(new, head->prev, head);
71338+}
71339+
71340 /**
71341 * list_del_rcu - deletes entry from list without re-initialization
71342 * @entry: the element to delete from the list.
71343@@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
71344 entry->prev = LIST_POISON2;
71345 }
71346
71347+extern void pax_list_del_rcu(struct list_head *entry);
71348+
71349 /**
71350 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
71351 * @n: the element to delete from the hash list.
71352diff --git a/include/linux/reboot.h b/include/linux/reboot.h
71353index 23b3630..e1bc12b 100644
71354--- a/include/linux/reboot.h
71355+++ b/include/linux/reboot.h
71356@@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
71357 * Architecture-specific implementations of sys_reboot commands.
71358 */
71359
71360-extern void machine_restart(char *cmd);
71361-extern void machine_halt(void);
71362-extern void machine_power_off(void);
71363+extern void machine_restart(char *cmd) __noreturn;
71364+extern void machine_halt(void) __noreturn;
71365+extern void machine_power_off(void) __noreturn;
71366
71367 extern void machine_shutdown(void);
71368 struct pt_regs;
71369@@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
71370 */
71371
71372 extern void kernel_restart_prepare(char *cmd);
71373-extern void kernel_restart(char *cmd);
71374-extern void kernel_halt(void);
71375-extern void kernel_power_off(void);
71376+extern void kernel_restart(char *cmd) __noreturn;
71377+extern void kernel_halt(void) __noreturn;
71378+extern void kernel_power_off(void) __noreturn;
71379
71380 extern int C_A_D; /* for sysctl */
71381 void ctrl_alt_del(void);
71382@@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
71383 * Emergency restart, callable from an interrupt handler.
71384 */
71385
71386-extern void emergency_restart(void);
71387+extern void emergency_restart(void) __noreturn;
71388 #include <asm/emergency-restart.h>
71389
71390 #endif /* _LINUX_REBOOT_H */
71391diff --git a/include/linux/regset.h b/include/linux/regset.h
71392index 8e0c9fe..ac4d221 100644
71393--- a/include/linux/regset.h
71394+++ b/include/linux/regset.h
71395@@ -161,7 +161,8 @@ struct user_regset {
71396 unsigned int align;
71397 unsigned int bias;
71398 unsigned int core_note_type;
71399-};
71400+} __do_const;
71401+typedef struct user_regset __no_const user_regset_no_const;
71402
71403 /**
71404 * struct user_regset_view - available regsets
71405diff --git a/include/linux/relay.h b/include/linux/relay.h
71406index 91cacc3..b55ff74 100644
71407--- a/include/linux/relay.h
71408+++ b/include/linux/relay.h
71409@@ -160,7 +160,7 @@ struct rchan_callbacks
71410 * The callback should return 0 if successful, negative if not.
71411 */
71412 int (*remove_buf_file)(struct dentry *dentry);
71413-};
71414+} __no_const;
71415
71416 /*
71417 * CONFIG_RELAY kernel API, kernel/relay.c
71418diff --git a/include/linux/rio.h b/include/linux/rio.h
71419index a3e7842..d973ca6 100644
71420--- a/include/linux/rio.h
71421+++ b/include/linux/rio.h
71422@@ -339,7 +339,7 @@ struct rio_ops {
71423 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
71424 u64 rstart, u32 size, u32 flags);
71425 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
71426-};
71427+} __no_const;
71428
71429 #define RIO_RESOURCE_MEM 0x00000100
71430 #define RIO_RESOURCE_DOORBELL 0x00000200
71431diff --git a/include/linux/rmap.h b/include/linux/rmap.h
71432index 6dacb93..6174423 100644
71433--- a/include/linux/rmap.h
71434+++ b/include/linux/rmap.h
71435@@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
71436 void anon_vma_init(void); /* create anon_vma_cachep */
71437 int anon_vma_prepare(struct vm_area_struct *);
71438 void unlink_anon_vmas(struct vm_area_struct *);
71439-int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
71440-int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
71441+int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
71442+int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
71443
71444 static inline void anon_vma_merge(struct vm_area_struct *vma,
71445 struct vm_area_struct *next)
71446diff --git a/include/linux/sched.h b/include/linux/sched.h
71447index be4e742..7f9d593 100644
71448--- a/include/linux/sched.h
71449+++ b/include/linux/sched.h
71450@@ -62,6 +62,7 @@ struct bio_list;
71451 struct fs_struct;
71452 struct perf_event_context;
71453 struct blk_plug;
71454+struct linux_binprm;
71455
71456 /*
71457 * List of flags we want to share for kernel threads,
71458@@ -315,7 +316,7 @@ extern char __sched_text_start[], __sched_text_end[];
71459 extern int in_sched_functions(unsigned long addr);
71460
71461 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
71462-extern signed long schedule_timeout(signed long timeout);
71463+extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
71464 extern signed long schedule_timeout_interruptible(signed long timeout);
71465 extern signed long schedule_timeout_killable(signed long timeout);
71466 extern signed long schedule_timeout_uninterruptible(signed long timeout);
71467@@ -329,6 +330,18 @@ struct user_namespace;
71468 #include <linux/aio.h>
71469
71470 #ifdef CONFIG_MMU
71471+
71472+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
71473+extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
71474+#else
71475+static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
71476+{
71477+ return 0;
71478+}
71479+#endif
71480+
71481+extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
71482+extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
71483 extern void arch_pick_mmap_layout(struct mm_struct *mm);
71484 extern unsigned long
71485 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
71486@@ -605,6 +618,17 @@ struct signal_struct {
71487 #ifdef CONFIG_TASKSTATS
71488 struct taskstats *stats;
71489 #endif
71490+
71491+#ifdef CONFIG_GRKERNSEC
71492+ u32 curr_ip;
71493+ u32 saved_ip;
71494+ u32 gr_saddr;
71495+ u32 gr_daddr;
71496+ u16 gr_sport;
71497+ u16 gr_dport;
71498+ u8 used_accept:1;
71499+#endif
71500+
71501 #ifdef CONFIG_AUDIT
71502 unsigned audit_tty;
71503 struct tty_audit_buf *tty_audit_buf;
71504@@ -683,6 +707,11 @@ struct user_struct {
71505 struct key *session_keyring; /* UID's default session keyring */
71506 #endif
71507
71508+#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
71509+ unsigned int banned;
71510+ unsigned long ban_expires;
71511+#endif
71512+
71513 /* Hash table maintenance information */
71514 struct hlist_node uidhash_node;
71515 kuid_t uid;
71516@@ -1082,7 +1111,7 @@ struct sched_class {
71517 #ifdef CONFIG_FAIR_GROUP_SCHED
71518 void (*task_move_group) (struct task_struct *p, int on_rq);
71519 #endif
71520-};
71521+} __do_const;
71522
71523 struct load_weight {
71524 unsigned long weight, inv_weight;
71525@@ -1323,8 +1352,8 @@ struct task_struct {
71526 struct list_head thread_group;
71527
71528 struct completion *vfork_done; /* for vfork() */
71529- int __user *set_child_tid; /* CLONE_CHILD_SETTID */
71530- int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71531+ pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
71532+ pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
71533
71534 cputime_t utime, stime, utimescaled, stimescaled;
71535 cputime_t gtime;
71536@@ -1349,11 +1378,6 @@ struct task_struct {
71537 struct task_cputime cputime_expires;
71538 struct list_head cpu_timers[3];
71539
71540-/* process credentials */
71541- const struct cred __rcu *real_cred; /* objective and real subjective task
71542- * credentials (COW) */
71543- const struct cred __rcu *cred; /* effective (overridable) subjective task
71544- * credentials (COW) */
71545 char comm[TASK_COMM_LEN]; /* executable name excluding path
71546 - access with [gs]et_task_comm (which lock
71547 it with task_lock())
71548@@ -1370,6 +1394,10 @@ struct task_struct {
71549 #endif
71550 /* CPU-specific state of this task */
71551 struct thread_struct thread;
71552+/* thread_info moved to task_struct */
71553+#ifdef CONFIG_X86
71554+ struct thread_info tinfo;
71555+#endif
71556 /* filesystem information */
71557 struct fs_struct *fs;
71558 /* open file information */
71559@@ -1443,6 +1471,10 @@ struct task_struct {
71560 gfp_t lockdep_reclaim_gfp;
71561 #endif
71562
71563+/* process credentials */
71564+ const struct cred __rcu *real_cred; /* objective and real subjective task
71565+ * credentials (COW) */
71566+
71567 /* journalling filesystem info */
71568 void *journal_info;
71569
71570@@ -1481,6 +1513,10 @@ struct task_struct {
71571 /* cg_list protected by css_set_lock and tsk->alloc_lock */
71572 struct list_head cg_list;
71573 #endif
71574+
71575+ const struct cred __rcu *cred; /* effective (overridable) subjective task
71576+ * credentials (COW) */
71577+
71578 #ifdef CONFIG_FUTEX
71579 struct robust_list_head __user *robust_list;
71580 #ifdef CONFIG_COMPAT
71581@@ -1577,8 +1613,74 @@ struct task_struct {
71582 #ifdef CONFIG_UPROBES
71583 struct uprobe_task *utask;
71584 #endif
71585+
71586+#ifdef CONFIG_GRKERNSEC
71587+ /* grsecurity */
71588+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71589+ u64 exec_id;
71590+#endif
71591+#ifdef CONFIG_GRKERNSEC_SETXID
71592+ const struct cred *delayed_cred;
71593+#endif
71594+ struct dentry *gr_chroot_dentry;
71595+ struct acl_subject_label *acl;
71596+ struct acl_role_label *role;
71597+ struct file *exec_file;
71598+ unsigned long brute_expires;
71599+ u16 acl_role_id;
71600+ /* is this the task that authenticated to the special role */
71601+ u8 acl_sp_role;
71602+ u8 is_writable;
71603+ u8 brute;
71604+ u8 gr_is_chrooted;
71605+#endif
71606+
71607 };
71608
71609+#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
71610+#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
71611+#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
71612+#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
71613+/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
71614+#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
71615+
71616+#ifdef CONFIG_PAX_SOFTMODE
71617+extern int pax_softmode;
71618+#endif
71619+
71620+extern int pax_check_flags(unsigned long *);
71621+
71622+/* if tsk != current then task_lock must be held on it */
71623+#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
71624+static inline unsigned long pax_get_flags(struct task_struct *tsk)
71625+{
71626+ if (likely(tsk->mm))
71627+ return tsk->mm->pax_flags;
71628+ else
71629+ return 0UL;
71630+}
71631+
71632+/* if tsk != current then task_lock must be held on it */
71633+static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
71634+{
71635+ if (likely(tsk->mm)) {
71636+ tsk->mm->pax_flags = flags;
71637+ return 0;
71638+ }
71639+ return -EINVAL;
71640+}
71641+#endif
71642+
71643+#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
71644+extern void pax_set_initial_flags(struct linux_binprm *bprm);
71645+#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
71646+extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
71647+#endif
71648+
71649+extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
71650+extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
71651+extern void pax_report_refcount_overflow(struct pt_regs *regs);
71652+
71653 /* Future-safe accessor for struct task_struct's cpus_allowed. */
71654 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
71655
71656@@ -1637,7 +1739,7 @@ struct pid_namespace;
71657 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
71658 struct pid_namespace *ns);
71659
71660-static inline pid_t task_pid_nr(struct task_struct *tsk)
71661+static inline pid_t task_pid_nr(const struct task_struct *tsk)
71662 {
71663 return tsk->pid;
71664 }
71665@@ -2073,7 +2175,9 @@ void yield(void);
71666 extern struct exec_domain default_exec_domain;
71667
71668 union thread_union {
71669+#ifndef CONFIG_X86
71670 struct thread_info thread_info;
71671+#endif
71672 unsigned long stack[THREAD_SIZE/sizeof(long)];
71673 };
71674
71675@@ -2106,6 +2210,7 @@ extern struct pid_namespace init_pid_ns;
71676 */
71677
71678 extern struct task_struct *find_task_by_vpid(pid_t nr);
71679+extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
71680 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
71681 struct pid_namespace *ns);
71682
71683@@ -2272,7 +2377,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
71684 extern void exit_itimers(struct signal_struct *);
71685 extern void flush_itimer_signals(void);
71686
71687-extern void do_group_exit(int);
71688+extern __noreturn void do_group_exit(int);
71689
71690 extern int allow_signal(int);
71691 extern int disallow_signal(int);
71692@@ -2463,9 +2568,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
71693
71694 #endif
71695
71696-static inline int object_is_on_stack(void *obj)
71697+static inline int object_starts_on_stack(void *obj)
71698 {
71699- void *stack = task_stack_page(current);
71700+ const void *stack = task_stack_page(current);
71701
71702 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
71703 }
71704diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
71705index bf8086b..962b035 100644
71706--- a/include/linux/sched/sysctl.h
71707+++ b/include/linux/sched/sysctl.h
71708@@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
71709 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
71710
71711 extern int sysctl_max_map_count;
71712+extern unsigned long sysctl_heap_stack_gap;
71713
71714 extern unsigned int sysctl_sched_latency;
71715 extern unsigned int sysctl_sched_min_granularity;
71716diff --git a/include/linux/security.h b/include/linux/security.h
71717index 032c366..2c1c2dc2 100644
71718--- a/include/linux/security.h
71719+++ b/include/linux/security.h
71720@@ -26,6 +26,7 @@
71721 #include <linux/capability.h>
71722 #include <linux/slab.h>
71723 #include <linux/err.h>
71724+#include <linux/grsecurity.h>
71725
71726 struct linux_binprm;
71727 struct cred;
71728diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
71729index 68a04a3..866e6a1 100644
71730--- a/include/linux/seq_file.h
71731+++ b/include/linux/seq_file.h
71732@@ -26,6 +26,9 @@ struct seq_file {
71733 struct mutex lock;
71734 const struct seq_operations *op;
71735 int poll_event;
71736+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
71737+ u64 exec_id;
71738+#endif
71739 #ifdef CONFIG_USER_NS
71740 struct user_namespace *user_ns;
71741 #endif
71742@@ -38,6 +41,7 @@ struct seq_operations {
71743 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
71744 int (*show) (struct seq_file *m, void *v);
71745 };
71746+typedef struct seq_operations __no_const seq_operations_no_const;
71747
71748 #define SEQ_SKIP 1
71749
71750diff --git a/include/linux/shm.h b/include/linux/shm.h
71751index 429c199..4d42e38 100644
71752--- a/include/linux/shm.h
71753+++ b/include/linux/shm.h
71754@@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
71755
71756 /* The task created the shm object. NULL if the task is dead. */
71757 struct task_struct *shm_creator;
71758+#ifdef CONFIG_GRKERNSEC
71759+ time_t shm_createtime;
71760+ pid_t shm_lapid;
71761+#endif
71762 };
71763
71764 /* shm_mode upper byte flags */
71765diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
71766index 1f2803c..4858a3d 100644
71767--- a/include/linux/skbuff.h
71768+++ b/include/linux/skbuff.h
71769@@ -599,7 +599,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
71770 extern struct sk_buff *__alloc_skb(unsigned int size,
71771 gfp_t priority, int flags, int node);
71772 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
71773-static inline struct sk_buff *alloc_skb(unsigned int size,
71774+static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
71775 gfp_t priority)
71776 {
71777 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
71778@@ -709,7 +709,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
71779 */
71780 static inline int skb_queue_empty(const struct sk_buff_head *list)
71781 {
71782- return list->next == (struct sk_buff *)list;
71783+ return list->next == (const struct sk_buff *)list;
71784 }
71785
71786 /**
71787@@ -722,7 +722,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
71788 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71789 const struct sk_buff *skb)
71790 {
71791- return skb->next == (struct sk_buff *)list;
71792+ return skb->next == (const struct sk_buff *)list;
71793 }
71794
71795 /**
71796@@ -735,7 +735,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
71797 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
71798 const struct sk_buff *skb)
71799 {
71800- return skb->prev == (struct sk_buff *)list;
71801+ return skb->prev == (const struct sk_buff *)list;
71802 }
71803
71804 /**
71805@@ -1756,7 +1756,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
71806 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
71807 */
71808 #ifndef NET_SKB_PAD
71809-#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
71810+#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
71811 #endif
71812
71813 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
71814@@ -2351,7 +2351,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
71815 int noblock, int *err);
71816 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
71817 struct poll_table_struct *wait);
71818-extern int skb_copy_datagram_iovec(const struct sk_buff *from,
71819+extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
71820 int offset, struct iovec *to,
71821 int size);
71822 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
71823@@ -2641,6 +2641,9 @@ static inline void nf_reset(struct sk_buff *skb)
71824 nf_bridge_put(skb->nf_bridge);
71825 skb->nf_bridge = NULL;
71826 #endif
71827+#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
71828+ skb->nf_trace = 0;
71829+#endif
71830 }
71831
71832 static inline void nf_reset_trace(struct sk_buff *skb)
71833diff --git a/include/linux/slab.h b/include/linux/slab.h
71834index 5d168d7..720bff3 100644
71835--- a/include/linux/slab.h
71836+++ b/include/linux/slab.h
71837@@ -12,13 +12,20 @@
71838 #include <linux/gfp.h>
71839 #include <linux/types.h>
71840 #include <linux/workqueue.h>
71841-
71842+#include <linux/err.h>
71843
71844 /*
71845 * Flags to pass to kmem_cache_create().
71846 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
71847 */
71848 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
71849+
71850+#ifdef CONFIG_PAX_USERCOPY_SLABS
71851+#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
71852+#else
71853+#define SLAB_USERCOPY 0x00000000UL
71854+#endif
71855+
71856 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
71857 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
71858 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
71859@@ -89,10 +96,13 @@
71860 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
71861 * Both make kfree a no-op.
71862 */
71863-#define ZERO_SIZE_PTR ((void *)16)
71864+#define ZERO_SIZE_PTR \
71865+({ \
71866+ BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
71867+ (void *)(-MAX_ERRNO-1L); \
71868+})
71869
71870-#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
71871- (unsigned long)ZERO_SIZE_PTR)
71872+#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
71873
71874 /*
71875 * Common fields provided in kmem_cache by all slab allocators
71876@@ -112,7 +122,7 @@ struct kmem_cache {
71877 unsigned int align; /* Alignment as calculated */
71878 unsigned long flags; /* Active flags on the slab */
71879 const char *name; /* Slab name for sysfs */
71880- int refcount; /* Use counter */
71881+ atomic_t refcount; /* Use counter */
71882 void (*ctor)(void *); /* Called on object slot creation */
71883 struct list_head list; /* List of all slab caches on the system */
71884 };
71885@@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
71886 void kfree(const void *);
71887 void kzfree(const void *);
71888 size_t ksize(const void *);
71889+const char *check_heap_object(const void *ptr, unsigned long n);
71890+bool is_usercopy_object(const void *ptr);
71891
71892 /*
71893 * Allocator specific definitions. These are mainly used to establish optimized
71894@@ -311,6 +323,7 @@ size_t ksize(const void *);
71895 * for general use, and so are not documented here. For a full list of
71896 * potential flags, always refer to linux/gfp.h.
71897 */
71898+
71899 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
71900 {
71901 if (size != 0 && n > SIZE_MAX / size)
71902@@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
71903 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71904 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71905 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71906-extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71907+extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
71908 #define kmalloc_track_caller(size, flags) \
71909 __kmalloc_track_caller(size, flags, _RET_IP_)
71910 #else
71911@@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
71912 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
71913 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
71914 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
71915-extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
71916+extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
71917 #define kmalloc_node_track_caller(size, flags, node) \
71918 __kmalloc_node_track_caller(size, flags, node, \
71919 _RET_IP_)
71920diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
71921index 8bb6e0e..8eb0dbe 100644
71922--- a/include/linux/slab_def.h
71923+++ b/include/linux/slab_def.h
71924@@ -52,7 +52,7 @@ struct kmem_cache {
71925 /* 4) cache creation/removal */
71926 const char *name;
71927 struct list_head list;
71928- int refcount;
71929+ atomic_t refcount;
71930 int object_size;
71931 int align;
71932
71933@@ -68,10 +68,10 @@ struct kmem_cache {
71934 unsigned long node_allocs;
71935 unsigned long node_frees;
71936 unsigned long node_overflow;
71937- atomic_t allochit;
71938- atomic_t allocmiss;
71939- atomic_t freehit;
71940- atomic_t freemiss;
71941+ atomic_unchecked_t allochit;
71942+ atomic_unchecked_t allocmiss;
71943+ atomic_unchecked_t freehit;
71944+ atomic_unchecked_t freemiss;
71945
71946 /*
71947 * If debugging is enabled, then the allocator can add additional
71948@@ -111,11 +111,16 @@ struct cache_sizes {
71949 #ifdef CONFIG_ZONE_DMA
71950 struct kmem_cache *cs_dmacachep;
71951 #endif
71952+
71953+#ifdef CONFIG_PAX_USERCOPY_SLABS
71954+ struct kmem_cache *cs_usercopycachep;
71955+#endif
71956+
71957 };
71958 extern struct cache_sizes malloc_sizes[];
71959
71960 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
71961-void *__kmalloc(size_t size, gfp_t flags);
71962+void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
71963
71964 #ifdef CONFIG_TRACING
71965 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
71966@@ -152,6 +157,13 @@ found:
71967 cachep = malloc_sizes[i].cs_dmacachep;
71968 else
71969 #endif
71970+
71971+#ifdef CONFIG_PAX_USERCOPY_SLABS
71972+ if (flags & GFP_USERCOPY)
71973+ cachep = malloc_sizes[i].cs_usercopycachep;
71974+ else
71975+#endif
71976+
71977 cachep = malloc_sizes[i].cs_cachep;
71978
71979 ret = kmem_cache_alloc_trace(cachep, flags, size);
71980@@ -162,7 +174,7 @@ found:
71981 }
71982
71983 #ifdef CONFIG_NUMA
71984-extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
71985+extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
71986 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
71987
71988 #ifdef CONFIG_TRACING
71989@@ -205,6 +217,13 @@ found:
71990 cachep = malloc_sizes[i].cs_dmacachep;
71991 else
71992 #endif
71993+
71994+#ifdef CONFIG_PAX_USERCOPY_SLABS
71995+ if (flags & GFP_USERCOPY)
71996+ cachep = malloc_sizes[i].cs_usercopycachep;
71997+ else
71998+#endif
71999+
72000 cachep = malloc_sizes[i].cs_cachep;
72001
72002 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
72003diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
72004index f28e14a..7831211 100644
72005--- a/include/linux/slob_def.h
72006+++ b/include/linux/slob_def.h
72007@@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
72008 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
72009 }
72010
72011-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72012+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72013
72014 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
72015 {
72016@@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72017 return __kmalloc_node(size, flags, NUMA_NO_NODE);
72018 }
72019
72020-static __always_inline void *__kmalloc(size_t size, gfp_t flags)
72021+static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
72022 {
72023 return kmalloc(size, flags);
72024 }
72025diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
72026index 9db4825..ed42fb5 100644
72027--- a/include/linux/slub_def.h
72028+++ b/include/linux/slub_def.h
72029@@ -91,7 +91,7 @@ struct kmem_cache {
72030 struct kmem_cache_order_objects max;
72031 struct kmem_cache_order_objects min;
72032 gfp_t allocflags; /* gfp flags to use on each alloc */
72033- int refcount; /* Refcount for slab cache destroy */
72034+ atomic_t refcount; /* Refcount for slab cache destroy */
72035 void (*ctor)(void *);
72036 int inuse; /* Offset to metadata */
72037 int align; /* Alignment */
72038@@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
72039 * Sorry that the following has to be that ugly but some versions of GCC
72040 * have trouble with constant propagation and loops.
72041 */
72042-static __always_inline int kmalloc_index(size_t size)
72043+static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
72044 {
72045 if (!size)
72046 return 0;
72047@@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
72048 }
72049
72050 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
72051-void *__kmalloc(size_t size, gfp_t flags);
72052+void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
72053
72054 static __always_inline void *
72055 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
72056@@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
72057 }
72058 #endif
72059
72060-static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
72061+static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
72062 {
72063 unsigned int order = get_order(size);
72064 return kmalloc_order_trace(size, flags, order);
72065@@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
72066 }
72067
72068 #ifdef CONFIG_NUMA
72069-void *__kmalloc_node(size_t size, gfp_t flags, int node);
72070+void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
72071 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
72072
72073 #ifdef CONFIG_TRACING
72074diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
72075index e8d702e..0a56eb4 100644
72076--- a/include/linux/sock_diag.h
72077+++ b/include/linux/sock_diag.h
72078@@ -10,7 +10,7 @@ struct sock;
72079 struct sock_diag_handler {
72080 __u8 family;
72081 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
72082-};
72083+} __do_const;
72084
72085 int sock_diag_register(const struct sock_diag_handler *h);
72086 void sock_diag_unregister(const struct sock_diag_handler *h);
72087diff --git a/include/linux/sonet.h b/include/linux/sonet.h
72088index 680f9a3..f13aeb0 100644
72089--- a/include/linux/sonet.h
72090+++ b/include/linux/sonet.h
72091@@ -7,7 +7,7 @@
72092 #include <uapi/linux/sonet.h>
72093
72094 struct k_sonet_stats {
72095-#define __HANDLE_ITEM(i) atomic_t i
72096+#define __HANDLE_ITEM(i) atomic_unchecked_t i
72097 __SONET_ITEMS
72098 #undef __HANDLE_ITEM
72099 };
72100diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
72101index 07d8e53..dc934c9 100644
72102--- a/include/linux/sunrpc/addr.h
72103+++ b/include/linux/sunrpc/addr.h
72104@@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
72105 {
72106 switch (sap->sa_family) {
72107 case AF_INET:
72108- return ntohs(((struct sockaddr_in *)sap)->sin_port);
72109+ return ntohs(((const struct sockaddr_in *)sap)->sin_port);
72110 case AF_INET6:
72111- return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
72112+ return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
72113 }
72114 return 0;
72115 }
72116@@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
72117 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
72118 const struct sockaddr *src)
72119 {
72120- const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
72121+ const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
72122 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
72123
72124 dsin->sin_family = ssin->sin_family;
72125@@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
72126 if (sa->sa_family != AF_INET6)
72127 return 0;
72128
72129- return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
72130+ return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
72131 }
72132
72133 #endif /* _LINUX_SUNRPC_ADDR_H */
72134diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
72135index 2cf4ffa..470d140 100644
72136--- a/include/linux/sunrpc/clnt.h
72137+++ b/include/linux/sunrpc/clnt.h
72138@@ -96,7 +96,7 @@ struct rpc_procinfo {
72139 unsigned int p_timer; /* Which RTT timer to use */
72140 u32 p_statidx; /* Which procedure to account */
72141 const char * p_name; /* name of procedure */
72142-};
72143+} __do_const;
72144
72145 #ifdef __KERNEL__
72146
72147diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
72148index 1f0216b..6a4fa50 100644
72149--- a/include/linux/sunrpc/svc.h
72150+++ b/include/linux/sunrpc/svc.h
72151@@ -411,7 +411,7 @@ struct svc_procedure {
72152 unsigned int pc_count; /* call count */
72153 unsigned int pc_cachetype; /* cache info (NFS) */
72154 unsigned int pc_xdrressize; /* maximum size of XDR reply */
72155-};
72156+} __do_const;
72157
72158 /*
72159 * Function prototypes.
72160diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
72161index 0b8e3e6..33e0a01 100644
72162--- a/include/linux/sunrpc/svc_rdma.h
72163+++ b/include/linux/sunrpc/svc_rdma.h
72164@@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
72165 extern unsigned int svcrdma_max_requests;
72166 extern unsigned int svcrdma_max_req_size;
72167
72168-extern atomic_t rdma_stat_recv;
72169-extern atomic_t rdma_stat_read;
72170-extern atomic_t rdma_stat_write;
72171-extern atomic_t rdma_stat_sq_starve;
72172-extern atomic_t rdma_stat_rq_starve;
72173-extern atomic_t rdma_stat_rq_poll;
72174-extern atomic_t rdma_stat_rq_prod;
72175-extern atomic_t rdma_stat_sq_poll;
72176-extern atomic_t rdma_stat_sq_prod;
72177+extern atomic_unchecked_t rdma_stat_recv;
72178+extern atomic_unchecked_t rdma_stat_read;
72179+extern atomic_unchecked_t rdma_stat_write;
72180+extern atomic_unchecked_t rdma_stat_sq_starve;
72181+extern atomic_unchecked_t rdma_stat_rq_starve;
72182+extern atomic_unchecked_t rdma_stat_rq_poll;
72183+extern atomic_unchecked_t rdma_stat_rq_prod;
72184+extern atomic_unchecked_t rdma_stat_sq_poll;
72185+extern atomic_unchecked_t rdma_stat_sq_prod;
72186
72187 #define RPCRDMA_VERSION 1
72188
72189diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
72190index ff374ab..7fd2ecb 100644
72191--- a/include/linux/sunrpc/svcauth.h
72192+++ b/include/linux/sunrpc/svcauth.h
72193@@ -109,7 +109,7 @@ struct auth_ops {
72194 int (*release)(struct svc_rqst *rq);
72195 void (*domain_release)(struct auth_domain *);
72196 int (*set_client)(struct svc_rqst *rq);
72197-};
72198+} __do_const;
72199
72200 #define SVC_GARBAGE 1
72201 #define SVC_SYSERR 2
72202diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
72203index a5ffd32..0935dea 100644
72204--- a/include/linux/swiotlb.h
72205+++ b/include/linux/swiotlb.h
72206@@ -60,7 +60,8 @@ extern void
72207
72208 extern void
72209 swiotlb_free_coherent(struct device *hwdev, size_t size,
72210- void *vaddr, dma_addr_t dma_handle);
72211+ void *vaddr, dma_addr_t dma_handle,
72212+ struct dma_attrs *attrs);
72213
72214 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
72215 unsigned long offset, size_t size,
72216diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
72217index 313a8e0..6b273a9 100644
72218--- a/include/linux/syscalls.h
72219+++ b/include/linux/syscalls.h
72220@@ -418,11 +418,11 @@ asmlinkage long sys_sync(void);
72221 asmlinkage long sys_fsync(unsigned int fd);
72222 asmlinkage long sys_fdatasync(unsigned int fd);
72223 asmlinkage long sys_bdflush(int func, long data);
72224-asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
72225- char __user *type, unsigned long flags,
72226+asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
72227+ const char __user *type, unsigned long flags,
72228 void __user *data);
72229-asmlinkage long sys_umount(char __user *name, int flags);
72230-asmlinkage long sys_oldumount(char __user *name);
72231+asmlinkage long sys_umount(const char __user *name, int flags);
72232+asmlinkage long sys_oldumount(const char __user *name);
72233 asmlinkage long sys_truncate(const char __user *path, long length);
72234 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
72235 asmlinkage long sys_stat(const char __user *filename,
72236@@ -634,7 +634,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
72237 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
72238 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
72239 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
72240- struct sockaddr __user *, int);
72241+ struct sockaddr __user *, int) __intentional_overflow(0);
72242 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
72243 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
72244 unsigned int vlen, unsigned flags);
72245diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
72246index 27b3b0b..e093dd9 100644
72247--- a/include/linux/syscore_ops.h
72248+++ b/include/linux/syscore_ops.h
72249@@ -16,7 +16,7 @@ struct syscore_ops {
72250 int (*suspend)(void);
72251 void (*resume)(void);
72252 void (*shutdown)(void);
72253-};
72254+} __do_const;
72255
72256 extern void register_syscore_ops(struct syscore_ops *ops);
72257 extern void unregister_syscore_ops(struct syscore_ops *ops);
72258diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
72259index 14a8ff2..af52bad 100644
72260--- a/include/linux/sysctl.h
72261+++ b/include/linux/sysctl.h
72262@@ -34,13 +34,13 @@ struct ctl_table_root;
72263 struct ctl_table_header;
72264 struct ctl_dir;
72265
72266-typedef struct ctl_table ctl_table;
72267-
72268 typedef int proc_handler (struct ctl_table *ctl, int write,
72269 void __user *buffer, size_t *lenp, loff_t *ppos);
72270
72271 extern int proc_dostring(struct ctl_table *, int,
72272 void __user *, size_t *, loff_t *);
72273+extern int proc_dostring_modpriv(struct ctl_table *, int,
72274+ void __user *, size_t *, loff_t *);
72275 extern int proc_dointvec(struct ctl_table *, int,
72276 void __user *, size_t *, loff_t *);
72277 extern int proc_dointvec_minmax(struct ctl_table *, int,
72278@@ -115,7 +115,9 @@ struct ctl_table
72279 struct ctl_table_poll *poll;
72280 void *extra1;
72281 void *extra2;
72282-};
72283+} __do_const;
72284+typedef struct ctl_table __no_const ctl_table_no_const;
72285+typedef struct ctl_table ctl_table;
72286
72287 struct ctl_node {
72288 struct rb_node node;
72289diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
72290index e2cee22..3ddb921 100644
72291--- a/include/linux/sysfs.h
72292+++ b/include/linux/sysfs.h
72293@@ -31,7 +31,8 @@ struct attribute {
72294 struct lock_class_key *key;
72295 struct lock_class_key skey;
72296 #endif
72297-};
72298+} __do_const;
72299+typedef struct attribute __no_const attribute_no_const;
72300
72301 /**
72302 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
72303@@ -59,8 +60,8 @@ struct attribute_group {
72304 umode_t (*is_visible)(struct kobject *,
72305 struct attribute *, int);
72306 struct attribute **attrs;
72307-};
72308-
72309+} __do_const;
72310+typedef struct attribute_group __no_const attribute_group_no_const;
72311
72312
72313 /**
72314@@ -107,7 +108,8 @@ struct bin_attribute {
72315 char *, loff_t, size_t);
72316 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
72317 struct vm_area_struct *vma);
72318-};
72319+} __do_const;
72320+typedef struct bin_attribute __no_const bin_attribute_no_const;
72321
72322 /**
72323 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
72324diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
72325index 7faf933..9b85a0c 100644
72326--- a/include/linux/sysrq.h
72327+++ b/include/linux/sysrq.h
72328@@ -16,6 +16,7 @@
72329
72330 #include <linux/errno.h>
72331 #include <linux/types.h>
72332+#include <linux/compiler.h>
72333
72334 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
72335 #define SYSRQ_DEFAULT_ENABLE 1
72336@@ -36,7 +37,7 @@ struct sysrq_key_op {
72337 char *help_msg;
72338 char *action_msg;
72339 int enable_mask;
72340-};
72341+} __do_const;
72342
72343 #ifdef CONFIG_MAGIC_SYSRQ
72344
72345diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
72346index e7e0473..7989295 100644
72347--- a/include/linux/thread_info.h
72348+++ b/include/linux/thread_info.h
72349@@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
72350 #error "no set_restore_sigmask() provided and default one won't work"
72351 #endif
72352
72353+extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
72354+static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
72355+{
72356+#ifndef CONFIG_PAX_USERCOPY_DEBUG
72357+ if (!__builtin_constant_p(n))
72358+#endif
72359+ __check_object_size(ptr, n, to_user);
72360+}
72361+
72362 #endif /* __KERNEL__ */
72363
72364 #endif /* _LINUX_THREAD_INFO_H */
72365diff --git a/include/linux/tty.h b/include/linux/tty.h
72366index c75d886..04cb148 100644
72367--- a/include/linux/tty.h
72368+++ b/include/linux/tty.h
72369@@ -194,7 +194,7 @@ struct tty_port {
72370 const struct tty_port_operations *ops; /* Port operations */
72371 spinlock_t lock; /* Lock protecting tty field */
72372 int blocked_open; /* Waiting to open */
72373- int count; /* Usage count */
72374+ atomic_t count; /* Usage count */
72375 wait_queue_head_t open_wait; /* Open waiters */
72376 wait_queue_head_t close_wait; /* Close waiters */
72377 wait_queue_head_t delta_msr_wait; /* Modem status change */
72378@@ -515,7 +515,7 @@ extern int tty_port_open(struct tty_port *port,
72379 struct tty_struct *tty, struct file *filp);
72380 static inline int tty_port_users(struct tty_port *port)
72381 {
72382- return port->count + port->blocked_open;
72383+ return atomic_read(&port->count) + port->blocked_open;
72384 }
72385
72386 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
72387diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
72388index 756a609..b302dd6 100644
72389--- a/include/linux/tty_driver.h
72390+++ b/include/linux/tty_driver.h
72391@@ -285,7 +285,7 @@ struct tty_operations {
72392 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
72393 #endif
72394 const struct file_operations *proc_fops;
72395-};
72396+} __do_const;
72397
72398 struct tty_driver {
72399 int magic; /* magic number for this structure */
72400diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
72401index 455a0d7..bf97ff5 100644
72402--- a/include/linux/tty_ldisc.h
72403+++ b/include/linux/tty_ldisc.h
72404@@ -146,7 +146,7 @@ struct tty_ldisc_ops {
72405
72406 struct module *owner;
72407
72408- int refcount;
72409+ atomic_t refcount;
72410 };
72411
72412 struct tty_ldisc {
72413diff --git a/include/linux/types.h b/include/linux/types.h
72414index 4d118ba..c3ee9bf 100644
72415--- a/include/linux/types.h
72416+++ b/include/linux/types.h
72417@@ -176,10 +176,26 @@ typedef struct {
72418 int counter;
72419 } atomic_t;
72420
72421+#ifdef CONFIG_PAX_REFCOUNT
72422+typedef struct {
72423+ int counter;
72424+} atomic_unchecked_t;
72425+#else
72426+typedef atomic_t atomic_unchecked_t;
72427+#endif
72428+
72429 #ifdef CONFIG_64BIT
72430 typedef struct {
72431 long counter;
72432 } atomic64_t;
72433+
72434+#ifdef CONFIG_PAX_REFCOUNT
72435+typedef struct {
72436+ long counter;
72437+} atomic64_unchecked_t;
72438+#else
72439+typedef atomic64_t atomic64_unchecked_t;
72440+#endif
72441 #endif
72442
72443 struct list_head {
72444diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
72445index 5ca0951..ab496a5 100644
72446--- a/include/linux/uaccess.h
72447+++ b/include/linux/uaccess.h
72448@@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
72449 long ret; \
72450 mm_segment_t old_fs = get_fs(); \
72451 \
72452- set_fs(KERNEL_DS); \
72453 pagefault_disable(); \
72454- ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
72455- pagefault_enable(); \
72456+ set_fs(KERNEL_DS); \
72457+ ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
72458 set_fs(old_fs); \
72459+ pagefault_enable(); \
72460 ret; \
72461 })
72462
72463diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
72464index 8e522cbc..aa8572d 100644
72465--- a/include/linux/uidgid.h
72466+++ b/include/linux/uidgid.h
72467@@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
72468
72469 #endif /* CONFIG_USER_NS */
72470
72471+#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
72472+#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
72473+#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
72474+#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
72475+
72476 #endif /* _LINUX_UIDGID_H */
72477diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
72478index 99c1b4d..562e6f3 100644
72479--- a/include/linux/unaligned/access_ok.h
72480+++ b/include/linux/unaligned/access_ok.h
72481@@ -4,34 +4,34 @@
72482 #include <linux/kernel.h>
72483 #include <asm/byteorder.h>
72484
72485-static inline u16 get_unaligned_le16(const void *p)
72486+static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
72487 {
72488- return le16_to_cpup((__le16 *)p);
72489+ return le16_to_cpup((const __le16 *)p);
72490 }
72491
72492-static inline u32 get_unaligned_le32(const void *p)
72493+static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
72494 {
72495- return le32_to_cpup((__le32 *)p);
72496+ return le32_to_cpup((const __le32 *)p);
72497 }
72498
72499-static inline u64 get_unaligned_le64(const void *p)
72500+static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
72501 {
72502- return le64_to_cpup((__le64 *)p);
72503+ return le64_to_cpup((const __le64 *)p);
72504 }
72505
72506-static inline u16 get_unaligned_be16(const void *p)
72507+static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
72508 {
72509- return be16_to_cpup((__be16 *)p);
72510+ return be16_to_cpup((const __be16 *)p);
72511 }
72512
72513-static inline u32 get_unaligned_be32(const void *p)
72514+static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
72515 {
72516- return be32_to_cpup((__be32 *)p);
72517+ return be32_to_cpup((const __be32 *)p);
72518 }
72519
72520-static inline u64 get_unaligned_be64(const void *p)
72521+static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
72522 {
72523- return be64_to_cpup((__be64 *)p);
72524+ return be64_to_cpup((const __be64 *)p);
72525 }
72526
72527 static inline void put_unaligned_le16(u16 val, void *p)
72528diff --git a/include/linux/usb.h b/include/linux/usb.h
72529index 4d22d0f..8d0e8f8 100644
72530--- a/include/linux/usb.h
72531+++ b/include/linux/usb.h
72532@@ -554,7 +554,7 @@ struct usb_device {
72533 int maxchild;
72534
72535 u32 quirks;
72536- atomic_t urbnum;
72537+ atomic_unchecked_t urbnum;
72538
72539 unsigned long active_duration;
72540
72541@@ -1604,7 +1604,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
72542
72543 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
72544 __u8 request, __u8 requesttype, __u16 value, __u16 index,
72545- void *data, __u16 size, int timeout);
72546+ void *data, __u16 size, int timeout) __intentional_overflow(-1);
72547 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
72548 void *data, int len, int *actual_length, int timeout);
72549 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
72550diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
72551index c5d36c6..108f4f9 100644
72552--- a/include/linux/usb/renesas_usbhs.h
72553+++ b/include/linux/usb/renesas_usbhs.h
72554@@ -39,7 +39,7 @@ enum {
72555 */
72556 struct renesas_usbhs_driver_callback {
72557 int (*notify_hotplug)(struct platform_device *pdev);
72558-};
72559+} __no_const;
72560
72561 /*
72562 * callback functions for platform
72563diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
72564index 6f8fbcf..8259001 100644
72565--- a/include/linux/vermagic.h
72566+++ b/include/linux/vermagic.h
72567@@ -25,9 +25,35 @@
72568 #define MODULE_ARCH_VERMAGIC ""
72569 #endif
72570
72571+#ifdef CONFIG_PAX_REFCOUNT
72572+#define MODULE_PAX_REFCOUNT "REFCOUNT "
72573+#else
72574+#define MODULE_PAX_REFCOUNT ""
72575+#endif
72576+
72577+#ifdef CONSTIFY_PLUGIN
72578+#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
72579+#else
72580+#define MODULE_CONSTIFY_PLUGIN ""
72581+#endif
72582+
72583+#ifdef STACKLEAK_PLUGIN
72584+#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
72585+#else
72586+#define MODULE_STACKLEAK_PLUGIN ""
72587+#endif
72588+
72589+#ifdef CONFIG_GRKERNSEC
72590+#define MODULE_GRSEC "GRSEC "
72591+#else
72592+#define MODULE_GRSEC ""
72593+#endif
72594+
72595 #define VERMAGIC_STRING \
72596 UTS_RELEASE " " \
72597 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
72598 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
72599- MODULE_ARCH_VERMAGIC
72600+ MODULE_ARCH_VERMAGIC \
72601+ MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
72602+ MODULE_GRSEC
72603
72604diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
72605index 6071e91..4c73b47 100644
72606--- a/include/linux/vmalloc.h
72607+++ b/include/linux/vmalloc.h
72608@@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
72609 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
72610 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
72611 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
72612+
72613+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
72614+#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
72615+#endif
72616+
72617 /* bits [20..32] reserved for arch specific ioremap internals */
72618
72619 /*
72620@@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
72621 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
72622 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
72623 unsigned long start, unsigned long end, gfp_t gfp_mask,
72624- pgprot_t prot, int node, const void *caller);
72625+ pgprot_t prot, int node, const void *caller) __size_overflow(1);
72626 extern void vfree(const void *addr);
72627
72628 extern void *vmap(struct page **pages, unsigned int count,
72629@@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
72630 extern void free_vm_area(struct vm_struct *area);
72631
72632 /* for /dev/kmem */
72633-extern long vread(char *buf, char *addr, unsigned long count);
72634-extern long vwrite(char *buf, char *addr, unsigned long count);
72635+extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
72636+extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
72637
72638 /*
72639 * Internals. Dont't use..
72640diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
72641index 5fd71a7..e5ef9a9 100644
72642--- a/include/linux/vmstat.h
72643+++ b/include/linux/vmstat.h
72644@@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
72645 /*
72646 * Zone based page accounting with per cpu differentials.
72647 */
72648-extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72649+extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
72650
72651 static inline void zone_page_state_add(long x, struct zone *zone,
72652 enum zone_stat_item item)
72653 {
72654- atomic_long_add(x, &zone->vm_stat[item]);
72655- atomic_long_add(x, &vm_stat[item]);
72656+ atomic_long_add_unchecked(x, &zone->vm_stat[item]);
72657+ atomic_long_add_unchecked(x, &vm_stat[item]);
72658 }
72659
72660 static inline unsigned long global_page_state(enum zone_stat_item item)
72661 {
72662- long x = atomic_long_read(&vm_stat[item]);
72663+ long x = atomic_long_read_unchecked(&vm_stat[item]);
72664 #ifdef CONFIG_SMP
72665 if (x < 0)
72666 x = 0;
72667@@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
72668 static inline unsigned long zone_page_state(struct zone *zone,
72669 enum zone_stat_item item)
72670 {
72671- long x = atomic_long_read(&zone->vm_stat[item]);
72672+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72673 #ifdef CONFIG_SMP
72674 if (x < 0)
72675 x = 0;
72676@@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
72677 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
72678 enum zone_stat_item item)
72679 {
72680- long x = atomic_long_read(&zone->vm_stat[item]);
72681+ long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
72682
72683 #ifdef CONFIG_SMP
72684 int cpu;
72685@@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
72686
72687 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
72688 {
72689- atomic_long_inc(&zone->vm_stat[item]);
72690- atomic_long_inc(&vm_stat[item]);
72691+ atomic_long_inc_unchecked(&zone->vm_stat[item]);
72692+ atomic_long_inc_unchecked(&vm_stat[item]);
72693 }
72694
72695 static inline void __inc_zone_page_state(struct page *page,
72696@@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
72697
72698 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
72699 {
72700- atomic_long_dec(&zone->vm_stat[item]);
72701- atomic_long_dec(&vm_stat[item]);
72702+ atomic_long_dec_unchecked(&zone->vm_stat[item]);
72703+ atomic_long_dec_unchecked(&vm_stat[item]);
72704 }
72705
72706 static inline void __dec_zone_page_state(struct page *page,
72707diff --git a/include/linux/xattr.h b/include/linux/xattr.h
72708index fdbafc6..49dfe4f 100644
72709--- a/include/linux/xattr.h
72710+++ b/include/linux/xattr.h
72711@@ -28,7 +28,7 @@ struct xattr_handler {
72712 size_t size, int handler_flags);
72713 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
72714 size_t size, int flags, int handler_flags);
72715-};
72716+} __do_const;
72717
72718 struct xattr {
72719 char *name;
72720@@ -37,6 +37,9 @@ struct xattr {
72721 };
72722
72723 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
72724+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
72725+ssize_t pax_getxattr(struct dentry *, void *, size_t);
72726+#endif
72727 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
72728 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
72729 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
72730diff --git a/include/linux/zlib.h b/include/linux/zlib.h
72731index 9c5a6b4..09c9438 100644
72732--- a/include/linux/zlib.h
72733+++ b/include/linux/zlib.h
72734@@ -31,6 +31,7 @@
72735 #define _ZLIB_H
72736
72737 #include <linux/zconf.h>
72738+#include <linux/compiler.h>
72739
72740 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
72741 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
72742@@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
72743
72744 /* basic functions */
72745
72746-extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
72747+extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
72748 /*
72749 Returns the number of bytes that needs to be allocated for a per-
72750 stream workspace with the specified parameters. A pointer to this
72751diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
72752index 95d1c91..6798cca 100644
72753--- a/include/media/v4l2-dev.h
72754+++ b/include/media/v4l2-dev.h
72755@@ -76,7 +76,7 @@ struct v4l2_file_operations {
72756 int (*mmap) (struct file *, struct vm_area_struct *);
72757 int (*open) (struct file *);
72758 int (*release) (struct file *);
72759-};
72760+} __do_const;
72761
72762 /*
72763 * Newer version of video_device, handled by videodev2.c
72764diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
72765index 4118ad1..cb7e25f 100644
72766--- a/include/media/v4l2-ioctl.h
72767+++ b/include/media/v4l2-ioctl.h
72768@@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
72769 bool valid_prio, int cmd, void *arg);
72770 };
72771
72772-
72773 /* v4l debugging and diagnostics */
72774
72775 /* Debug bitmask flags to be used on V4L2 */
72776diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
72777index adcbb20..62c2559 100644
72778--- a/include/net/9p/transport.h
72779+++ b/include/net/9p/transport.h
72780@@ -57,7 +57,7 @@ struct p9_trans_module {
72781 int (*cancel) (struct p9_client *, struct p9_req_t *req);
72782 int (*zc_request)(struct p9_client *, struct p9_req_t *,
72783 char *, char *, int , int, int, int);
72784-};
72785+} __do_const;
72786
72787 void v9fs_register_trans(struct p9_trans_module *m);
72788 void v9fs_unregister_trans(struct p9_trans_module *m);
72789diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
72790index cdd3302..76f8ede 100644
72791--- a/include/net/bluetooth/l2cap.h
72792+++ b/include/net/bluetooth/l2cap.h
72793@@ -551,7 +551,7 @@ struct l2cap_ops {
72794 void (*defer) (struct l2cap_chan *chan);
72795 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
72796 unsigned long len, int nb);
72797-};
72798+} __do_const;
72799
72800 struct l2cap_conn {
72801 struct hci_conn *hcon;
72802diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
72803index 9e5425b..8136ffc 100644
72804--- a/include/net/caif/cfctrl.h
72805+++ b/include/net/caif/cfctrl.h
72806@@ -52,7 +52,7 @@ struct cfctrl_rsp {
72807 void (*radioset_rsp)(void);
72808 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
72809 struct cflayer *client_layer);
72810-};
72811+} __no_const;
72812
72813 /* Link Setup Parameters for CAIF-Links. */
72814 struct cfctrl_link_param {
72815@@ -101,8 +101,8 @@ struct cfctrl_request_info {
72816 struct cfctrl {
72817 struct cfsrvl serv;
72818 struct cfctrl_rsp res;
72819- atomic_t req_seq_no;
72820- atomic_t rsp_seq_no;
72821+ atomic_unchecked_t req_seq_no;
72822+ atomic_unchecked_t rsp_seq_no;
72823 struct list_head list;
72824 /* Protects from simultaneous access to first_req list */
72825 spinlock_t info_list_lock;
72826diff --git a/include/net/flow.h b/include/net/flow.h
72827index 628e11b..4c475df 100644
72828--- a/include/net/flow.h
72829+++ b/include/net/flow.h
72830@@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
72831
72832 extern void flow_cache_flush(void);
72833 extern void flow_cache_flush_deferred(void);
72834-extern atomic_t flow_cache_genid;
72835+extern atomic_unchecked_t flow_cache_genid;
72836
72837 #endif
72838diff --git a/include/net/genetlink.h b/include/net/genetlink.h
72839index bdfbe68..4402ebe 100644
72840--- a/include/net/genetlink.h
72841+++ b/include/net/genetlink.h
72842@@ -118,7 +118,7 @@ struct genl_ops {
72843 struct netlink_callback *cb);
72844 int (*done)(struct netlink_callback *cb);
72845 struct list_head ops_list;
72846-};
72847+} __do_const;
72848
72849 extern int genl_register_family(struct genl_family *family);
72850 extern int genl_register_family_with_ops(struct genl_family *family,
72851diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
72852index 734d9b5..48a9a4b 100644
72853--- a/include/net/gro_cells.h
72854+++ b/include/net/gro_cells.h
72855@@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
72856 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
72857
72858 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
72859- atomic_long_inc(&dev->rx_dropped);
72860+ atomic_long_inc_unchecked(&dev->rx_dropped);
72861 kfree_skb(skb);
72862 return;
72863 }
72864diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
72865index 1832927..ce39aea 100644
72866--- a/include/net/inet_connection_sock.h
72867+++ b/include/net/inet_connection_sock.h
72868@@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
72869 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
72870 int (*bind_conflict)(const struct sock *sk,
72871 const struct inet_bind_bucket *tb, bool relax);
72872-};
72873+} __do_const;
72874
72875 /** inet_connection_sock - INET connection oriented sock
72876 *
72877diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
72878index 53f464d..ba76aaa 100644
72879--- a/include/net/inetpeer.h
72880+++ b/include/net/inetpeer.h
72881@@ -47,8 +47,8 @@ struct inet_peer {
72882 */
72883 union {
72884 struct {
72885- atomic_t rid; /* Frag reception counter */
72886- atomic_t ip_id_count; /* IP ID for the next packet */
72887+ atomic_unchecked_t rid; /* Frag reception counter */
72888+ atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
72889 };
72890 struct rcu_head rcu;
72891 struct inet_peer *gc_next;
72892@@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
72893 more++;
72894 inet_peer_refcheck(p);
72895 do {
72896- old = atomic_read(&p->ip_id_count);
72897+ old = atomic_read_unchecked(&p->ip_id_count);
72898 new = old + more;
72899 if (!new)
72900 new = 1;
72901- } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
72902+ } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
72903 return new;
72904 }
72905
72906diff --git a/include/net/ip.h b/include/net/ip.h
72907index a68f838..74518ab 100644
72908--- a/include/net/ip.h
72909+++ b/include/net/ip.h
72910@@ -202,7 +202,7 @@ extern struct local_ports {
72911 } sysctl_local_ports;
72912 extern void inet_get_local_port_range(int *low, int *high);
72913
72914-extern unsigned long *sysctl_local_reserved_ports;
72915+extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
72916 static inline int inet_is_reserved_local_port(int port)
72917 {
72918 return test_bit(port, sysctl_local_reserved_ports);
72919diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
72920index e49db91..76a81de 100644
72921--- a/include/net/ip_fib.h
72922+++ b/include/net/ip_fib.h
72923@@ -167,7 +167,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
72924
72925 #define FIB_RES_SADDR(net, res) \
72926 ((FIB_RES_NH(res).nh_saddr_genid == \
72927- atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
72928+ atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
72929 FIB_RES_NH(res).nh_saddr : \
72930 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
72931 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
72932diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
72933index fce8e6b..3ca4916 100644
72934--- a/include/net/ip_vs.h
72935+++ b/include/net/ip_vs.h
72936@@ -599,7 +599,7 @@ struct ip_vs_conn {
72937 struct ip_vs_conn *control; /* Master control connection */
72938 atomic_t n_control; /* Number of controlled ones */
72939 struct ip_vs_dest *dest; /* real server */
72940- atomic_t in_pkts; /* incoming packet counter */
72941+ atomic_unchecked_t in_pkts; /* incoming packet counter */
72942
72943 /* packet transmitter for different forwarding methods. If it
72944 mangles the packet, it must return NF_DROP or better NF_STOLEN,
72945@@ -737,7 +737,7 @@ struct ip_vs_dest {
72946 __be16 port; /* port number of the server */
72947 union nf_inet_addr addr; /* IP address of the server */
72948 volatile unsigned int flags; /* dest status flags */
72949- atomic_t conn_flags; /* flags to copy to conn */
72950+ atomic_unchecked_t conn_flags; /* flags to copy to conn */
72951 atomic_t weight; /* server weight */
72952
72953 atomic_t refcnt; /* reference counter */
72954@@ -981,11 +981,11 @@ struct netns_ipvs {
72955 /* ip_vs_lblc */
72956 int sysctl_lblc_expiration;
72957 struct ctl_table_header *lblc_ctl_header;
72958- struct ctl_table *lblc_ctl_table;
72959+ ctl_table_no_const *lblc_ctl_table;
72960 /* ip_vs_lblcr */
72961 int sysctl_lblcr_expiration;
72962 struct ctl_table_header *lblcr_ctl_header;
72963- struct ctl_table *lblcr_ctl_table;
72964+ ctl_table_no_const *lblcr_ctl_table;
72965 /* ip_vs_est */
72966 struct list_head est_list; /* estimator list */
72967 spinlock_t est_lock;
72968diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
72969index 80ffde3..968b0f4 100644
72970--- a/include/net/irda/ircomm_tty.h
72971+++ b/include/net/irda/ircomm_tty.h
72972@@ -35,6 +35,7 @@
72973 #include <linux/termios.h>
72974 #include <linux/timer.h>
72975 #include <linux/tty.h> /* struct tty_struct */
72976+#include <asm/local.h>
72977
72978 #include <net/irda/irias_object.h>
72979 #include <net/irda/ircomm_core.h>
72980diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
72981index 714cc9a..ea05f3e 100644
72982--- a/include/net/iucv/af_iucv.h
72983+++ b/include/net/iucv/af_iucv.h
72984@@ -149,7 +149,7 @@ struct iucv_skb_cb {
72985 struct iucv_sock_list {
72986 struct hlist_head head;
72987 rwlock_t lock;
72988- atomic_t autobind_name;
72989+ atomic_unchecked_t autobind_name;
72990 };
72991
72992 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
72993diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
72994index df83f69..9b640b8 100644
72995--- a/include/net/llc_c_ac.h
72996+++ b/include/net/llc_c_ac.h
72997@@ -87,7 +87,7 @@
72998 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
72999 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
73000
73001-typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73002+typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
73003
73004 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
73005 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
73006diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
73007index 6ca3113..f8026dd 100644
73008--- a/include/net/llc_c_ev.h
73009+++ b/include/net/llc_c_ev.h
73010@@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
73011 return (struct llc_conn_state_ev *)skb->cb;
73012 }
73013
73014-typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73015-typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73016+typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
73017+typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
73018
73019 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
73020 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
73021diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
73022index 0e79cfb..f46db31 100644
73023--- a/include/net/llc_c_st.h
73024+++ b/include/net/llc_c_st.h
73025@@ -37,7 +37,7 @@ struct llc_conn_state_trans {
73026 u8 next_state;
73027 llc_conn_ev_qfyr_t *ev_qualifiers;
73028 llc_conn_action_t *ev_actions;
73029-};
73030+} __do_const;
73031
73032 struct llc_conn_state {
73033 u8 current_state;
73034diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
73035index 37a3bbd..55a4241 100644
73036--- a/include/net/llc_s_ac.h
73037+++ b/include/net/llc_s_ac.h
73038@@ -23,7 +23,7 @@
73039 #define SAP_ACT_TEST_IND 9
73040
73041 /* All action functions must look like this */
73042-typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73043+typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
73044
73045 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
73046 struct sk_buff *skb);
73047diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
73048index 567c681..cd73ac0 100644
73049--- a/include/net/llc_s_st.h
73050+++ b/include/net/llc_s_st.h
73051@@ -20,7 +20,7 @@ struct llc_sap_state_trans {
73052 llc_sap_ev_t ev;
73053 u8 next_state;
73054 llc_sap_action_t *ev_actions;
73055-};
73056+} __do_const;
73057
73058 struct llc_sap_state {
73059 u8 curr_state;
73060diff --git a/include/net/mac80211.h b/include/net/mac80211.h
73061index f7eba13..91ed983 100644
73062--- a/include/net/mac80211.h
73063+++ b/include/net/mac80211.h
73064@@ -4119,7 +4119,7 @@ struct rate_control_ops {
73065 void (*add_sta_debugfs)(void *priv, void *priv_sta,
73066 struct dentry *dir);
73067 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
73068-};
73069+} __do_const;
73070
73071 static inline int rate_supported(struct ieee80211_sta *sta,
73072 enum ieee80211_band band,
73073diff --git a/include/net/neighbour.h b/include/net/neighbour.h
73074index 7e748ad..5c6229b 100644
73075--- a/include/net/neighbour.h
73076+++ b/include/net/neighbour.h
73077@@ -123,7 +123,7 @@ struct neigh_ops {
73078 void (*error_report)(struct neighbour *, struct sk_buff *);
73079 int (*output)(struct neighbour *, struct sk_buff *);
73080 int (*connected_output)(struct neighbour *, struct sk_buff *);
73081-};
73082+} __do_const;
73083
73084 struct pneigh_entry {
73085 struct pneigh_entry *next;
73086diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
73087index de644bc..dfbcc4c 100644
73088--- a/include/net/net_namespace.h
73089+++ b/include/net/net_namespace.h
73090@@ -115,7 +115,7 @@ struct net {
73091 #endif
73092 struct netns_ipvs *ipvs;
73093 struct sock *diag_nlsk;
73094- atomic_t rt_genid;
73095+ atomic_unchecked_t rt_genid;
73096 };
73097
73098 /*
73099@@ -272,7 +272,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
73100 #define __net_init __init
73101 #define __net_exit __exit_refok
73102 #define __net_initdata __initdata
73103+#ifdef CONSTIFY_PLUGIN
73104 #define __net_initconst __initconst
73105+#else
73106+#define __net_initconst __initdata
73107+#endif
73108 #endif
73109
73110 struct pernet_operations {
73111@@ -282,7 +286,7 @@ struct pernet_operations {
73112 void (*exit_batch)(struct list_head *net_exit_list);
73113 int *id;
73114 size_t size;
73115-};
73116+} __do_const;
73117
73118 /*
73119 * Use these carefully. If you implement a network device and it
73120@@ -330,12 +334,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
73121
73122 static inline int rt_genid(struct net *net)
73123 {
73124- return atomic_read(&net->rt_genid);
73125+ return atomic_read_unchecked(&net->rt_genid);
73126 }
73127
73128 static inline void rt_genid_bump(struct net *net)
73129 {
73130- atomic_inc(&net->rt_genid);
73131+ atomic_inc_unchecked(&net->rt_genid);
73132 }
73133
73134 #endif /* __NET_NET_NAMESPACE_H */
73135diff --git a/include/net/netdma.h b/include/net/netdma.h
73136index 8ba8ce2..99b7fff 100644
73137--- a/include/net/netdma.h
73138+++ b/include/net/netdma.h
73139@@ -24,7 +24,7 @@
73140 #include <linux/dmaengine.h>
73141 #include <linux/skbuff.h>
73142
73143-int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73144+int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
73145 struct sk_buff *skb, int offset, struct iovec *to,
73146 size_t len, struct dma_pinned_list *pinned_list);
73147
73148diff --git a/include/net/netlink.h b/include/net/netlink.h
73149index 9690b0f..87aded7 100644
73150--- a/include/net/netlink.h
73151+++ b/include/net/netlink.h
73152@@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
73153 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
73154 {
73155 if (mark)
73156- skb_trim(skb, (unsigned char *) mark - skb->data);
73157+ skb_trim(skb, (const unsigned char *) mark - skb->data);
73158 }
73159
73160 /**
73161diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
73162index c9c0c53..53f24c3 100644
73163--- a/include/net/netns/conntrack.h
73164+++ b/include/net/netns/conntrack.h
73165@@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
73166 struct nf_proto_net {
73167 #ifdef CONFIG_SYSCTL
73168 struct ctl_table_header *ctl_table_header;
73169- struct ctl_table *ctl_table;
73170+ ctl_table_no_const *ctl_table;
73171 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
73172 struct ctl_table_header *ctl_compat_header;
73173- struct ctl_table *ctl_compat_table;
73174+ ctl_table_no_const *ctl_compat_table;
73175 #endif
73176 #endif
73177 unsigned int users;
73178@@ -58,7 +58,7 @@ struct nf_ip_net {
73179 struct nf_icmp_net icmpv6;
73180 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
73181 struct ctl_table_header *ctl_table_header;
73182- struct ctl_table *ctl_table;
73183+ ctl_table_no_const *ctl_table;
73184 #endif
73185 };
73186
73187diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
73188index 2ba9de8..47bd6c7 100644
73189--- a/include/net/netns/ipv4.h
73190+++ b/include/net/netns/ipv4.h
73191@@ -67,7 +67,7 @@ struct netns_ipv4 {
73192 kgid_t sysctl_ping_group_range[2];
73193 long sysctl_tcp_mem[3];
73194
73195- atomic_t dev_addr_genid;
73196+ atomic_unchecked_t dev_addr_genid;
73197
73198 #ifdef CONFIG_IP_MROUTE
73199 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
73200diff --git a/include/net/protocol.h b/include/net/protocol.h
73201index 047c047..b9dad15 100644
73202--- a/include/net/protocol.h
73203+++ b/include/net/protocol.h
73204@@ -44,7 +44,7 @@ struct net_protocol {
73205 void (*err_handler)(struct sk_buff *skb, u32 info);
73206 unsigned int no_policy:1,
73207 netns_ok:1;
73208-};
73209+} __do_const;
73210
73211 #if IS_ENABLED(CONFIG_IPV6)
73212 struct inet6_protocol {
73213@@ -57,7 +57,7 @@ struct inet6_protocol {
73214 u8 type, u8 code, int offset,
73215 __be32 info);
73216 unsigned int flags; /* INET6_PROTO_xxx */
73217-};
73218+} __do_const;
73219
73220 #define INET6_PROTO_NOPOLICY 0x1
73221 #define INET6_PROTO_FINAL 0x2
73222diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
73223index 5a15fab..d799ea7 100644
73224--- a/include/net/rtnetlink.h
73225+++ b/include/net/rtnetlink.h
73226@@ -81,7 +81,7 @@ struct rtnl_link_ops {
73227 const struct net_device *dev);
73228 unsigned int (*get_num_tx_queues)(void);
73229 unsigned int (*get_num_rx_queues)(void);
73230-};
73231+} __do_const;
73232
73233 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
73234 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
73235diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
73236index df85a0c..19ac300 100644
73237--- a/include/net/sctp/sctp.h
73238+++ b/include/net/sctp/sctp.h
73239@@ -330,9 +330,9 @@ do { \
73240
73241 #else /* SCTP_DEBUG */
73242
73243-#define SCTP_DEBUG_PRINTK(whatever...)
73244-#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
73245-#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
73246+#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
73247+#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
73248+#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
73249 #define SCTP_ENABLE_DEBUG
73250 #define SCTP_DISABLE_DEBUG
73251 #define SCTP_ASSERT(expr, str, func)
73252diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
73253index 2a82d13..62a31c2 100644
73254--- a/include/net/sctp/sm.h
73255+++ b/include/net/sctp/sm.h
73256@@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
73257 typedef struct {
73258 sctp_state_fn_t *fn;
73259 const char *name;
73260-} sctp_sm_table_entry_t;
73261+} __do_const sctp_sm_table_entry_t;
73262
73263 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
73264 * currently in use.
73265@@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
73266 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
73267
73268 /* Extern declarations for major data structures. */
73269-extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73270+extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
73271
73272
73273 /* Get the size of a DATA chunk payload. */
73274diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
73275index 0e0f9d2..cd05ebb 100644
73276--- a/include/net/sctp/structs.h
73277+++ b/include/net/sctp/structs.h
73278@@ -517,7 +517,7 @@ struct sctp_pf {
73279 struct sctp_association *asoc);
73280 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
73281 struct sctp_af *af;
73282-};
73283+} __do_const;
73284
73285
73286 /* Structure to track chunk fragments that have been acked, but peer
73287diff --git a/include/net/secure_seq.h b/include/net/secure_seq.h
73288index c2e542b..6ca975b 100644
73289--- a/include/net/secure_seq.h
73290+++ b/include/net/secure_seq.h
73291@@ -3,6 +3,7 @@
73292
73293 #include <linux/types.h>
73294
73295+extern void net_secret_init(void);
73296 extern __u32 secure_ip_id(__be32 daddr);
73297 extern __u32 secure_ipv6_id(const __be32 daddr[4]);
73298 extern u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport);
73299diff --git a/include/net/sock.h b/include/net/sock.h
73300index 0be480a..586232f 100644
73301--- a/include/net/sock.h
73302+++ b/include/net/sock.h
73303@@ -325,7 +325,7 @@ struct sock {
73304 #ifdef CONFIG_RPS
73305 __u32 sk_rxhash;
73306 #endif
73307- atomic_t sk_drops;
73308+ atomic_unchecked_t sk_drops;
73309 int sk_rcvbuf;
73310
73311 struct sk_filter __rcu *sk_filter;
73312@@ -1796,7 +1796,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
73313 }
73314
73315 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
73316- char __user *from, char *to,
73317+ char __user *from, unsigned char *to,
73318 int copy, int offset)
73319 {
73320 if (skb->ip_summed == CHECKSUM_NONE) {
73321@@ -2055,7 +2055,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
73322 }
73323 }
73324
73325-struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73326+struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
73327
73328 /**
73329 * sk_page_frag - return an appropriate page_frag
73330diff --git a/include/net/tcp.h b/include/net/tcp.h
73331index a345480..3c65cf4 100644
73332--- a/include/net/tcp.h
73333+++ b/include/net/tcp.h
73334@@ -529,7 +529,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
73335 extern void tcp_xmit_retransmit_queue(struct sock *);
73336 extern void tcp_simple_retransmit(struct sock *);
73337 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
73338-extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73339+extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
73340
73341 extern void tcp_send_probe0(struct sock *);
73342 extern void tcp_send_partial(struct sock *);
73343@@ -700,8 +700,8 @@ struct tcp_skb_cb {
73344 struct inet6_skb_parm h6;
73345 #endif
73346 } header; /* For incoming frames */
73347- __u32 seq; /* Starting sequence number */
73348- __u32 end_seq; /* SEQ + FIN + SYN + datalen */
73349+ __u32 seq __intentional_overflow(0); /* Starting sequence number */
73350+ __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
73351 __u32 when; /* used to compute rtt's */
73352 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
73353
73354@@ -715,7 +715,7 @@ struct tcp_skb_cb {
73355
73356 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
73357 /* 1 byte hole */
73358- __u32 ack_seq; /* Sequence number ACK'd */
73359+ __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
73360 };
73361
73362 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
73363diff --git a/include/net/xfrm.h b/include/net/xfrm.h
73364index 24c8886..e6fb816 100644
73365--- a/include/net/xfrm.h
73366+++ b/include/net/xfrm.h
73367@@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
73368 struct net_device *dev,
73369 const struct flowi *fl);
73370 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
73371-};
73372+} __do_const;
73373
73374 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
73375 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
73376@@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
73377 struct sk_buff *skb);
73378 int (*transport_finish)(struct sk_buff *skb,
73379 int async);
73380-};
73381+} __do_const;
73382
73383 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
73384 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
73385@@ -423,7 +423,7 @@ struct xfrm_mode {
73386 struct module *owner;
73387 unsigned int encap;
73388 int flags;
73389-};
73390+} __do_const;
73391
73392 /* Flags for xfrm_mode. */
73393 enum {
73394@@ -520,7 +520,7 @@ struct xfrm_policy {
73395 struct timer_list timer;
73396
73397 struct flow_cache_object flo;
73398- atomic_t genid;
73399+ atomic_unchecked_t genid;
73400 u32 priority;
73401 u32 index;
73402 struct xfrm_mark mark;
73403diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
73404index 1a046b1..ee0bef0 100644
73405--- a/include/rdma/iw_cm.h
73406+++ b/include/rdma/iw_cm.h
73407@@ -122,7 +122,7 @@ struct iw_cm_verbs {
73408 int backlog);
73409
73410 int (*destroy_listen)(struct iw_cm_id *cm_id);
73411-};
73412+} __no_const;
73413
73414 /**
73415 * iw_create_cm_id - Create an IW CM identifier.
73416diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
73417index e1379b4..67eafbe 100644
73418--- a/include/scsi/libfc.h
73419+++ b/include/scsi/libfc.h
73420@@ -762,6 +762,7 @@ struct libfc_function_template {
73421 */
73422 void (*disc_stop_final) (struct fc_lport *);
73423 };
73424+typedef struct libfc_function_template __no_const libfc_function_template_no_const;
73425
73426 /**
73427 * struct fc_disc - Discovery context
73428@@ -866,7 +867,7 @@ struct fc_lport {
73429 struct fc_vport *vport;
73430
73431 /* Operational Information */
73432- struct libfc_function_template tt;
73433+ libfc_function_template_no_const tt;
73434 u8 link_up;
73435 u8 qfull;
73436 enum fc_lport_state state;
73437diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
73438index a7f9cba..b1f44d0 100644
73439--- a/include/scsi/scsi_device.h
73440+++ b/include/scsi/scsi_device.h
73441@@ -171,9 +171,9 @@ struct scsi_device {
73442 unsigned int max_device_blocked; /* what device_blocked counts down from */
73443 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
73444
73445- atomic_t iorequest_cnt;
73446- atomic_t iodone_cnt;
73447- atomic_t ioerr_cnt;
73448+ atomic_unchecked_t iorequest_cnt;
73449+ atomic_unchecked_t iodone_cnt;
73450+ atomic_unchecked_t ioerr_cnt;
73451
73452 struct device sdev_gendev,
73453 sdev_dev;
73454diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
73455index b797e8f..8e2c3aa 100644
73456--- a/include/scsi/scsi_transport_fc.h
73457+++ b/include/scsi/scsi_transport_fc.h
73458@@ -751,7 +751,8 @@ struct fc_function_template {
73459 unsigned long show_host_system_hostname:1;
73460
73461 unsigned long disable_target_scan:1;
73462-};
73463+} __do_const;
73464+typedef struct fc_function_template __no_const fc_function_template_no_const;
73465
73466
73467 /**
73468diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
73469index ff6c741..393815f 100644
73470--- a/include/sound/compress_driver.h
73471+++ b/include/sound/compress_driver.h
73472@@ -130,7 +130,7 @@ struct snd_compr_ops {
73473 struct snd_compr_caps *caps);
73474 int (*get_codec_caps) (struct snd_compr_stream *stream,
73475 struct snd_compr_codec_caps *codec);
73476-};
73477+} __no_const;
73478
73479 /**
73480 * struct snd_compr: Compressed device
73481diff --git a/include/sound/soc.h b/include/sound/soc.h
73482index a6a059c..2243336 100644
73483--- a/include/sound/soc.h
73484+++ b/include/sound/soc.h
73485@@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
73486 /* probe ordering - for components with runtime dependencies */
73487 int probe_order;
73488 int remove_order;
73489-};
73490+} __do_const;
73491
73492 /* SoC platform interface */
73493 struct snd_soc_platform_driver {
73494@@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
73495 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
73496 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
73497 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
73498-};
73499+} __do_const;
73500
73501 struct snd_soc_platform {
73502 const char *name;
73503diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
73504index f8640f3..b72d113 100644
73505--- a/include/target/target_core_base.h
73506+++ b/include/target/target_core_base.h
73507@@ -658,7 +658,7 @@ struct se_device {
73508 spinlock_t stats_lock;
73509 /* Active commands on this virtual SE device */
73510 atomic_t simple_cmds;
73511- atomic_t dev_ordered_id;
73512+ atomic_unchecked_t dev_ordered_id;
73513 atomic_t dev_ordered_sync;
73514 atomic_t dev_qf_count;
73515 int export_count;
73516diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
73517new file mode 100644
73518index 0000000..fb634b7
73519--- /dev/null
73520+++ b/include/trace/events/fs.h
73521@@ -0,0 +1,53 @@
73522+#undef TRACE_SYSTEM
73523+#define TRACE_SYSTEM fs
73524+
73525+#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
73526+#define _TRACE_FS_H
73527+
73528+#include <linux/fs.h>
73529+#include <linux/tracepoint.h>
73530+
73531+TRACE_EVENT(do_sys_open,
73532+
73533+ TP_PROTO(const char *filename, int flags, int mode),
73534+
73535+ TP_ARGS(filename, flags, mode),
73536+
73537+ TP_STRUCT__entry(
73538+ __string( filename, filename )
73539+ __field( int, flags )
73540+ __field( int, mode )
73541+ ),
73542+
73543+ TP_fast_assign(
73544+ __assign_str(filename, filename);
73545+ __entry->flags = flags;
73546+ __entry->mode = mode;
73547+ ),
73548+
73549+ TP_printk("\"%s\" %x %o",
73550+ __get_str(filename), __entry->flags, __entry->mode)
73551+);
73552+
73553+TRACE_EVENT(open_exec,
73554+
73555+ TP_PROTO(const char *filename),
73556+
73557+ TP_ARGS(filename),
73558+
73559+ TP_STRUCT__entry(
73560+ __string( filename, filename )
73561+ ),
73562+
73563+ TP_fast_assign(
73564+ __assign_str(filename, filename);
73565+ ),
73566+
73567+ TP_printk("\"%s\"",
73568+ __get_str(filename))
73569+);
73570+
73571+#endif /* _TRACE_FS_H */
73572+
73573+/* This part must be outside protection */
73574+#include <trace/define_trace.h>
73575diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
73576index 1c09820..7f5ec79 100644
73577--- a/include/trace/events/irq.h
73578+++ b/include/trace/events/irq.h
73579@@ -36,7 +36,7 @@ struct softirq_action;
73580 */
73581 TRACE_EVENT(irq_handler_entry,
73582
73583- TP_PROTO(int irq, struct irqaction *action),
73584+ TP_PROTO(int irq, const struct irqaction *action),
73585
73586 TP_ARGS(irq, action),
73587
73588@@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
73589 */
73590 TRACE_EVENT(irq_handler_exit,
73591
73592- TP_PROTO(int irq, struct irqaction *action, int ret),
73593+ TP_PROTO(int irq, const struct irqaction *action, int ret),
73594
73595 TP_ARGS(irq, action, ret),
73596
73597diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
73598index 7caf44c..23c6f27 100644
73599--- a/include/uapi/linux/a.out.h
73600+++ b/include/uapi/linux/a.out.h
73601@@ -39,6 +39,14 @@ enum machine_type {
73602 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
73603 };
73604
73605+/* Constants for the N_FLAGS field */
73606+#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73607+#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
73608+#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
73609+#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
73610+/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73611+#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73612+
73613 #if !defined (N_MAGIC)
73614 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
73615 #endif
73616diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
73617index d876736..ccce5c0 100644
73618--- a/include/uapi/linux/byteorder/little_endian.h
73619+++ b/include/uapi/linux/byteorder/little_endian.h
73620@@ -42,51 +42,51 @@
73621
73622 static inline __le64 __cpu_to_le64p(const __u64 *p)
73623 {
73624- return (__force __le64)*p;
73625+ return (__force const __le64)*p;
73626 }
73627-static inline __u64 __le64_to_cpup(const __le64 *p)
73628+static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
73629 {
73630- return (__force __u64)*p;
73631+ return (__force const __u64)*p;
73632 }
73633 static inline __le32 __cpu_to_le32p(const __u32 *p)
73634 {
73635- return (__force __le32)*p;
73636+ return (__force const __le32)*p;
73637 }
73638 static inline __u32 __le32_to_cpup(const __le32 *p)
73639 {
73640- return (__force __u32)*p;
73641+ return (__force const __u32)*p;
73642 }
73643 static inline __le16 __cpu_to_le16p(const __u16 *p)
73644 {
73645- return (__force __le16)*p;
73646+ return (__force const __le16)*p;
73647 }
73648 static inline __u16 __le16_to_cpup(const __le16 *p)
73649 {
73650- return (__force __u16)*p;
73651+ return (__force const __u16)*p;
73652 }
73653 static inline __be64 __cpu_to_be64p(const __u64 *p)
73654 {
73655- return (__force __be64)__swab64p(p);
73656+ return (__force const __be64)__swab64p(p);
73657 }
73658 static inline __u64 __be64_to_cpup(const __be64 *p)
73659 {
73660- return __swab64p((__u64 *)p);
73661+ return __swab64p((const __u64 *)p);
73662 }
73663 static inline __be32 __cpu_to_be32p(const __u32 *p)
73664 {
73665- return (__force __be32)__swab32p(p);
73666+ return (__force const __be32)__swab32p(p);
73667 }
73668-static inline __u32 __be32_to_cpup(const __be32 *p)
73669+static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
73670 {
73671- return __swab32p((__u32 *)p);
73672+ return __swab32p((const __u32 *)p);
73673 }
73674 static inline __be16 __cpu_to_be16p(const __u16 *p)
73675 {
73676- return (__force __be16)__swab16p(p);
73677+ return (__force const __be16)__swab16p(p);
73678 }
73679 static inline __u16 __be16_to_cpup(const __be16 *p)
73680 {
73681- return __swab16p((__u16 *)p);
73682+ return __swab16p((const __u16 *)p);
73683 }
73684 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
73685 #define __le64_to_cpus(x) do { (void)(x); } while (0)
73686diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
73687index 8072d35..e77aeb8 100644
73688--- a/include/uapi/linux/elf.h
73689+++ b/include/uapi/linux/elf.h
73690@@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
73691 #define PT_GNU_EH_FRAME 0x6474e550
73692
73693 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
73694+#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
73695+
73696+#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
73697+
73698+/* Constants for the e_flags field */
73699+#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
73700+#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
73701+#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
73702+#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
73703+/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
73704+#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
73705
73706 /*
73707 * Extended Numbering
73708@@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
73709 #define DT_DEBUG 21
73710 #define DT_TEXTREL 22
73711 #define DT_JMPREL 23
73712+#define DT_FLAGS 30
73713+ #define DF_TEXTREL 0x00000004
73714 #define DT_ENCODING 32
73715 #define OLD_DT_LOOS 0x60000000
73716 #define DT_LOOS 0x6000000d
73717@@ -240,6 +253,19 @@ typedef struct elf64_hdr {
73718 #define PF_W 0x2
73719 #define PF_X 0x1
73720
73721+#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
73722+#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
73723+#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
73724+#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
73725+#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
73726+#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
73727+/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
73728+/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
73729+#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
73730+#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
73731+#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
73732+#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
73733+
73734 typedef struct elf32_phdr{
73735 Elf32_Word p_type;
73736 Elf32_Off p_offset;
73737@@ -332,6 +358,8 @@ typedef struct elf64_shdr {
73738 #define EI_OSABI 7
73739 #define EI_PAD 8
73740
73741+#define EI_PAX 14
73742+
73743 #define ELFMAG0 0x7f /* EI_MAG */
73744 #define ELFMAG1 'E'
73745 #define ELFMAG2 'L'
73746diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
73747index aa169c4..6a2771d 100644
73748--- a/include/uapi/linux/personality.h
73749+++ b/include/uapi/linux/personality.h
73750@@ -30,6 +30,7 @@ enum {
73751 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
73752 ADDR_NO_RANDOMIZE | \
73753 ADDR_COMPAT_LAYOUT | \
73754+ ADDR_LIMIT_3GB | \
73755 MMAP_PAGE_ZERO)
73756
73757 /*
73758diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
73759index 7530e74..e714828 100644
73760--- a/include/uapi/linux/screen_info.h
73761+++ b/include/uapi/linux/screen_info.h
73762@@ -43,7 +43,8 @@ struct screen_info {
73763 __u16 pages; /* 0x32 */
73764 __u16 vesa_attributes; /* 0x34 */
73765 __u32 capabilities; /* 0x36 */
73766- __u8 _reserved[6]; /* 0x3a */
73767+ __u16 vesapm_size; /* 0x3a */
73768+ __u8 _reserved[4]; /* 0x3c */
73769 } __attribute__((packed));
73770
73771 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
73772diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
73773index 0e011eb..82681b1 100644
73774--- a/include/uapi/linux/swab.h
73775+++ b/include/uapi/linux/swab.h
73776@@ -43,7 +43,7 @@
73777 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
73778 */
73779
73780-static inline __attribute_const__ __u16 __fswab16(__u16 val)
73781+static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
73782 {
73783 #ifdef __HAVE_BUILTIN_BSWAP16__
73784 return __builtin_bswap16(val);
73785@@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
73786 #endif
73787 }
73788
73789-static inline __attribute_const__ __u32 __fswab32(__u32 val)
73790+static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
73791 {
73792 #ifdef __HAVE_BUILTIN_BSWAP32__
73793 return __builtin_bswap32(val);
73794@@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
73795 #endif
73796 }
73797
73798-static inline __attribute_const__ __u64 __fswab64(__u64 val)
73799+static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
73800 {
73801 #ifdef __HAVE_BUILTIN_BSWAP64__
73802 return __builtin_bswap64(val);
73803diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
73804index 6d67213..8dab561 100644
73805--- a/include/uapi/linux/sysctl.h
73806+++ b/include/uapi/linux/sysctl.h
73807@@ -155,7 +155,11 @@ enum
73808 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
73809 };
73810
73811-
73812+#ifdef CONFIG_PAX_SOFTMODE
73813+enum {
73814+ PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
73815+};
73816+#endif
73817
73818 /* CTL_VM names: */
73819 enum
73820diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
73821index e4629b9..6958086 100644
73822--- a/include/uapi/linux/xattr.h
73823+++ b/include/uapi/linux/xattr.h
73824@@ -63,5 +63,9 @@
73825 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
73826 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
73827
73828+/* User namespace */
73829+#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
73830+#define XATTR_PAX_FLAGS_SUFFIX "flags"
73831+#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
73832
73833 #endif /* _UAPI_LINUX_XATTR_H */
73834diff --git a/include/video/udlfb.h b/include/video/udlfb.h
73835index f9466fa..f4e2b81 100644
73836--- a/include/video/udlfb.h
73837+++ b/include/video/udlfb.h
73838@@ -53,10 +53,10 @@ struct dlfb_data {
73839 u32 pseudo_palette[256];
73840 int blank_mode; /*one of FB_BLANK_ */
73841 /* blit-only rendering path metrics, exposed through sysfs */
73842- atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73843- atomic_t bytes_identical; /* saved effort with backbuffer comparison */
73844- atomic_t bytes_sent; /* to usb, after compression including overhead */
73845- atomic_t cpu_kcycles_used; /* transpired during pixel processing */
73846+ atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
73847+ atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
73848+ atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
73849+ atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
73850 };
73851
73852 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
73853diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
73854index 1a91850..28573f8 100644
73855--- a/include/video/uvesafb.h
73856+++ b/include/video/uvesafb.h
73857@@ -122,6 +122,7 @@ struct uvesafb_par {
73858 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
73859 u8 pmi_setpal; /* PMI for palette changes */
73860 u16 *pmi_base; /* protected mode interface location */
73861+ u8 *pmi_code; /* protected mode code location */
73862 void *pmi_start;
73863 void *pmi_pal;
73864 u8 *vbe_state_orig; /*
73865diff --git a/init/Kconfig b/init/Kconfig
73866index 5341d72..153f24f 100644
73867--- a/init/Kconfig
73868+++ b/init/Kconfig
73869@@ -984,6 +984,7 @@ endif # CGROUPS
73870
73871 config CHECKPOINT_RESTORE
73872 bool "Checkpoint/restore support" if EXPERT
73873+ depends on !GRKERNSEC
73874 default n
73875 help
73876 Enables additional kernel features in a sake of checkpoint/restore.
73877@@ -1471,7 +1472,7 @@ config SLUB_DEBUG
73878
73879 config COMPAT_BRK
73880 bool "Disable heap randomization"
73881- default y
73882+ default n
73883 help
73884 Randomizing heap placement makes heap exploits harder, but it
73885 also breaks ancient binaries (including anything libc5 based).
73886@@ -1734,7 +1735,7 @@ config INIT_ALL_POSSIBLE
73887 config STOP_MACHINE
73888 bool
73889 default y
73890- depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
73891+ depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
73892 help
73893 Need stop_machine() primitive.
73894
73895diff --git a/init/Makefile b/init/Makefile
73896index 7bc47ee..6da2dc7 100644
73897--- a/init/Makefile
73898+++ b/init/Makefile
73899@@ -2,6 +2,9 @@
73900 # Makefile for the linux kernel.
73901 #
73902
73903+ccflags-y := $(GCC_PLUGINS_CFLAGS)
73904+asflags-y := $(GCC_PLUGINS_AFLAGS)
73905+
73906 obj-y := main.o version.o mounts.o
73907 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
73908 obj-y += noinitramfs.o
73909diff --git a/init/do_mounts.c b/init/do_mounts.c
73910index a2b49f2..03a0e17c 100644
73911--- a/init/do_mounts.c
73912+++ b/init/do_mounts.c
73913@@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
73914 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
73915 {
73916 struct super_block *s;
73917- int err = sys_mount(name, "/root", fs, flags, data);
73918+ int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
73919 if (err)
73920 return err;
73921
73922- sys_chdir("/root");
73923+ sys_chdir((const char __force_user *)"/root");
73924 s = current->fs->pwd.dentry->d_sb;
73925 ROOT_DEV = s->s_dev;
73926 printk(KERN_INFO
73927@@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
73928 va_start(args, fmt);
73929 vsprintf(buf, fmt, args);
73930 va_end(args);
73931- fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
73932+ fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
73933 if (fd >= 0) {
73934 sys_ioctl(fd, FDEJECT, 0);
73935 sys_close(fd);
73936 }
73937 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
73938- fd = sys_open("/dev/console", O_RDWR, 0);
73939+ fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
73940 if (fd >= 0) {
73941 sys_ioctl(fd, TCGETS, (long)&termios);
73942 termios.c_lflag &= ~ICANON;
73943 sys_ioctl(fd, TCSETSF, (long)&termios);
73944- sys_read(fd, &c, 1);
73945+ sys_read(fd, (char __user *)&c, 1);
73946 termios.c_lflag |= ICANON;
73947 sys_ioctl(fd, TCSETSF, (long)&termios);
73948 sys_close(fd);
73949@@ -585,6 +585,6 @@ void __init prepare_namespace(void)
73950 mount_root();
73951 out:
73952 devtmpfs_mount("dev");
73953- sys_mount(".", "/", NULL, MS_MOVE, NULL);
73954- sys_chroot(".");
73955+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
73956+ sys_chroot((const char __force_user *)".");
73957 }
73958diff --git a/init/do_mounts.h b/init/do_mounts.h
73959index f5b978a..69dbfe8 100644
73960--- a/init/do_mounts.h
73961+++ b/init/do_mounts.h
73962@@ -15,15 +15,15 @@ extern int root_mountflags;
73963
73964 static inline int create_dev(char *name, dev_t dev)
73965 {
73966- sys_unlink(name);
73967- return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
73968+ sys_unlink((char __force_user *)name);
73969+ return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
73970 }
73971
73972 #if BITS_PER_LONG == 32
73973 static inline u32 bstat(char *name)
73974 {
73975 struct stat64 stat;
73976- if (sys_stat64(name, &stat) != 0)
73977+ if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
73978 return 0;
73979 if (!S_ISBLK(stat.st_mode))
73980 return 0;
73981@@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
73982 static inline u32 bstat(char *name)
73983 {
73984 struct stat stat;
73985- if (sys_newstat(name, &stat) != 0)
73986+ if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
73987 return 0;
73988 if (!S_ISBLK(stat.st_mode))
73989 return 0;
73990diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
73991index a32ec1c..60a6659 100644
73992--- a/init/do_mounts_initrd.c
73993+++ b/init/do_mounts_initrd.c
73994@@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
73995 {
73996 sys_unshare(CLONE_FS | CLONE_FILES);
73997 /* stdin/stdout/stderr for /linuxrc */
73998- sys_open("/dev/console", O_RDWR, 0);
73999+ sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
74000 sys_dup(0);
74001 sys_dup(0);
74002 /* move initrd over / and chdir/chroot in initrd root */
74003- sys_chdir("/root");
74004- sys_mount(".", "/", NULL, MS_MOVE, NULL);
74005- sys_chroot(".");
74006+ sys_chdir((const char __force_user *)"/root");
74007+ sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
74008+ sys_chroot((const char __force_user *)".");
74009 sys_setsid();
74010 return 0;
74011 }
74012@@ -58,8 +58,8 @@ static void __init handle_initrd(void)
74013 create_dev("/dev/root.old", Root_RAM0);
74014 /* mount initrd on rootfs' /root */
74015 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
74016- sys_mkdir("/old", 0700);
74017- sys_chdir("/old");
74018+ sys_mkdir((const char __force_user *)"/old", 0700);
74019+ sys_chdir((const char __force_user *)"/old");
74020
74021 /* try loading default modules from initrd */
74022 load_default_modules();
74023@@ -76,31 +76,31 @@ static void __init handle_initrd(void)
74024 current->flags &= ~PF_FREEZER_SKIP;
74025
74026 /* move initrd to rootfs' /old */
74027- sys_mount("..", ".", NULL, MS_MOVE, NULL);
74028+ sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
74029 /* switch root and cwd back to / of rootfs */
74030- sys_chroot("..");
74031+ sys_chroot((const char __force_user *)"..");
74032
74033 if (new_decode_dev(real_root_dev) == Root_RAM0) {
74034- sys_chdir("/old");
74035+ sys_chdir((const char __force_user *)"/old");
74036 return;
74037 }
74038
74039- sys_chdir("/");
74040+ sys_chdir((const char __force_user *)"/");
74041 ROOT_DEV = new_decode_dev(real_root_dev);
74042 mount_root();
74043
74044 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
74045- error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
74046+ error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
74047 if (!error)
74048 printk("okay\n");
74049 else {
74050- int fd = sys_open("/dev/root.old", O_RDWR, 0);
74051+ int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
74052 if (error == -ENOENT)
74053 printk("/initrd does not exist. Ignored.\n");
74054 else
74055 printk("failed\n");
74056 printk(KERN_NOTICE "Unmounting old root\n");
74057- sys_umount("/old", MNT_DETACH);
74058+ sys_umount((char __force_user *)"/old", MNT_DETACH);
74059 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
74060 if (fd < 0) {
74061 error = fd;
74062@@ -123,11 +123,11 @@ int __init initrd_load(void)
74063 * mounted in the normal path.
74064 */
74065 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
74066- sys_unlink("/initrd.image");
74067+ sys_unlink((const char __force_user *)"/initrd.image");
74068 handle_initrd();
74069 return 1;
74070 }
74071 }
74072- sys_unlink("/initrd.image");
74073+ sys_unlink((const char __force_user *)"/initrd.image");
74074 return 0;
74075 }
74076diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
74077index 8cb6db5..d729f50 100644
74078--- a/init/do_mounts_md.c
74079+++ b/init/do_mounts_md.c
74080@@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
74081 partitioned ? "_d" : "", minor,
74082 md_setup_args[ent].device_names);
74083
74084- fd = sys_open(name, 0, 0);
74085+ fd = sys_open((char __force_user *)name, 0, 0);
74086 if (fd < 0) {
74087 printk(KERN_ERR "md: open failed - cannot start "
74088 "array %s\n", name);
74089@@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
74090 * array without it
74091 */
74092 sys_close(fd);
74093- fd = sys_open(name, 0, 0);
74094+ fd = sys_open((char __force_user *)name, 0, 0);
74095 sys_ioctl(fd, BLKRRPART, 0);
74096 }
74097 sys_close(fd);
74098@@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
74099
74100 wait_for_device_probe();
74101
74102- fd = sys_open("/dev/md0", 0, 0);
74103+ fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
74104 if (fd >= 0) {
74105 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
74106 sys_close(fd);
74107diff --git a/init/init_task.c b/init/init_task.c
74108index ba0a7f36..2bcf1d5 100644
74109--- a/init/init_task.c
74110+++ b/init/init_task.c
74111@@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
74112 * Initial thread structure. Alignment of this is handled by a special
74113 * linker map entry.
74114 */
74115+#ifdef CONFIG_X86
74116+union thread_union init_thread_union __init_task_data;
74117+#else
74118 union thread_union init_thread_union __init_task_data =
74119 { INIT_THREAD_INFO(init_task) };
74120+#endif
74121diff --git a/init/initramfs.c b/init/initramfs.c
74122index a67ef9d..2d17ed9 100644
74123--- a/init/initramfs.c
74124+++ b/init/initramfs.c
74125@@ -84,7 +84,7 @@ static void __init free_hash(void)
74126 }
74127 }
74128
74129-static long __init do_utime(char *filename, time_t mtime)
74130+static long __init do_utime(char __force_user *filename, time_t mtime)
74131 {
74132 struct timespec t[2];
74133
74134@@ -119,7 +119,7 @@ static void __init dir_utime(void)
74135 struct dir_entry *de, *tmp;
74136 list_for_each_entry_safe(de, tmp, &dir_list, list) {
74137 list_del(&de->list);
74138- do_utime(de->name, de->mtime);
74139+ do_utime((char __force_user *)de->name, de->mtime);
74140 kfree(de->name);
74141 kfree(de);
74142 }
74143@@ -281,7 +281,7 @@ static int __init maybe_link(void)
74144 if (nlink >= 2) {
74145 char *old = find_link(major, minor, ino, mode, collected);
74146 if (old)
74147- return (sys_link(old, collected) < 0) ? -1 : 1;
74148+ return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
74149 }
74150 return 0;
74151 }
74152@@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
74153 {
74154 struct stat st;
74155
74156- if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
74157+ if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
74158 if (S_ISDIR(st.st_mode))
74159- sys_rmdir(path);
74160+ sys_rmdir((char __force_user *)path);
74161 else
74162- sys_unlink(path);
74163+ sys_unlink((char __force_user *)path);
74164 }
74165 }
74166
74167@@ -315,7 +315,7 @@ static int __init do_name(void)
74168 int openflags = O_WRONLY|O_CREAT;
74169 if (ml != 1)
74170 openflags |= O_TRUNC;
74171- wfd = sys_open(collected, openflags, mode);
74172+ wfd = sys_open((char __force_user *)collected, openflags, mode);
74173
74174 if (wfd >= 0) {
74175 sys_fchown(wfd, uid, gid);
74176@@ -327,17 +327,17 @@ static int __init do_name(void)
74177 }
74178 }
74179 } else if (S_ISDIR(mode)) {
74180- sys_mkdir(collected, mode);
74181- sys_chown(collected, uid, gid);
74182- sys_chmod(collected, mode);
74183+ sys_mkdir((char __force_user *)collected, mode);
74184+ sys_chown((char __force_user *)collected, uid, gid);
74185+ sys_chmod((char __force_user *)collected, mode);
74186 dir_add(collected, mtime);
74187 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
74188 S_ISFIFO(mode) || S_ISSOCK(mode)) {
74189 if (maybe_link() == 0) {
74190- sys_mknod(collected, mode, rdev);
74191- sys_chown(collected, uid, gid);
74192- sys_chmod(collected, mode);
74193- do_utime(collected, mtime);
74194+ sys_mknod((char __force_user *)collected, mode, rdev);
74195+ sys_chown((char __force_user *)collected, uid, gid);
74196+ sys_chmod((char __force_user *)collected, mode);
74197+ do_utime((char __force_user *)collected, mtime);
74198 }
74199 }
74200 return 0;
74201@@ -346,15 +346,15 @@ static int __init do_name(void)
74202 static int __init do_copy(void)
74203 {
74204 if (count >= body_len) {
74205- sys_write(wfd, victim, body_len);
74206+ sys_write(wfd, (char __force_user *)victim, body_len);
74207 sys_close(wfd);
74208- do_utime(vcollected, mtime);
74209+ do_utime((char __force_user *)vcollected, mtime);
74210 kfree(vcollected);
74211 eat(body_len);
74212 state = SkipIt;
74213 return 0;
74214 } else {
74215- sys_write(wfd, victim, count);
74216+ sys_write(wfd, (char __force_user *)victim, count);
74217 body_len -= count;
74218 eat(count);
74219 return 1;
74220@@ -365,9 +365,9 @@ static int __init do_symlink(void)
74221 {
74222 collected[N_ALIGN(name_len) + body_len] = '\0';
74223 clean_path(collected, 0);
74224- sys_symlink(collected + N_ALIGN(name_len), collected);
74225- sys_lchown(collected, uid, gid);
74226- do_utime(collected, mtime);
74227+ sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
74228+ sys_lchown((char __force_user *)collected, uid, gid);
74229+ do_utime((char __force_user *)collected, mtime);
74230 state = SkipIt;
74231 next_state = Reset;
74232 return 0;
74233@@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
74234 {
74235 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
74236 if (err)
74237- panic(err); /* Failed to decompress INTERNAL initramfs */
74238+ panic("%s", err); /* Failed to decompress INTERNAL initramfs */
74239 if (initrd_start) {
74240 #ifdef CONFIG_BLK_DEV_RAM
74241 int fd;
74242diff --git a/init/main.c b/init/main.c
74243index 63534a1..85feae2 100644
74244--- a/init/main.c
74245+++ b/init/main.c
74246@@ -98,6 +98,8 @@ static inline void mark_rodata_ro(void) { }
74247 extern void tc_init(void);
74248 #endif
74249
74250+extern void grsecurity_init(void);
74251+
74252 /*
74253 * Debug helper: via this flag we know that we are in 'early bootup code'
74254 * where only the boot processor is running with IRQ disabled. This means
74255@@ -151,6 +153,64 @@ static int __init set_reset_devices(char *str)
74256
74257 __setup("reset_devices", set_reset_devices);
74258
74259+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
74260+kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
74261+static int __init setup_grsec_proc_gid(char *str)
74262+{
74263+ grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
74264+ return 1;
74265+}
74266+__setup("grsec_proc_gid=", setup_grsec_proc_gid);
74267+#endif
74268+
74269+#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
74270+unsigned long pax_user_shadow_base __read_only = 1UL << TASK_SIZE_MAX_SHIFT;
74271+EXPORT_SYMBOL(pax_user_shadow_base);
74272+extern char pax_enter_kernel_user[];
74273+extern char pax_exit_kernel_user[];
74274+extern pgdval_t clone_pgd_mask;
74275+#endif
74276+
74277+#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
74278+static int __init setup_pax_nouderef(char *str)
74279+{
74280+#ifdef CONFIG_X86_32
74281+ unsigned int cpu;
74282+ struct desc_struct *gdt;
74283+
74284+ for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
74285+ gdt = get_cpu_gdt_table(cpu);
74286+ gdt[GDT_ENTRY_KERNEL_DS].type = 3;
74287+ gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
74288+ gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
74289+ gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
74290+ }
74291+ loadsegment(ds, __KERNEL_DS);
74292+ loadsegment(es, __KERNEL_DS);
74293+ loadsegment(ss, __KERNEL_DS);
74294+#else
74295+ memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
74296+ memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
74297+ clone_pgd_mask = ~(pgdval_t)0UL;
74298+ pax_user_shadow_base = 0UL;
74299+#endif
74300+
74301+ return 0;
74302+}
74303+early_param("pax_nouderef", setup_pax_nouderef);
74304+#endif
74305+
74306+#ifdef CONFIG_PAX_SOFTMODE
74307+int pax_softmode;
74308+
74309+static int __init setup_pax_softmode(char *str)
74310+{
74311+ get_option(&str, &pax_softmode);
74312+ return 1;
74313+}
74314+__setup("pax_softmode=", setup_pax_softmode);
74315+#endif
74316+
74317 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
74318 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
74319 static const char *panic_later, *panic_param;
74320@@ -683,6 +743,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
74321 {
74322 int count = preempt_count();
74323 int ret;
74324+ const char *msg1 = "", *msg2 = "";
74325
74326 if (initcall_debug)
74327 ret = do_one_initcall_debug(fn);
74328@@ -695,15 +756,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
74329 sprintf(msgbuf, "error code %d ", ret);
74330
74331 if (preempt_count() != count) {
74332- strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
74333+ msg1 = " preemption imbalance";
74334 preempt_count() = count;
74335 }
74336 if (irqs_disabled()) {
74337- strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
74338+ msg2 = " disabled interrupts";
74339 local_irq_enable();
74340 }
74341- if (msgbuf[0]) {
74342- printk("initcall %pF returned with %s\n", fn, msgbuf);
74343+ if (msgbuf[0] || *msg1 || *msg2) {
74344+ printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
74345 }
74346
74347 return ret;
74348@@ -757,8 +818,14 @@ static void __init do_initcall_level(int level)
74349 level, level,
74350 &repair_env_string);
74351
74352- for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
74353+ for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
74354 do_one_initcall(*fn);
74355+
74356+#ifdef LATENT_ENTROPY_PLUGIN
74357+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74358+#endif
74359+
74360+ }
74361 }
74362
74363 static void __init do_initcalls(void)
74364@@ -792,8 +859,14 @@ static void __init do_pre_smp_initcalls(void)
74365 {
74366 initcall_t *fn;
74367
74368- for (fn = __initcall_start; fn < __initcall0_start; fn++)
74369+ for (fn = __initcall_start; fn < __initcall0_start; fn++) {
74370 do_one_initcall(*fn);
74371+
74372+#ifdef LATENT_ENTROPY_PLUGIN
74373+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
74374+#endif
74375+
74376+ }
74377 }
74378
74379 /*
74380@@ -811,8 +884,8 @@ static int run_init_process(const char *init_filename)
74381 {
74382 argv_init[0] = init_filename;
74383 return do_execve(init_filename,
74384- (const char __user *const __user *)argv_init,
74385- (const char __user *const __user *)envp_init);
74386+ (const char __user *const __force_user *)argv_init,
74387+ (const char __user *const __force_user *)envp_init);
74388 }
74389
74390 static noinline void __init kernel_init_freeable(void);
74391@@ -890,7 +963,7 @@ static noinline void __init kernel_init_freeable(void)
74392 do_basic_setup();
74393
74394 /* Open the /dev/console on the rootfs, this should never fail */
74395- if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
74396+ if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
74397 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
74398
74399 (void) sys_dup(0);
74400@@ -903,11 +976,13 @@ static noinline void __init kernel_init_freeable(void)
74401 if (!ramdisk_execute_command)
74402 ramdisk_execute_command = "/init";
74403
74404- if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
74405+ if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
74406 ramdisk_execute_command = NULL;
74407 prepare_namespace();
74408 }
74409
74410+ grsecurity_init();
74411+
74412 /*
74413 * Ok, we have completed the initial bootup, and
74414 * we're essentially up and running. Get rid of the
74415diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
74416index 130dfec..cc88451 100644
74417--- a/ipc/ipc_sysctl.c
74418+++ b/ipc/ipc_sysctl.c
74419@@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
74420 static int proc_ipc_dointvec(ctl_table *table, int write,
74421 void __user *buffer, size_t *lenp, loff_t *ppos)
74422 {
74423- struct ctl_table ipc_table;
74424+ ctl_table_no_const ipc_table;
74425
74426 memcpy(&ipc_table, table, sizeof(ipc_table));
74427 ipc_table.data = get_ipc(table);
74428@@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
74429 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
74430 void __user *buffer, size_t *lenp, loff_t *ppos)
74431 {
74432- struct ctl_table ipc_table;
74433+ ctl_table_no_const ipc_table;
74434
74435 memcpy(&ipc_table, table, sizeof(ipc_table));
74436 ipc_table.data = get_ipc(table);
74437@@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
74438 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74439 void __user *buffer, size_t *lenp, loff_t *ppos)
74440 {
74441- struct ctl_table ipc_table;
74442+ ctl_table_no_const ipc_table;
74443 size_t lenp_bef = *lenp;
74444 int rc;
74445
74446@@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
74447 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
74448 void __user *buffer, size_t *lenp, loff_t *ppos)
74449 {
74450- struct ctl_table ipc_table;
74451+ ctl_table_no_const ipc_table;
74452 memcpy(&ipc_table, table, sizeof(ipc_table));
74453 ipc_table.data = get_ipc(table);
74454
74455@@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
74456 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
74457 void __user *buffer, size_t *lenp, loff_t *ppos)
74458 {
74459- struct ctl_table ipc_table;
74460+ ctl_table_no_const ipc_table;
74461 size_t lenp_bef = *lenp;
74462 int oldval;
74463 int rc;
74464diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
74465index 383d638..943fdbb 100644
74466--- a/ipc/mq_sysctl.c
74467+++ b/ipc/mq_sysctl.c
74468@@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
74469 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
74470 void __user *buffer, size_t *lenp, loff_t *ppos)
74471 {
74472- struct ctl_table mq_table;
74473+ ctl_table_no_const mq_table;
74474 memcpy(&mq_table, table, sizeof(mq_table));
74475 mq_table.data = get_mq(table);
74476
74477diff --git a/ipc/mqueue.c b/ipc/mqueue.c
74478index e4e47f6..a85e0ad 100644
74479--- a/ipc/mqueue.c
74480+++ b/ipc/mqueue.c
74481@@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
74482 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
74483 info->attr.mq_msgsize);
74484
74485+ gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
74486 spin_lock(&mq_lock);
74487 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
74488 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
74489diff --git a/ipc/msg.c b/ipc/msg.c
74490index fede1d0..9778e0f8 100644
74491--- a/ipc/msg.c
74492+++ b/ipc/msg.c
74493@@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
74494 return security_msg_queue_associate(msq, msgflg);
74495 }
74496
74497+static struct ipc_ops msg_ops = {
74498+ .getnew = newque,
74499+ .associate = msg_security,
74500+ .more_checks = NULL
74501+};
74502+
74503 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
74504 {
74505 struct ipc_namespace *ns;
74506- struct ipc_ops msg_ops;
74507 struct ipc_params msg_params;
74508
74509 ns = current->nsproxy->ipc_ns;
74510
74511- msg_ops.getnew = newque;
74512- msg_ops.associate = msg_security;
74513- msg_ops.more_checks = NULL;
74514-
74515 msg_params.key = key;
74516 msg_params.flg = msgflg;
74517
74518diff --git a/ipc/sem.c b/ipc/sem.c
74519index 58d31f1..cce7a55 100644
74520--- a/ipc/sem.c
74521+++ b/ipc/sem.c
74522@@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
74523 return 0;
74524 }
74525
74526+static struct ipc_ops sem_ops = {
74527+ .getnew = newary,
74528+ .associate = sem_security,
74529+ .more_checks = sem_more_checks
74530+};
74531+
74532 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74533 {
74534 struct ipc_namespace *ns;
74535- struct ipc_ops sem_ops;
74536 struct ipc_params sem_params;
74537
74538 ns = current->nsproxy->ipc_ns;
74539@@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
74540 if (nsems < 0 || nsems > ns->sc_semmsl)
74541 return -EINVAL;
74542
74543- sem_ops.getnew = newary;
74544- sem_ops.associate = sem_security;
74545- sem_ops.more_checks = sem_more_checks;
74546-
74547 sem_params.key = key;
74548 sem_params.flg = semflg;
74549 sem_params.u.nsems = nsems;
74550diff --git a/ipc/shm.c b/ipc/shm.c
74551index 7e199fa..180a1ca 100644
74552--- a/ipc/shm.c
74553+++ b/ipc/shm.c
74554@@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
74555 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
74556 #endif
74557
74558+#ifdef CONFIG_GRKERNSEC
74559+extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74560+ const time_t shm_createtime, const kuid_t cuid,
74561+ const int shmid);
74562+extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74563+ const time_t shm_createtime);
74564+#endif
74565+
74566 void shm_init_ns(struct ipc_namespace *ns)
74567 {
74568 ns->shm_ctlmax = SHMMAX;
74569@@ -531,6 +539,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
74570 shp->shm_lprid = 0;
74571 shp->shm_atim = shp->shm_dtim = 0;
74572 shp->shm_ctim = get_seconds();
74573+#ifdef CONFIG_GRKERNSEC
74574+ {
74575+ struct timespec timeval;
74576+ do_posix_clock_monotonic_gettime(&timeval);
74577+
74578+ shp->shm_createtime = timeval.tv_sec;
74579+ }
74580+#endif
74581 shp->shm_segsz = size;
74582 shp->shm_nattch = 0;
74583 shp->shm_file = file;
74584@@ -582,18 +598,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
74585 return 0;
74586 }
74587
74588+static struct ipc_ops shm_ops = {
74589+ .getnew = newseg,
74590+ .associate = shm_security,
74591+ .more_checks = shm_more_checks
74592+};
74593+
74594 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
74595 {
74596 struct ipc_namespace *ns;
74597- struct ipc_ops shm_ops;
74598 struct ipc_params shm_params;
74599
74600 ns = current->nsproxy->ipc_ns;
74601
74602- shm_ops.getnew = newseg;
74603- shm_ops.associate = shm_security;
74604- shm_ops.more_checks = shm_more_checks;
74605-
74606 shm_params.key = key;
74607 shm_params.flg = shmflg;
74608 shm_params.u.size = size;
74609@@ -1014,6 +1031,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74610 f_mode = FMODE_READ | FMODE_WRITE;
74611 }
74612 if (shmflg & SHM_EXEC) {
74613+
74614+#ifdef CONFIG_PAX_MPROTECT
74615+ if (current->mm->pax_flags & MF_PAX_MPROTECT)
74616+ goto out;
74617+#endif
74618+
74619 prot |= PROT_EXEC;
74620 acc_mode |= S_IXUGO;
74621 }
74622@@ -1037,9 +1060,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
74623 if (err)
74624 goto out_unlock;
74625
74626+#ifdef CONFIG_GRKERNSEC
74627+ if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
74628+ shp->shm_perm.cuid, shmid) ||
74629+ !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
74630+ err = -EACCES;
74631+ goto out_unlock;
74632+ }
74633+#endif
74634+
74635 path = shp->shm_file->f_path;
74636 path_get(&path);
74637 shp->shm_nattch++;
74638+#ifdef CONFIG_GRKERNSEC
74639+ shp->shm_lapid = current->pid;
74640+#endif
74641 size = i_size_read(path.dentry->d_inode);
74642 shm_unlock(shp);
74643
74644diff --git a/kernel/acct.c b/kernel/acct.c
74645index b9bd7f0..1762b4a 100644
74646--- a/kernel/acct.c
74647+++ b/kernel/acct.c
74648@@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
74649 */
74650 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
74651 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
74652- file->f_op->write(file, (char *)&ac,
74653+ file->f_op->write(file, (char __force_user *)&ac,
74654 sizeof(acct_t), &file->f_pos);
74655 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
74656 set_fs(fs);
74657diff --git a/kernel/audit.c b/kernel/audit.c
74658index 8a667f10..7375e3f 100644
74659--- a/kernel/audit.c
74660+++ b/kernel/audit.c
74661@@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
74662 3) suppressed due to audit_rate_limit
74663 4) suppressed due to audit_backlog_limit
74664 */
74665-static atomic_t audit_lost = ATOMIC_INIT(0);
74666+static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
74667
74668 /* The netlink socket. */
74669 static struct sock *audit_sock;
74670@@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
74671 unsigned long now;
74672 int print;
74673
74674- atomic_inc(&audit_lost);
74675+ atomic_inc_unchecked(&audit_lost);
74676
74677 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
74678
74679@@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
74680 printk(KERN_WARNING
74681 "audit: audit_lost=%d audit_rate_limit=%d "
74682 "audit_backlog_limit=%d\n",
74683- atomic_read(&audit_lost),
74684+ atomic_read_unchecked(&audit_lost),
74685 audit_rate_limit,
74686 audit_backlog_limit);
74687 audit_panic(message);
74688@@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
74689 status_set.pid = audit_pid;
74690 status_set.rate_limit = audit_rate_limit;
74691 status_set.backlog_limit = audit_backlog_limit;
74692- status_set.lost = atomic_read(&audit_lost);
74693+ status_set.lost = atomic_read_unchecked(&audit_lost);
74694 status_set.backlog = skb_queue_len(&audit_skb_queue);
74695 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
74696 &status_set, sizeof(status_set));
74697diff --git a/kernel/auditsc.c b/kernel/auditsc.c
74698index c4b72b0..8654c4e 100644
74699--- a/kernel/auditsc.c
74700+++ b/kernel/auditsc.c
74701@@ -2295,7 +2295,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
74702 }
74703
74704 /* global counter which is incremented every time something logs in */
74705-static atomic_t session_id = ATOMIC_INIT(0);
74706+static atomic_unchecked_t session_id = ATOMIC_INIT(0);
74707
74708 /**
74709 * audit_set_loginuid - set current task's audit_context loginuid
74710@@ -2319,7 +2319,7 @@ int audit_set_loginuid(kuid_t loginuid)
74711 return -EPERM;
74712 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
74713
74714- sessionid = atomic_inc_return(&session_id);
74715+ sessionid = atomic_inc_return_unchecked(&session_id);
74716 if (context && context->in_syscall) {
74717 struct audit_buffer *ab;
74718
74719diff --git a/kernel/capability.c b/kernel/capability.c
74720index f6c2ce5..982c0f9 100644
74721--- a/kernel/capability.c
74722+++ b/kernel/capability.c
74723@@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
74724 * before modification is attempted and the application
74725 * fails.
74726 */
74727+ if (tocopy > ARRAY_SIZE(kdata))
74728+ return -EFAULT;
74729+
74730 if (copy_to_user(dataptr, kdata, tocopy
74731 * sizeof(struct __user_cap_data_struct))) {
74732 return -EFAULT;
74733@@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
74734 int ret;
74735
74736 rcu_read_lock();
74737- ret = security_capable(__task_cred(t), ns, cap);
74738+ ret = security_capable(__task_cred(t), ns, cap) == 0 &&
74739+ gr_task_is_capable(t, __task_cred(t), cap);
74740 rcu_read_unlock();
74741
74742- return (ret == 0);
74743+ return ret;
74744 }
74745
74746 /**
74747@@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
74748 int ret;
74749
74750 rcu_read_lock();
74751- ret = security_capable_noaudit(__task_cred(t), ns, cap);
74752+ ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
74753 rcu_read_unlock();
74754
74755- return (ret == 0);
74756+ return ret;
74757 }
74758
74759 /**
74760@@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
74761 BUG();
74762 }
74763
74764- if (security_capable(current_cred(), ns, cap) == 0) {
74765+ if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
74766 current->flags |= PF_SUPERPRIV;
74767 return true;
74768 }
74769@@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
74770 }
74771 EXPORT_SYMBOL(ns_capable);
74772
74773+bool ns_capable_nolog(struct user_namespace *ns, int cap)
74774+{
74775+ if (unlikely(!cap_valid(cap))) {
74776+ printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
74777+ BUG();
74778+ }
74779+
74780+ if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
74781+ current->flags |= PF_SUPERPRIV;
74782+ return true;
74783+ }
74784+ return false;
74785+}
74786+EXPORT_SYMBOL(ns_capable_nolog);
74787+
74788 /**
74789 * file_ns_capable - Determine if the file's opener had a capability in effect
74790 * @file: The file we want to check
74791@@ -432,6 +451,12 @@ bool capable(int cap)
74792 }
74793 EXPORT_SYMBOL(capable);
74794
74795+bool capable_nolog(int cap)
74796+{
74797+ return ns_capable_nolog(&init_user_ns, cap);
74798+}
74799+EXPORT_SYMBOL(capable_nolog);
74800+
74801 /**
74802 * nsown_capable - Check superior capability to one's own user_ns
74803 * @cap: The capability in question
74804@@ -464,3 +489,10 @@ bool inode_capable(const struct inode *inode, int cap)
74805
74806 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74807 }
74808+
74809+bool inode_capable_nolog(const struct inode *inode, int cap)
74810+{
74811+ struct user_namespace *ns = current_user_ns();
74812+
74813+ return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
74814+}
74815diff --git a/kernel/cgroup.c b/kernel/cgroup.c
74816index a48de6a..df24bfe 100644
74817--- a/kernel/cgroup.c
74818+++ b/kernel/cgroup.c
74819@@ -5567,7 +5567,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
74820 struct css_set *cg = link->cg;
74821 struct task_struct *task;
74822 int count = 0;
74823- seq_printf(seq, "css_set %p\n", cg);
74824+ seq_printf(seq, "css_set %pK\n", cg);
74825 list_for_each_entry(task, &cg->tasks, cg_list) {
74826 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
74827 seq_puts(seq, " ...\n");
74828diff --git a/kernel/compat.c b/kernel/compat.c
74829index 19971d8..02fe2df 100644
74830--- a/kernel/compat.c
74831+++ b/kernel/compat.c
74832@@ -13,6 +13,7 @@
74833
74834 #include <linux/linkage.h>
74835 #include <linux/compat.h>
74836+#include <linux/module.h>
74837 #include <linux/errno.h>
74838 #include <linux/time.h>
74839 #include <linux/signal.h>
74840@@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
74841 mm_segment_t oldfs;
74842 long ret;
74843
74844- restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
74845+ restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
74846 oldfs = get_fs();
74847 set_fs(KERNEL_DS);
74848 ret = hrtimer_nanosleep_restart(restart);
74849@@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
74850 oldfs = get_fs();
74851 set_fs(KERNEL_DS);
74852 ret = hrtimer_nanosleep(&tu,
74853- rmtp ? (struct timespec __user *)&rmt : NULL,
74854+ rmtp ? (struct timespec __force_user *)&rmt : NULL,
74855 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
74856 set_fs(oldfs);
74857
74858@@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
74859 mm_segment_t old_fs = get_fs();
74860
74861 set_fs(KERNEL_DS);
74862- ret = sys_sigpending((old_sigset_t __user *) &s);
74863+ ret = sys_sigpending((old_sigset_t __force_user *) &s);
74864 set_fs(old_fs);
74865 if (ret == 0)
74866 ret = put_user(s, set);
74867@@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
74868 mm_segment_t old_fs = get_fs();
74869
74870 set_fs(KERNEL_DS);
74871- ret = sys_old_getrlimit(resource, &r);
74872+ ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
74873 set_fs(old_fs);
74874
74875 if (!ret) {
74876@@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
74877 mm_segment_t old_fs = get_fs();
74878
74879 set_fs(KERNEL_DS);
74880- ret = sys_getrusage(who, (struct rusage __user *) &r);
74881+ ret = sys_getrusage(who, (struct rusage __force_user *) &r);
74882 set_fs(old_fs);
74883
74884 if (ret)
74885@@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
74886 set_fs (KERNEL_DS);
74887 ret = sys_wait4(pid,
74888 (stat_addr ?
74889- (unsigned int __user *) &status : NULL),
74890- options, (struct rusage __user *) &r);
74891+ (unsigned int __force_user *) &status : NULL),
74892+ options, (struct rusage __force_user *) &r);
74893 set_fs (old_fs);
74894
74895 if (ret > 0) {
74896@@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
74897 memset(&info, 0, sizeof(info));
74898
74899 set_fs(KERNEL_DS);
74900- ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
74901- uru ? (struct rusage __user *)&ru : NULL);
74902+ ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
74903+ uru ? (struct rusage __force_user *)&ru : NULL);
74904 set_fs(old_fs);
74905
74906 if ((ret < 0) || (info.si_signo == 0))
74907@@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
74908 oldfs = get_fs();
74909 set_fs(KERNEL_DS);
74910 err = sys_timer_settime(timer_id, flags,
74911- (struct itimerspec __user *) &newts,
74912- (struct itimerspec __user *) &oldts);
74913+ (struct itimerspec __force_user *) &newts,
74914+ (struct itimerspec __force_user *) &oldts);
74915 set_fs(oldfs);
74916 if (!err && old && put_compat_itimerspec(old, &oldts))
74917 return -EFAULT;
74918@@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
74919 oldfs = get_fs();
74920 set_fs(KERNEL_DS);
74921 err = sys_timer_gettime(timer_id,
74922- (struct itimerspec __user *) &ts);
74923+ (struct itimerspec __force_user *) &ts);
74924 set_fs(oldfs);
74925 if (!err && put_compat_itimerspec(setting, &ts))
74926 return -EFAULT;
74927@@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
74928 oldfs = get_fs();
74929 set_fs(KERNEL_DS);
74930 err = sys_clock_settime(which_clock,
74931- (struct timespec __user *) &ts);
74932+ (struct timespec __force_user *) &ts);
74933 set_fs(oldfs);
74934 return err;
74935 }
74936@@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
74937 oldfs = get_fs();
74938 set_fs(KERNEL_DS);
74939 err = sys_clock_gettime(which_clock,
74940- (struct timespec __user *) &ts);
74941+ (struct timespec __force_user *) &ts);
74942 set_fs(oldfs);
74943 if (!err && put_compat_timespec(&ts, tp))
74944 return -EFAULT;
74945@@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
74946
74947 oldfs = get_fs();
74948 set_fs(KERNEL_DS);
74949- ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
74950+ ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
74951 set_fs(oldfs);
74952
74953 err = compat_put_timex(utp, &txc);
74954@@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
74955 oldfs = get_fs();
74956 set_fs(KERNEL_DS);
74957 err = sys_clock_getres(which_clock,
74958- (struct timespec __user *) &ts);
74959+ (struct timespec __force_user *) &ts);
74960 set_fs(oldfs);
74961 if (!err && tp && put_compat_timespec(&ts, tp))
74962 return -EFAULT;
74963@@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
74964 long err;
74965 mm_segment_t oldfs;
74966 struct timespec tu;
74967- struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
74968+ struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
74969
74970- restart->nanosleep.rmtp = (struct timespec __user *) &tu;
74971+ restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
74972 oldfs = get_fs();
74973 set_fs(KERNEL_DS);
74974 err = clock_nanosleep_restart(restart);
74975@@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
74976 oldfs = get_fs();
74977 set_fs(KERNEL_DS);
74978 err = sys_clock_nanosleep(which_clock, flags,
74979- (struct timespec __user *) &in,
74980- (struct timespec __user *) &out);
74981+ (struct timespec __force_user *) &in,
74982+ (struct timespec __force_user *) &out);
74983 set_fs(oldfs);
74984
74985 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
74986diff --git a/kernel/configs.c b/kernel/configs.c
74987index 42e8fa0..9e7406b 100644
74988--- a/kernel/configs.c
74989+++ b/kernel/configs.c
74990@@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
74991 struct proc_dir_entry *entry;
74992
74993 /* create the current config file */
74994+#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
74995+#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
74996+ entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
74997+ &ikconfig_file_ops);
74998+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
74999+ entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
75000+ &ikconfig_file_ops);
75001+#endif
75002+#else
75003 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
75004 &ikconfig_file_ops);
75005+#endif
75006+
75007 if (!entry)
75008 return -ENOMEM;
75009
75010diff --git a/kernel/cred.c b/kernel/cred.c
75011index e0573a4..3874e41 100644
75012--- a/kernel/cred.c
75013+++ b/kernel/cred.c
75014@@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
75015 validate_creds(cred);
75016 alter_cred_subscribers(cred, -1);
75017 put_cred(cred);
75018+
75019+#ifdef CONFIG_GRKERNSEC_SETXID
75020+ cred = (struct cred *) tsk->delayed_cred;
75021+ if (cred != NULL) {
75022+ tsk->delayed_cred = NULL;
75023+ validate_creds(cred);
75024+ alter_cred_subscribers(cred, -1);
75025+ put_cred(cred);
75026+ }
75027+#endif
75028 }
75029
75030 /**
75031@@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
75032 * Always returns 0 thus allowing this function to be tail-called at the end
75033 * of, say, sys_setgid().
75034 */
75035-int commit_creds(struct cred *new)
75036+static int __commit_creds(struct cred *new)
75037 {
75038 struct task_struct *task = current;
75039 const struct cred *old = task->real_cred;
75040@@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
75041
75042 get_cred(new); /* we will require a ref for the subj creds too */
75043
75044+ gr_set_role_label(task, new->uid, new->gid);
75045+
75046 /* dumpability changes */
75047 if (!uid_eq(old->euid, new->euid) ||
75048 !gid_eq(old->egid, new->egid) ||
75049@@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
75050 put_cred(old);
75051 return 0;
75052 }
75053+#ifdef CONFIG_GRKERNSEC_SETXID
75054+extern int set_user(struct cred *new);
75055+
75056+void gr_delayed_cred_worker(void)
75057+{
75058+ const struct cred *new = current->delayed_cred;
75059+ struct cred *ncred;
75060+
75061+ current->delayed_cred = NULL;
75062+
75063+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
75064+ // from doing get_cred on it when queueing this
75065+ put_cred(new);
75066+ return;
75067+ } else if (new == NULL)
75068+ return;
75069+
75070+ ncred = prepare_creds();
75071+ if (!ncred)
75072+ goto die;
75073+ // uids
75074+ ncred->uid = new->uid;
75075+ ncred->euid = new->euid;
75076+ ncred->suid = new->suid;
75077+ ncred->fsuid = new->fsuid;
75078+ // gids
75079+ ncred->gid = new->gid;
75080+ ncred->egid = new->egid;
75081+ ncred->sgid = new->sgid;
75082+ ncred->fsgid = new->fsgid;
75083+ // groups
75084+ if (set_groups(ncred, new->group_info) < 0) {
75085+ abort_creds(ncred);
75086+ goto die;
75087+ }
75088+ // caps
75089+ ncred->securebits = new->securebits;
75090+ ncred->cap_inheritable = new->cap_inheritable;
75091+ ncred->cap_permitted = new->cap_permitted;
75092+ ncred->cap_effective = new->cap_effective;
75093+ ncred->cap_bset = new->cap_bset;
75094+
75095+ if (set_user(ncred)) {
75096+ abort_creds(ncred);
75097+ goto die;
75098+ }
75099+
75100+ // from doing get_cred on it when queueing this
75101+ put_cred(new);
75102+
75103+ __commit_creds(ncred);
75104+ return;
75105+die:
75106+ // from doing get_cred on it when queueing this
75107+ put_cred(new);
75108+ do_group_exit(SIGKILL);
75109+}
75110+#endif
75111+
75112+int commit_creds(struct cred *new)
75113+{
75114+#ifdef CONFIG_GRKERNSEC_SETXID
75115+ int ret;
75116+ int schedule_it = 0;
75117+ struct task_struct *t;
75118+
75119+ /* we won't get called with tasklist_lock held for writing
75120+ and interrupts disabled as the cred struct in that case is
75121+ init_cred
75122+ */
75123+ if (grsec_enable_setxid && !current_is_single_threaded() &&
75124+ uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
75125+ !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
75126+ schedule_it = 1;
75127+ }
75128+ ret = __commit_creds(new);
75129+ if (schedule_it) {
75130+ rcu_read_lock();
75131+ read_lock(&tasklist_lock);
75132+ for (t = next_thread(current); t != current;
75133+ t = next_thread(t)) {
75134+ if (t->delayed_cred == NULL) {
75135+ t->delayed_cred = get_cred(new);
75136+ set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
75137+ set_tsk_need_resched(t);
75138+ }
75139+ }
75140+ read_unlock(&tasklist_lock);
75141+ rcu_read_unlock();
75142+ }
75143+ return ret;
75144+#else
75145+ return __commit_creds(new);
75146+#endif
75147+}
75148+
75149 EXPORT_SYMBOL(commit_creds);
75150
75151 /**
75152diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
75153index c26278f..e323fb8 100644
75154--- a/kernel/debug/debug_core.c
75155+++ b/kernel/debug/debug_core.c
75156@@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
75157 */
75158 static atomic_t masters_in_kgdb;
75159 static atomic_t slaves_in_kgdb;
75160-static atomic_t kgdb_break_tasklet_var;
75161+static atomic_unchecked_t kgdb_break_tasklet_var;
75162 atomic_t kgdb_setting_breakpoint;
75163
75164 struct task_struct *kgdb_usethread;
75165@@ -133,7 +133,7 @@ int kgdb_single_step;
75166 static pid_t kgdb_sstep_pid;
75167
75168 /* to keep track of the CPU which is doing the single stepping*/
75169-atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75170+atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
75171
75172 /*
75173 * If you are debugging a problem where roundup (the collection of
75174@@ -541,7 +541,7 @@ return_normal:
75175 * kernel will only try for the value of sstep_tries before
75176 * giving up and continuing on.
75177 */
75178- if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
75179+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
75180 (kgdb_info[cpu].task &&
75181 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
75182 atomic_set(&kgdb_active, -1);
75183@@ -635,8 +635,8 @@ cpu_master_loop:
75184 }
75185
75186 kgdb_restore:
75187- if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
75188- int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
75189+ if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
75190+ int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
75191 if (kgdb_info[sstep_cpu].task)
75192 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
75193 else
75194@@ -888,18 +888,18 @@ static void kgdb_unregister_callbacks(void)
75195 static void kgdb_tasklet_bpt(unsigned long ing)
75196 {
75197 kgdb_breakpoint();
75198- atomic_set(&kgdb_break_tasklet_var, 0);
75199+ atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
75200 }
75201
75202 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
75203
75204 void kgdb_schedule_breakpoint(void)
75205 {
75206- if (atomic_read(&kgdb_break_tasklet_var) ||
75207+ if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
75208 atomic_read(&kgdb_active) != -1 ||
75209 atomic_read(&kgdb_setting_breakpoint))
75210 return;
75211- atomic_inc(&kgdb_break_tasklet_var);
75212+ atomic_inc_unchecked(&kgdb_break_tasklet_var);
75213 tasklet_schedule(&kgdb_tasklet_breakpoint);
75214 }
75215 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
75216diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
75217index 00eb8f7..d7e3244 100644
75218--- a/kernel/debug/kdb/kdb_main.c
75219+++ b/kernel/debug/kdb/kdb_main.c
75220@@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
75221 continue;
75222
75223 kdb_printf("%-20s%8u 0x%p ", mod->name,
75224- mod->core_size, (void *)mod);
75225+ mod->core_size_rx + mod->core_size_rw, (void *)mod);
75226 #ifdef CONFIG_MODULE_UNLOAD
75227 kdb_printf("%4ld ", module_refcount(mod));
75228 #endif
75229@@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
75230 kdb_printf(" (Loading)");
75231 else
75232 kdb_printf(" (Live)");
75233- kdb_printf(" 0x%p", mod->module_core);
75234+ kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
75235
75236 #ifdef CONFIG_MODULE_UNLOAD
75237 {
75238diff --git a/kernel/events/core.c b/kernel/events/core.c
75239index f8ddcfb..77c06ec 100644
75240--- a/kernel/events/core.c
75241+++ b/kernel/events/core.c
75242@@ -154,8 +154,15 @@ static struct srcu_struct pmus_srcu;
75243 * 0 - disallow raw tracepoint access for unpriv
75244 * 1 - disallow cpu events for unpriv
75245 * 2 - disallow kernel profiling for unpriv
75246+ * 3 - disallow all unpriv perf event use
75247 */
75248-int sysctl_perf_event_paranoid __read_mostly = 1;
75249+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75250+int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
75251+#elif defined(CONFIG_GRKERNSEC_HIDESYM)
75252+int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
75253+#else
75254+int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
75255+#endif
75256
75257 /* Minimum for 512 kiB + 1 user control page */
75258 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
75259@@ -182,7 +189,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
75260 return 0;
75261 }
75262
75263-static atomic64_t perf_event_id;
75264+static atomic64_unchecked_t perf_event_id;
75265
75266 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
75267 enum event_type_t event_type);
75268@@ -2674,7 +2681,7 @@ static void __perf_event_read(void *info)
75269
75270 static inline u64 perf_event_count(struct perf_event *event)
75271 {
75272- return local64_read(&event->count) + atomic64_read(&event->child_count);
75273+ return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
75274 }
75275
75276 static u64 perf_event_read(struct perf_event *event)
75277@@ -3020,9 +3027,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
75278 mutex_lock(&event->child_mutex);
75279 total += perf_event_read(event);
75280 *enabled += event->total_time_enabled +
75281- atomic64_read(&event->child_total_time_enabled);
75282+ atomic64_read_unchecked(&event->child_total_time_enabled);
75283 *running += event->total_time_running +
75284- atomic64_read(&event->child_total_time_running);
75285+ atomic64_read_unchecked(&event->child_total_time_running);
75286
75287 list_for_each_entry(child, &event->child_list, child_list) {
75288 total += perf_event_read(child);
75289@@ -3408,10 +3415,10 @@ void perf_event_update_userpage(struct perf_event *event)
75290 userpg->offset -= local64_read(&event->hw.prev_count);
75291
75292 userpg->time_enabled = enabled +
75293- atomic64_read(&event->child_total_time_enabled);
75294+ atomic64_read_unchecked(&event->child_total_time_enabled);
75295
75296 userpg->time_running = running +
75297- atomic64_read(&event->child_total_time_running);
75298+ atomic64_read_unchecked(&event->child_total_time_running);
75299
75300 arch_perf_update_userpage(userpg, now);
75301
75302@@ -3961,7 +3968,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
75303
75304 /* Data. */
75305 sp = perf_user_stack_pointer(regs);
75306- rem = __output_copy_user(handle, (void *) sp, dump_size);
75307+ rem = __output_copy_user(handle, (void __user *) sp, dump_size);
75308 dyn_size = dump_size - rem;
75309
75310 perf_output_skip(handle, rem);
75311@@ -4049,11 +4056,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
75312 values[n++] = perf_event_count(event);
75313 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
75314 values[n++] = enabled +
75315- atomic64_read(&event->child_total_time_enabled);
75316+ atomic64_read_unchecked(&event->child_total_time_enabled);
75317 }
75318 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
75319 values[n++] = running +
75320- atomic64_read(&event->child_total_time_running);
75321+ atomic64_read_unchecked(&event->child_total_time_running);
75322 }
75323 if (read_format & PERF_FORMAT_ID)
75324 values[n++] = primary_event_id(event);
75325@@ -4801,12 +4808,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
75326 * need to add enough zero bytes after the string to handle
75327 * the 64bit alignment we do later.
75328 */
75329- buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
75330+ buf = kzalloc(PATH_MAX, GFP_KERNEL);
75331 if (!buf) {
75332 name = strncpy(tmp, "//enomem", sizeof(tmp));
75333 goto got_name;
75334 }
75335- name = d_path(&file->f_path, buf, PATH_MAX);
75336+ name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
75337 if (IS_ERR(name)) {
75338 name = strncpy(tmp, "//toolong", sizeof(tmp));
75339 goto got_name;
75340@@ -6242,7 +6249,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
75341 event->parent = parent_event;
75342
75343 event->ns = get_pid_ns(task_active_pid_ns(current));
75344- event->id = atomic64_inc_return(&perf_event_id);
75345+ event->id = atomic64_inc_return_unchecked(&perf_event_id);
75346
75347 event->state = PERF_EVENT_STATE_INACTIVE;
75348
75349@@ -6552,6 +6559,11 @@ SYSCALL_DEFINE5(perf_event_open,
75350 if (flags & ~PERF_FLAG_ALL)
75351 return -EINVAL;
75352
75353+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
75354+ if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
75355+ return -EACCES;
75356+#endif
75357+
75358 err = perf_copy_attr(attr_uptr, &attr);
75359 if (err)
75360 return err;
75361@@ -6884,10 +6896,10 @@ static void sync_child_event(struct perf_event *child_event,
75362 /*
75363 * Add back the child's count to the parent's count:
75364 */
75365- atomic64_add(child_val, &parent_event->child_count);
75366- atomic64_add(child_event->total_time_enabled,
75367+ atomic64_add_unchecked(child_val, &parent_event->child_count);
75368+ atomic64_add_unchecked(child_event->total_time_enabled,
75369 &parent_event->child_total_time_enabled);
75370- atomic64_add(child_event->total_time_running,
75371+ atomic64_add_unchecked(child_event->total_time_running,
75372 &parent_event->child_total_time_running);
75373
75374 /*
75375diff --git a/kernel/events/internal.h b/kernel/events/internal.h
75376index ca65997..cc8cee4 100644
75377--- a/kernel/events/internal.h
75378+++ b/kernel/events/internal.h
75379@@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
75380 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
75381 }
75382
75383-#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
75384+#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
75385 static inline unsigned int \
75386 func_name(struct perf_output_handle *handle, \
75387- const void *buf, unsigned int len) \
75388+ const void user *buf, unsigned int len) \
75389 { \
75390 unsigned long size, written; \
75391 \
75392@@ -116,17 +116,17 @@ static inline int memcpy_common(void *dst, const void *src, size_t n)
75393 return n;
75394 }
75395
75396-DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
75397+DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
75398
75399 #define MEMCPY_SKIP(dst, src, n) (n)
75400
75401-DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP)
75402+DEFINE_OUTPUT_COPY(__output_skip, MEMCPY_SKIP, )
75403
75404 #ifndef arch_perf_out_copy_user
75405 #define arch_perf_out_copy_user __copy_from_user_inatomic
75406 #endif
75407
75408-DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
75409+DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
75410
75411 /* Callchain handling */
75412 extern struct perf_callchain_entry *
75413diff --git a/kernel/exit.c b/kernel/exit.c
75414index 60bc027..ca6d727 100644
75415--- a/kernel/exit.c
75416+++ b/kernel/exit.c
75417@@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
75418 struct task_struct *leader;
75419 int zap_leader;
75420 repeat:
75421+#ifdef CONFIG_NET
75422+ gr_del_task_from_ip_table(p);
75423+#endif
75424+
75425 /* don't need to get the RCU readlock here - the process is dead and
75426 * can't be modifying its own credentials. But shut RCU-lockdep up */
75427 rcu_read_lock();
75428@@ -340,7 +344,7 @@ int allow_signal(int sig)
75429 * know it'll be handled, so that they don't get converted to
75430 * SIGKILL or just silently dropped.
75431 */
75432- current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
75433+ current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
75434 recalc_sigpending();
75435 spin_unlock_irq(&current->sighand->siglock);
75436 return 0;
75437@@ -710,6 +714,8 @@ void do_exit(long code)
75438 struct task_struct *tsk = current;
75439 int group_dead;
75440
75441+ set_fs(USER_DS);
75442+
75443 profile_task_exit(tsk);
75444
75445 WARN_ON(blk_needs_flush_plug(tsk));
75446@@ -726,7 +732,6 @@ void do_exit(long code)
75447 * mm_release()->clear_child_tid() from writing to a user-controlled
75448 * kernel address.
75449 */
75450- set_fs(USER_DS);
75451
75452 ptrace_event(PTRACE_EVENT_EXIT, code);
75453
75454@@ -785,6 +790,9 @@ void do_exit(long code)
75455 tsk->exit_code = code;
75456 taskstats_exit(tsk, group_dead);
75457
75458+ gr_acl_handle_psacct(tsk, code);
75459+ gr_acl_handle_exit();
75460+
75461 exit_mm(tsk);
75462
75463 if (group_dead)
75464@@ -905,7 +913,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
75465 * Take down every thread in the group. This is called by fatal signals
75466 * as well as by sys_exit_group (below).
75467 */
75468-void
75469+__noreturn void
75470 do_group_exit(int exit_code)
75471 {
75472 struct signal_struct *sig = current->signal;
75473diff --git a/kernel/fork.c b/kernel/fork.c
75474index 1766d32..c0e44e2 100644
75475--- a/kernel/fork.c
75476+++ b/kernel/fork.c
75477@@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
75478 *stackend = STACK_END_MAGIC; /* for overflow detection */
75479
75480 #ifdef CONFIG_CC_STACKPROTECTOR
75481- tsk->stack_canary = get_random_int();
75482+ tsk->stack_canary = pax_get_random_long();
75483 #endif
75484
75485 /*
75486@@ -344,13 +344,81 @@ free_tsk:
75487 }
75488
75489 #ifdef CONFIG_MMU
75490+static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
75491+{
75492+ struct vm_area_struct *tmp;
75493+ unsigned long charge;
75494+ struct mempolicy *pol;
75495+ struct file *file;
75496+
75497+ charge = 0;
75498+ if (mpnt->vm_flags & VM_ACCOUNT) {
75499+ unsigned long len = vma_pages(mpnt);
75500+
75501+ if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75502+ goto fail_nomem;
75503+ charge = len;
75504+ }
75505+ tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75506+ if (!tmp)
75507+ goto fail_nomem;
75508+ *tmp = *mpnt;
75509+ tmp->vm_mm = mm;
75510+ INIT_LIST_HEAD(&tmp->anon_vma_chain);
75511+ pol = mpol_dup(vma_policy(mpnt));
75512+ if (IS_ERR(pol))
75513+ goto fail_nomem_policy;
75514+ vma_set_policy(tmp, pol);
75515+ if (anon_vma_fork(tmp, mpnt))
75516+ goto fail_nomem_anon_vma_fork;
75517+ tmp->vm_flags &= ~VM_LOCKED;
75518+ tmp->vm_next = tmp->vm_prev = NULL;
75519+ tmp->vm_mirror = NULL;
75520+ file = tmp->vm_file;
75521+ if (file) {
75522+ struct inode *inode = file_inode(file);
75523+ struct address_space *mapping = file->f_mapping;
75524+
75525+ get_file(file);
75526+ if (tmp->vm_flags & VM_DENYWRITE)
75527+ atomic_dec(&inode->i_writecount);
75528+ mutex_lock(&mapping->i_mmap_mutex);
75529+ if (tmp->vm_flags & VM_SHARED)
75530+ mapping->i_mmap_writable++;
75531+ flush_dcache_mmap_lock(mapping);
75532+ /* insert tmp into the share list, just after mpnt */
75533+ if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75534+ vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
75535+ else
75536+ vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
75537+ flush_dcache_mmap_unlock(mapping);
75538+ mutex_unlock(&mapping->i_mmap_mutex);
75539+ }
75540+
75541+ /*
75542+ * Clear hugetlb-related page reserves for children. This only
75543+ * affects MAP_PRIVATE mappings. Faults generated by the child
75544+ * are not guaranteed to succeed, even if read-only
75545+ */
75546+ if (is_vm_hugetlb_page(tmp))
75547+ reset_vma_resv_huge_pages(tmp);
75548+
75549+ return tmp;
75550+
75551+fail_nomem_anon_vma_fork:
75552+ mpol_put(pol);
75553+fail_nomem_policy:
75554+ kmem_cache_free(vm_area_cachep, tmp);
75555+fail_nomem:
75556+ vm_unacct_memory(charge);
75557+ return NULL;
75558+}
75559+
75560 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75561 {
75562 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
75563 struct rb_node **rb_link, *rb_parent;
75564 int retval;
75565- unsigned long charge;
75566- struct mempolicy *pol;
75567
75568 uprobe_start_dup_mmap();
75569 down_write(&oldmm->mmap_sem);
75570@@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75571 mm->locked_vm = 0;
75572 mm->mmap = NULL;
75573 mm->mmap_cache = NULL;
75574- mm->free_area_cache = oldmm->mmap_base;
75575- mm->cached_hole_size = ~0UL;
75576+ mm->free_area_cache = oldmm->free_area_cache;
75577+ mm->cached_hole_size = oldmm->cached_hole_size;
75578 mm->map_count = 0;
75579 cpumask_clear(mm_cpumask(mm));
75580 mm->mm_rb = RB_ROOT;
75581@@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75582
75583 prev = NULL;
75584 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
75585- struct file *file;
75586-
75587 if (mpnt->vm_flags & VM_DONTCOPY) {
75588 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
75589 -vma_pages(mpnt));
75590 continue;
75591 }
75592- charge = 0;
75593- if (mpnt->vm_flags & VM_ACCOUNT) {
75594- unsigned long len = vma_pages(mpnt);
75595-
75596- if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
75597- goto fail_nomem;
75598- charge = len;
75599- }
75600- tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
75601- if (!tmp)
75602- goto fail_nomem;
75603- *tmp = *mpnt;
75604- INIT_LIST_HEAD(&tmp->anon_vma_chain);
75605- pol = mpol_dup(vma_policy(mpnt));
75606- retval = PTR_ERR(pol);
75607- if (IS_ERR(pol))
75608- goto fail_nomem_policy;
75609- vma_set_policy(tmp, pol);
75610- tmp->vm_mm = mm;
75611- if (anon_vma_fork(tmp, mpnt))
75612- goto fail_nomem_anon_vma_fork;
75613- tmp->vm_flags &= ~VM_LOCKED;
75614- tmp->vm_next = tmp->vm_prev = NULL;
75615- file = tmp->vm_file;
75616- if (file) {
75617- struct inode *inode = file_inode(file);
75618- struct address_space *mapping = file->f_mapping;
75619-
75620- get_file(file);
75621- if (tmp->vm_flags & VM_DENYWRITE)
75622- atomic_dec(&inode->i_writecount);
75623- mutex_lock(&mapping->i_mmap_mutex);
75624- if (tmp->vm_flags & VM_SHARED)
75625- mapping->i_mmap_writable++;
75626- flush_dcache_mmap_lock(mapping);
75627- /* insert tmp into the share list, just after mpnt */
75628- if (unlikely(tmp->vm_flags & VM_NONLINEAR))
75629- vma_nonlinear_insert(tmp,
75630- &mapping->i_mmap_nonlinear);
75631- else
75632- vma_interval_tree_insert_after(tmp, mpnt,
75633- &mapping->i_mmap);
75634- flush_dcache_mmap_unlock(mapping);
75635- mutex_unlock(&mapping->i_mmap_mutex);
75636+ tmp = dup_vma(mm, oldmm, mpnt);
75637+ if (!tmp) {
75638+ retval = -ENOMEM;
75639+ goto out;
75640 }
75641
75642 /*
75643@@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
75644 if (retval)
75645 goto out;
75646 }
75647+
75648+#ifdef CONFIG_PAX_SEGMEXEC
75649+ if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
75650+ struct vm_area_struct *mpnt_m;
75651+
75652+ for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
75653+ BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
75654+
75655+ if (!mpnt->vm_mirror)
75656+ continue;
75657+
75658+ if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
75659+ BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
75660+ mpnt->vm_mirror = mpnt_m;
75661+ } else {
75662+ BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
75663+ mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
75664+ mpnt_m->vm_mirror->vm_mirror = mpnt_m;
75665+ mpnt->vm_mirror->vm_mirror = mpnt;
75666+ }
75667+ }
75668+ BUG_ON(mpnt_m);
75669+ }
75670+#endif
75671+
75672 /* a new mm has just been created */
75673 arch_dup_mmap(oldmm, mm);
75674 retval = 0;
75675@@ -472,14 +523,6 @@ out:
75676 up_write(&oldmm->mmap_sem);
75677 uprobe_end_dup_mmap();
75678 return retval;
75679-fail_nomem_anon_vma_fork:
75680- mpol_put(pol);
75681-fail_nomem_policy:
75682- kmem_cache_free(vm_area_cachep, tmp);
75683-fail_nomem:
75684- retval = -ENOMEM;
75685- vm_unacct_memory(charge);
75686- goto out;
75687 }
75688
75689 static inline int mm_alloc_pgd(struct mm_struct *mm)
75690@@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
75691 return ERR_PTR(err);
75692
75693 mm = get_task_mm(task);
75694- if (mm && mm != current->mm &&
75695- !ptrace_may_access(task, mode)) {
75696+ if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
75697+ (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
75698 mmput(mm);
75699 mm = ERR_PTR(-EACCES);
75700 }
75701@@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
75702 spin_unlock(&fs->lock);
75703 return -EAGAIN;
75704 }
75705- fs->users++;
75706+ atomic_inc(&fs->users);
75707 spin_unlock(&fs->lock);
75708 return 0;
75709 }
75710 tsk->fs = copy_fs_struct(fs);
75711 if (!tsk->fs)
75712 return -ENOMEM;
75713+ /* Carry through gr_chroot_dentry and is_chrooted instead
75714+ of recomputing it here. Already copied when the task struct
75715+ is duplicated. This allows pivot_root to not be treated as
75716+ a chroot
75717+ */
75718+ //gr_set_chroot_entries(tsk, &tsk->fs->root);
75719+
75720 return 0;
75721 }
75722
75723@@ -1196,6 +1246,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75724 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
75725 #endif
75726 retval = -EAGAIN;
75727+
75728+ gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
75729+
75730 if (atomic_read(&p->real_cred->user->processes) >=
75731 task_rlimit(p, RLIMIT_NPROC)) {
75732 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
75733@@ -1441,6 +1494,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
75734 goto bad_fork_free_pid;
75735 }
75736
75737+ /* synchronizes with gr_set_acls()
75738+ we need to call this past the point of no return for fork()
75739+ */
75740+ gr_copy_label(p);
75741+
75742 if (clone_flags & CLONE_THREAD) {
75743 current->signal->nr_threads++;
75744 atomic_inc(&current->signal->live);
75745@@ -1524,6 +1582,8 @@ bad_fork_cleanup_count:
75746 bad_fork_free:
75747 free_task(p);
75748 fork_out:
75749+ gr_log_forkfail(retval);
75750+
75751 return ERR_PTR(retval);
75752 }
75753
75754@@ -1574,6 +1634,23 @@ long do_fork(unsigned long clone_flags,
75755 return -EINVAL;
75756 }
75757
75758+#ifdef CONFIG_GRKERNSEC
75759+ if (clone_flags & CLONE_NEWUSER) {
75760+ /*
75761+ * This doesn't really inspire confidence:
75762+ * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
75763+ * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
75764+ * Increases kernel attack surface in areas developers
75765+ * previously cared little about ("low importance due
75766+ * to requiring "root" capability")
75767+ * To be removed when this code receives *proper* review
75768+ */
75769+ if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
75770+ !capable(CAP_SETGID))
75771+ return -EPERM;
75772+ }
75773+#endif
75774+
75775 /*
75776 * Determine whether and which event to report to ptracer. When
75777 * called from kernel_thread or CLONE_UNTRACED is explicitly
75778@@ -1608,6 +1685,8 @@ long do_fork(unsigned long clone_flags,
75779 if (clone_flags & CLONE_PARENT_SETTID)
75780 put_user(nr, parent_tidptr);
75781
75782+ gr_handle_brute_check();
75783+
75784 if (clone_flags & CLONE_VFORK) {
75785 p->vfork_done = &vfork;
75786 init_completion(&vfork);
75787@@ -1761,7 +1840,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
75788 return 0;
75789
75790 /* don't need lock here; in the worst case we'll do useless copy */
75791- if (fs->users == 1)
75792+ if (atomic_read(&fs->users) == 1)
75793 return 0;
75794
75795 *new_fsp = copy_fs_struct(fs);
75796@@ -1873,7 +1952,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
75797 fs = current->fs;
75798 spin_lock(&fs->lock);
75799 current->fs = new_fs;
75800- if (--fs->users)
75801+ gr_set_chroot_entries(current, &current->fs->root);
75802+ if (atomic_dec_return(&fs->users))
75803 new_fs = NULL;
75804 else
75805 new_fs = fs;
75806diff --git a/kernel/futex.c b/kernel/futex.c
75807index b26dcfc..39e266a 100644
75808--- a/kernel/futex.c
75809+++ b/kernel/futex.c
75810@@ -54,6 +54,7 @@
75811 #include <linux/mount.h>
75812 #include <linux/pagemap.h>
75813 #include <linux/syscalls.h>
75814+#include <linux/ptrace.h>
75815 #include <linux/signal.h>
75816 #include <linux/export.h>
75817 #include <linux/magic.h>
75818@@ -241,6 +242,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
75819 struct page *page, *page_head;
75820 int err, ro = 0;
75821
75822+#ifdef CONFIG_PAX_SEGMEXEC
75823+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
75824+ return -EFAULT;
75825+#endif
75826+
75827 /*
75828 * The futex address must be "naturally" aligned.
75829 */
75830@@ -2732,6 +2738,7 @@ static int __init futex_init(void)
75831 {
75832 u32 curval;
75833 int i;
75834+ mm_segment_t oldfs;
75835
75836 /*
75837 * This will fail and we want it. Some arch implementations do
75838@@ -2743,8 +2750,11 @@ static int __init futex_init(void)
75839 * implementation, the non-functional ones will return
75840 * -ENOSYS.
75841 */
75842+ oldfs = get_fs();
75843+ set_fs(USER_DS);
75844 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
75845 futex_cmpxchg_enabled = 1;
75846+ set_fs(oldfs);
75847
75848 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
75849 plist_head_init(&futex_queues[i].chain);
75850diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
75851index f9f44fd..29885e4 100644
75852--- a/kernel/futex_compat.c
75853+++ b/kernel/futex_compat.c
75854@@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
75855 return 0;
75856 }
75857
75858-static void __user *futex_uaddr(struct robust_list __user *entry,
75859+static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
75860 compat_long_t futex_offset)
75861 {
75862 compat_uptr_t base = ptr_to_compat(entry);
75863diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
75864index 9b22d03..6295b62 100644
75865--- a/kernel/gcov/base.c
75866+++ b/kernel/gcov/base.c
75867@@ -102,11 +102,6 @@ void gcov_enable_events(void)
75868 }
75869
75870 #ifdef CONFIG_MODULES
75871-static inline int within(void *addr, void *start, unsigned long size)
75872-{
75873- return ((addr >= start) && (addr < start + size));
75874-}
75875-
75876 /* Update list and generate events when modules are unloaded. */
75877 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75878 void *data)
75879@@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
75880 prev = NULL;
75881 /* Remove entries located in module from linked list. */
75882 for (info = gcov_info_head; info; info = info->next) {
75883- if (within(info, mod->module_core, mod->core_size)) {
75884+ if (within_module_core_rw((unsigned long)info, mod)) {
75885 if (prev)
75886 prev->next = info->next;
75887 else
75888diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
75889index 7ef5556..8247f11 100644
75890--- a/kernel/hrtimer.c
75891+++ b/kernel/hrtimer.c
75892@@ -1416,7 +1416,7 @@ void hrtimer_peek_ahead_timers(void)
75893 local_irq_restore(flags);
75894 }
75895
75896-static void run_hrtimer_softirq(struct softirq_action *h)
75897+static void run_hrtimer_softirq(void)
75898 {
75899 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
75900
75901@@ -1758,7 +1758,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
75902 return NOTIFY_OK;
75903 }
75904
75905-static struct notifier_block __cpuinitdata hrtimers_nb = {
75906+static struct notifier_block hrtimers_nb = {
75907 .notifier_call = hrtimer_cpu_notify,
75908 };
75909
75910diff --git a/kernel/irq_work.c b/kernel/irq_work.c
75911index 55fcce6..0e4cf34 100644
75912--- a/kernel/irq_work.c
75913+++ b/kernel/irq_work.c
75914@@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
75915 return NOTIFY_OK;
75916 }
75917
75918-static struct notifier_block cpu_notify;
75919+static struct notifier_block cpu_notify = {
75920+ .notifier_call = irq_work_cpu_notify,
75921+ .priority = 0,
75922+};
75923
75924 static __init int irq_work_init_cpu_notifier(void)
75925 {
75926- cpu_notify.notifier_call = irq_work_cpu_notify;
75927- cpu_notify.priority = 0;
75928 register_cpu_notifier(&cpu_notify);
75929 return 0;
75930 }
75931diff --git a/kernel/jump_label.c b/kernel/jump_label.c
75932index 60f48fa..7f3a770 100644
75933--- a/kernel/jump_label.c
75934+++ b/kernel/jump_label.c
75935@@ -13,6 +13,7 @@
75936 #include <linux/sort.h>
75937 #include <linux/err.h>
75938 #include <linux/static_key.h>
75939+#include <linux/mm.h>
75940
75941 #ifdef HAVE_JUMP_LABEL
75942
75943@@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
75944
75945 size = (((unsigned long)stop - (unsigned long)start)
75946 / sizeof(struct jump_entry));
75947+ pax_open_kernel();
75948 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
75949+ pax_close_kernel();
75950 }
75951
75952 static void jump_label_update(struct static_key *key, int enable);
75953@@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
75954 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
75955 struct jump_entry *iter;
75956
75957+ pax_open_kernel();
75958 for (iter = iter_start; iter < iter_stop; iter++) {
75959 if (within_module_init(iter->code, mod))
75960 iter->code = 0;
75961 }
75962+ pax_close_kernel();
75963 }
75964
75965 static int
75966diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
75967index 2169fee..706ccca 100644
75968--- a/kernel/kallsyms.c
75969+++ b/kernel/kallsyms.c
75970@@ -11,6 +11,9 @@
75971 * Changed the compression method from stem compression to "table lookup"
75972 * compression (see scripts/kallsyms.c for a more complete description)
75973 */
75974+#ifdef CONFIG_GRKERNSEC_HIDESYM
75975+#define __INCLUDED_BY_HIDESYM 1
75976+#endif
75977 #include <linux/kallsyms.h>
75978 #include <linux/module.h>
75979 #include <linux/init.h>
75980@@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
75981
75982 static inline int is_kernel_inittext(unsigned long addr)
75983 {
75984+ if (system_state != SYSTEM_BOOTING)
75985+ return 0;
75986+
75987 if (addr >= (unsigned long)_sinittext
75988 && addr <= (unsigned long)_einittext)
75989 return 1;
75990 return 0;
75991 }
75992
75993+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75994+#ifdef CONFIG_MODULES
75995+static inline int is_module_text(unsigned long addr)
75996+{
75997+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
75998+ return 1;
75999+
76000+ addr = ktla_ktva(addr);
76001+ return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
76002+}
76003+#else
76004+static inline int is_module_text(unsigned long addr)
76005+{
76006+ return 0;
76007+}
76008+#endif
76009+#endif
76010+
76011 static inline int is_kernel_text(unsigned long addr)
76012 {
76013 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
76014@@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
76015
76016 static inline int is_kernel(unsigned long addr)
76017 {
76018+
76019+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76020+ if (is_kernel_text(addr) || is_kernel_inittext(addr))
76021+ return 1;
76022+
76023+ if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
76024+#else
76025 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
76026+#endif
76027+
76028 return 1;
76029 return in_gate_area_no_mm(addr);
76030 }
76031
76032 static int is_ksym_addr(unsigned long addr)
76033 {
76034+
76035+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
76036+ if (is_module_text(addr))
76037+ return 0;
76038+#endif
76039+
76040 if (all_var)
76041 return is_kernel(addr);
76042
76043@@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
76044
76045 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
76046 {
76047- iter->name[0] = '\0';
76048 iter->nameoff = get_symbol_offset(new_pos);
76049 iter->pos = new_pos;
76050 }
76051@@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
76052 {
76053 struct kallsym_iter *iter = m->private;
76054
76055+#ifdef CONFIG_GRKERNSEC_HIDESYM
76056+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
76057+ return 0;
76058+#endif
76059+
76060 /* Some debugging symbols have no name. Ignore them. */
76061 if (!iter->name[0])
76062 return 0;
76063@@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
76064 */
76065 type = iter->exported ? toupper(iter->type) :
76066 tolower(iter->type);
76067+
76068 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
76069 type, iter->name, iter->module_name);
76070 } else
76071@@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
76072 struct kallsym_iter *iter;
76073 int ret;
76074
76075- iter = kmalloc(sizeof(*iter), GFP_KERNEL);
76076+ iter = kzalloc(sizeof(*iter), GFP_KERNEL);
76077 if (!iter)
76078 return -ENOMEM;
76079 reset_iter(iter, 0);
76080diff --git a/kernel/kcmp.c b/kernel/kcmp.c
76081index e30ac0f..3528cac 100644
76082--- a/kernel/kcmp.c
76083+++ b/kernel/kcmp.c
76084@@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
76085 struct task_struct *task1, *task2;
76086 int ret;
76087
76088+#ifdef CONFIG_GRKERNSEC
76089+ return -ENOSYS;
76090+#endif
76091+
76092 rcu_read_lock();
76093
76094 /*
76095diff --git a/kernel/kexec.c b/kernel/kexec.c
76096index ffd4e11..c3ff6bf 100644
76097--- a/kernel/kexec.c
76098+++ b/kernel/kexec.c
76099@@ -1048,7 +1048,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
76100 unsigned long flags)
76101 {
76102 struct compat_kexec_segment in;
76103- struct kexec_segment out, __user *ksegments;
76104+ struct kexec_segment out;
76105+ struct kexec_segment __user *ksegments;
76106 unsigned long i, result;
76107
76108 /* Don't allow clients that don't understand the native
76109diff --git a/kernel/kmod.c b/kernel/kmod.c
76110index 8985c87..f539dbe 100644
76111--- a/kernel/kmod.c
76112+++ b/kernel/kmod.c
76113@@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
76114 kfree(info->argv);
76115 }
76116
76117-static int call_modprobe(char *module_name, int wait)
76118+static int call_modprobe(char *module_name, char *module_param, int wait)
76119 {
76120 static char *envp[] = {
76121 "HOME=/",
76122@@ -84,7 +84,7 @@ static int call_modprobe(char *module_name, int wait)
76123 NULL
76124 };
76125
76126- char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
76127+ char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
76128 if (!argv)
76129 goto out;
76130
76131@@ -96,7 +96,8 @@ static int call_modprobe(char *module_name, int wait)
76132 argv[1] = "-q";
76133 argv[2] = "--";
76134 argv[3] = module_name; /* check free_modprobe_argv() */
76135- argv[4] = NULL;
76136+ argv[4] = module_param;
76137+ argv[5] = NULL;
76138
76139 return call_usermodehelper_fns(modprobe_path, argv, envp,
76140 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
76141@@ -121,9 +122,8 @@ out:
76142 * If module auto-loading support is disabled then this function
76143 * becomes a no-operation.
76144 */
76145-int __request_module(bool wait, const char *fmt, ...)
76146+static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
76147 {
76148- va_list args;
76149 char module_name[MODULE_NAME_LEN];
76150 unsigned int max_modprobes;
76151 int ret;
76152@@ -139,9 +139,7 @@ int __request_module(bool wait, const char *fmt, ...)
76153 */
76154 WARN_ON_ONCE(wait && current_is_async());
76155
76156- va_start(args, fmt);
76157- ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
76158- va_end(args);
76159+ ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
76160 if (ret >= MODULE_NAME_LEN)
76161 return -ENAMETOOLONG;
76162
76163@@ -149,6 +147,20 @@ int __request_module(bool wait, const char *fmt, ...)
76164 if (ret)
76165 return ret;
76166
76167+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76168+ if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76169+ /* hack to workaround consolekit/udisks stupidity */
76170+ read_lock(&tasklist_lock);
76171+ if (!strcmp(current->comm, "mount") &&
76172+ current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
76173+ read_unlock(&tasklist_lock);
76174+ printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
76175+ return -EPERM;
76176+ }
76177+ read_unlock(&tasklist_lock);
76178+ }
76179+#endif
76180+
76181 /* If modprobe needs a service that is in a module, we get a recursive
76182 * loop. Limit the number of running kmod threads to max_threads/2 or
76183 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
76184@@ -177,11 +189,52 @@ int __request_module(bool wait, const char *fmt, ...)
76185
76186 trace_module_request(module_name, wait, _RET_IP_);
76187
76188- ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76189+ ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
76190
76191 atomic_dec(&kmod_concurrent);
76192 return ret;
76193 }
76194+
76195+int ___request_module(bool wait, char *module_param, const char *fmt, ...)
76196+{
76197+ va_list args;
76198+ int ret;
76199+
76200+ va_start(args, fmt);
76201+ ret = ____request_module(wait, module_param, fmt, args);
76202+ va_end(args);
76203+
76204+ return ret;
76205+}
76206+
76207+int __request_module(bool wait, const char *fmt, ...)
76208+{
76209+ va_list args;
76210+ int ret;
76211+
76212+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76213+ if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
76214+ char module_param[MODULE_NAME_LEN];
76215+
76216+ memset(module_param, 0, sizeof(module_param));
76217+
76218+ snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
76219+
76220+ va_start(args, fmt);
76221+ ret = ____request_module(wait, module_param, fmt, args);
76222+ va_end(args);
76223+
76224+ return ret;
76225+ }
76226+#endif
76227+
76228+ va_start(args, fmt);
76229+ ret = ____request_module(wait, NULL, fmt, args);
76230+ va_end(args);
76231+
76232+ return ret;
76233+}
76234+
76235 EXPORT_SYMBOL(__request_module);
76236 #endif /* CONFIG_MODULES */
76237
76238@@ -292,7 +345,7 @@ static int wait_for_helper(void *data)
76239 *
76240 * Thus the __user pointer cast is valid here.
76241 */
76242- sys_wait4(pid, (int __user *)&ret, 0, NULL);
76243+ sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
76244
76245 /*
76246 * If ret is 0, either ____call_usermodehelper failed and the
76247@@ -649,7 +702,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
76248 static int proc_cap_handler(struct ctl_table *table, int write,
76249 void __user *buffer, size_t *lenp, loff_t *ppos)
76250 {
76251- struct ctl_table t;
76252+ ctl_table_no_const t;
76253 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
76254 kernel_cap_t new_cap;
76255 int err, i;
76256diff --git a/kernel/kprobes.c b/kernel/kprobes.c
76257index 3fed7f0..a3f95ed 100644
76258--- a/kernel/kprobes.c
76259+++ b/kernel/kprobes.c
76260@@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
76261 * kernel image and loaded module images reside. This is required
76262 * so x86_64 can correctly handle the %rip-relative fixups.
76263 */
76264- kip->insns = module_alloc(PAGE_SIZE);
76265+ kip->insns = module_alloc_exec(PAGE_SIZE);
76266 if (!kip->insns) {
76267 kfree(kip);
76268 return NULL;
76269@@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
76270 */
76271 if (!list_is_singular(&kip->list)) {
76272 list_del(&kip->list);
76273- module_free(NULL, kip->insns);
76274+ module_free_exec(NULL, kip->insns);
76275 kfree(kip);
76276 }
76277 return 1;
76278@@ -2073,7 +2073,7 @@ static int __init init_kprobes(void)
76279 {
76280 int i, err = 0;
76281 unsigned long offset = 0, size = 0;
76282- char *modname, namebuf[128];
76283+ char *modname, namebuf[KSYM_NAME_LEN];
76284 const char *symbol_name;
76285 void *addr;
76286 struct kprobe_blackpoint *kb;
76287@@ -2158,11 +2158,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
76288 kprobe_type = "k";
76289
76290 if (sym)
76291- seq_printf(pi, "%p %s %s+0x%x %s ",
76292+ seq_printf(pi, "%pK %s %s+0x%x %s ",
76293 p->addr, kprobe_type, sym, offset,
76294 (modname ? modname : " "));
76295 else
76296- seq_printf(pi, "%p %s %p ",
76297+ seq_printf(pi, "%pK %s %pK ",
76298 p->addr, kprobe_type, p->addr);
76299
76300 if (!pp)
76301@@ -2199,7 +2199,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
76302 const char *sym = NULL;
76303 unsigned int i = *(loff_t *) v;
76304 unsigned long offset = 0;
76305- char *modname, namebuf[128];
76306+ char *modname, namebuf[KSYM_NAME_LEN];
76307
76308 head = &kprobe_table[i];
76309 preempt_disable();
76310diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
76311index 6ada93c..dce7d5d 100644
76312--- a/kernel/ksysfs.c
76313+++ b/kernel/ksysfs.c
76314@@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
76315 {
76316 if (count+1 > UEVENT_HELPER_PATH_LEN)
76317 return -ENOENT;
76318+ if (!capable(CAP_SYS_ADMIN))
76319+ return -EPERM;
76320 memcpy(uevent_helper, buf, count);
76321 uevent_helper[count] = '\0';
76322 if (count && uevent_helper[count-1] == '\n')
76323@@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
76324 return count;
76325 }
76326
76327-static struct bin_attribute notes_attr = {
76328+static bin_attribute_no_const notes_attr __read_only = {
76329 .attr = {
76330 .name = "notes",
76331 .mode = S_IRUGO,
76332diff --git a/kernel/lockdep.c b/kernel/lockdep.c
76333index 8a0efac..56f1e2d 100644
76334--- a/kernel/lockdep.c
76335+++ b/kernel/lockdep.c
76336@@ -590,6 +590,10 @@ static int static_obj(void *obj)
76337 end = (unsigned long) &_end,
76338 addr = (unsigned long) obj;
76339
76340+#ifdef CONFIG_PAX_KERNEXEC
76341+ start = ktla_ktva(start);
76342+#endif
76343+
76344 /*
76345 * static variable?
76346 */
76347@@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
76348 if (!static_obj(lock->key)) {
76349 debug_locks_off();
76350 printk("INFO: trying to register non-static key.\n");
76351+ printk("lock:%pS key:%pS.\n", lock, lock->key);
76352 printk("the code is fine but needs lockdep annotation.\n");
76353 printk("turning off the locking correctness validator.\n");
76354 dump_stack();
76355@@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
76356 if (!class)
76357 return 0;
76358 }
76359- atomic_inc((atomic_t *)&class->ops);
76360+ atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
76361 if (very_verbose(class)) {
76362 printk("\nacquire class [%p] %s", class->key, class->name);
76363 if (class->name_version > 1)
76364diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
76365index b2c71c5..7b88d63 100644
76366--- a/kernel/lockdep_proc.c
76367+++ b/kernel/lockdep_proc.c
76368@@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
76369 return 0;
76370 }
76371
76372- seq_printf(m, "%p", class->key);
76373+ seq_printf(m, "%pK", class->key);
76374 #ifdef CONFIG_DEBUG_LOCKDEP
76375 seq_printf(m, " OPS:%8ld", class->ops);
76376 #endif
76377@@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
76378
76379 list_for_each_entry(entry, &class->locks_after, entry) {
76380 if (entry->distance == 1) {
76381- seq_printf(m, " -> [%p] ", entry->class->key);
76382+ seq_printf(m, " -> [%pK] ", entry->class->key);
76383 print_name(m, entry->class);
76384 seq_puts(m, "\n");
76385 }
76386@@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
76387 if (!class->key)
76388 continue;
76389
76390- seq_printf(m, "[%p] ", class->key);
76391+ seq_printf(m, "[%pK] ", class->key);
76392 print_name(m, class);
76393 seq_puts(m, "\n");
76394 }
76395@@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76396 if (!i)
76397 seq_line(m, '-', 40-namelen, namelen);
76398
76399- snprintf(ip, sizeof(ip), "[<%p>]",
76400+ snprintf(ip, sizeof(ip), "[<%pK>]",
76401 (void *)class->contention_point[i]);
76402 seq_printf(m, "%40s %14lu %29s %pS\n",
76403 name, stats->contention_point[i],
76404@@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
76405 if (!i)
76406 seq_line(m, '-', 40-namelen, namelen);
76407
76408- snprintf(ip, sizeof(ip), "[<%p>]",
76409+ snprintf(ip, sizeof(ip), "[<%pK>]",
76410 (void *)class->contending_point[i]);
76411 seq_printf(m, "%40s %14lu %29s %pS\n",
76412 name, stats->contending_point[i],
76413diff --git a/kernel/module.c b/kernel/module.c
76414index 97f202c..109575f 100644
76415--- a/kernel/module.c
76416+++ b/kernel/module.c
76417@@ -61,6 +61,7 @@
76418 #include <linux/pfn.h>
76419 #include <linux/bsearch.h>
76420 #include <linux/fips.h>
76421+#include <linux/grsecurity.h>
76422 #include <uapi/linux/module.h>
76423 #include "module-internal.h"
76424
76425@@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
76426
76427 /* Bounds of module allocation, for speeding __module_address.
76428 * Protected by module_mutex. */
76429-static unsigned long module_addr_min = -1UL, module_addr_max = 0;
76430+static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
76431+static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
76432
76433 int register_module_notifier(struct notifier_block * nb)
76434 {
76435@@ -323,7 +325,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76436 return true;
76437
76438 list_for_each_entry_rcu(mod, &modules, list) {
76439- struct symsearch arr[] = {
76440+ struct symsearch modarr[] = {
76441 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
76442 NOT_GPL_ONLY, false },
76443 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
76444@@ -348,7 +350,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
76445 if (mod->state == MODULE_STATE_UNFORMED)
76446 continue;
76447
76448- if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
76449+ if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
76450 return true;
76451 }
76452 return false;
76453@@ -485,7 +487,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
76454 static int percpu_modalloc(struct module *mod,
76455 unsigned long size, unsigned long align)
76456 {
76457- if (align > PAGE_SIZE) {
76458+ if (align-1 >= PAGE_SIZE) {
76459 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
76460 mod->name, align, PAGE_SIZE);
76461 align = PAGE_SIZE;
76462@@ -1089,7 +1091,7 @@ struct module_attribute module_uevent =
76463 static ssize_t show_coresize(struct module_attribute *mattr,
76464 struct module_kobject *mk, char *buffer)
76465 {
76466- return sprintf(buffer, "%u\n", mk->mod->core_size);
76467+ return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
76468 }
76469
76470 static struct module_attribute modinfo_coresize =
76471@@ -1098,7 +1100,7 @@ static struct module_attribute modinfo_coresize =
76472 static ssize_t show_initsize(struct module_attribute *mattr,
76473 struct module_kobject *mk, char *buffer)
76474 {
76475- return sprintf(buffer, "%u\n", mk->mod->init_size);
76476+ return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
76477 }
76478
76479 static struct module_attribute modinfo_initsize =
76480@@ -1312,7 +1314,7 @@ resolve_symbol_wait(struct module *mod,
76481 */
76482 #ifdef CONFIG_SYSFS
76483
76484-#ifdef CONFIG_KALLSYMS
76485+#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
76486 static inline bool sect_empty(const Elf_Shdr *sect)
76487 {
76488 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
76489@@ -1452,7 +1454,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
76490 {
76491 unsigned int notes, loaded, i;
76492 struct module_notes_attrs *notes_attrs;
76493- struct bin_attribute *nattr;
76494+ bin_attribute_no_const *nattr;
76495
76496 /* failed to create section attributes, so can't create notes */
76497 if (!mod->sect_attrs)
76498@@ -1564,7 +1566,7 @@ static void del_usage_links(struct module *mod)
76499 static int module_add_modinfo_attrs(struct module *mod)
76500 {
76501 struct module_attribute *attr;
76502- struct module_attribute *temp_attr;
76503+ module_attribute_no_const *temp_attr;
76504 int error = 0;
76505 int i;
76506
76507@@ -1778,21 +1780,21 @@ static void set_section_ro_nx(void *base,
76508
76509 static void unset_module_core_ro_nx(struct module *mod)
76510 {
76511- set_page_attributes(mod->module_core + mod->core_text_size,
76512- mod->module_core + mod->core_size,
76513+ set_page_attributes(mod->module_core_rw,
76514+ mod->module_core_rw + mod->core_size_rw,
76515 set_memory_x);
76516- set_page_attributes(mod->module_core,
76517- mod->module_core + mod->core_ro_size,
76518+ set_page_attributes(mod->module_core_rx,
76519+ mod->module_core_rx + mod->core_size_rx,
76520 set_memory_rw);
76521 }
76522
76523 static void unset_module_init_ro_nx(struct module *mod)
76524 {
76525- set_page_attributes(mod->module_init + mod->init_text_size,
76526- mod->module_init + mod->init_size,
76527+ set_page_attributes(mod->module_init_rw,
76528+ mod->module_init_rw + mod->init_size_rw,
76529 set_memory_x);
76530- set_page_attributes(mod->module_init,
76531- mod->module_init + mod->init_ro_size,
76532+ set_page_attributes(mod->module_init_rx,
76533+ mod->module_init_rx + mod->init_size_rx,
76534 set_memory_rw);
76535 }
76536
76537@@ -1805,14 +1807,14 @@ void set_all_modules_text_rw(void)
76538 list_for_each_entry_rcu(mod, &modules, list) {
76539 if (mod->state == MODULE_STATE_UNFORMED)
76540 continue;
76541- if ((mod->module_core) && (mod->core_text_size)) {
76542- set_page_attributes(mod->module_core,
76543- mod->module_core + mod->core_text_size,
76544+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76545+ set_page_attributes(mod->module_core_rx,
76546+ mod->module_core_rx + mod->core_size_rx,
76547 set_memory_rw);
76548 }
76549- if ((mod->module_init) && (mod->init_text_size)) {
76550- set_page_attributes(mod->module_init,
76551- mod->module_init + mod->init_text_size,
76552+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76553+ set_page_attributes(mod->module_init_rx,
76554+ mod->module_init_rx + mod->init_size_rx,
76555 set_memory_rw);
76556 }
76557 }
76558@@ -1828,14 +1830,14 @@ void set_all_modules_text_ro(void)
76559 list_for_each_entry_rcu(mod, &modules, list) {
76560 if (mod->state == MODULE_STATE_UNFORMED)
76561 continue;
76562- if ((mod->module_core) && (mod->core_text_size)) {
76563- set_page_attributes(mod->module_core,
76564- mod->module_core + mod->core_text_size,
76565+ if ((mod->module_core_rx) && (mod->core_size_rx)) {
76566+ set_page_attributes(mod->module_core_rx,
76567+ mod->module_core_rx + mod->core_size_rx,
76568 set_memory_ro);
76569 }
76570- if ((mod->module_init) && (mod->init_text_size)) {
76571- set_page_attributes(mod->module_init,
76572- mod->module_init + mod->init_text_size,
76573+ if ((mod->module_init_rx) && (mod->init_size_rx)) {
76574+ set_page_attributes(mod->module_init_rx,
76575+ mod->module_init_rx + mod->init_size_rx,
76576 set_memory_ro);
76577 }
76578 }
76579@@ -1886,16 +1888,19 @@ static void free_module(struct module *mod)
76580
76581 /* This may be NULL, but that's OK */
76582 unset_module_init_ro_nx(mod);
76583- module_free(mod, mod->module_init);
76584+ module_free(mod, mod->module_init_rw);
76585+ module_free_exec(mod, mod->module_init_rx);
76586 kfree(mod->args);
76587 percpu_modfree(mod);
76588
76589 /* Free lock-classes: */
76590- lockdep_free_key_range(mod->module_core, mod->core_size);
76591+ lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
76592+ lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
76593
76594 /* Finally, free the core (containing the module structure) */
76595 unset_module_core_ro_nx(mod);
76596- module_free(mod, mod->module_core);
76597+ module_free_exec(mod, mod->module_core_rx);
76598+ module_free(mod, mod->module_core_rw);
76599
76600 #ifdef CONFIG_MPU
76601 update_protections(current->mm);
76602@@ -1965,9 +1970,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76603 int ret = 0;
76604 const struct kernel_symbol *ksym;
76605
76606+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76607+ int is_fs_load = 0;
76608+ int register_filesystem_found = 0;
76609+ char *p;
76610+
76611+ p = strstr(mod->args, "grsec_modharden_fs");
76612+ if (p) {
76613+ char *endptr = p + sizeof("grsec_modharden_fs") - 1;
76614+ /* copy \0 as well */
76615+ memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
76616+ is_fs_load = 1;
76617+ }
76618+#endif
76619+
76620 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
76621 const char *name = info->strtab + sym[i].st_name;
76622
76623+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76624+ /* it's a real shame this will never get ripped and copied
76625+ upstream! ;(
76626+ */
76627+ if (is_fs_load && !strcmp(name, "register_filesystem"))
76628+ register_filesystem_found = 1;
76629+#endif
76630+
76631 switch (sym[i].st_shndx) {
76632 case SHN_COMMON:
76633 /* We compiled with -fno-common. These are not
76634@@ -1988,7 +2015,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76635 ksym = resolve_symbol_wait(mod, info, name);
76636 /* Ok if resolved. */
76637 if (ksym && !IS_ERR(ksym)) {
76638+ pax_open_kernel();
76639 sym[i].st_value = ksym->value;
76640+ pax_close_kernel();
76641 break;
76642 }
76643
76644@@ -2007,11 +2036,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
76645 secbase = (unsigned long)mod_percpu(mod);
76646 else
76647 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
76648+ pax_open_kernel();
76649 sym[i].st_value += secbase;
76650+ pax_close_kernel();
76651 break;
76652 }
76653 }
76654
76655+#ifdef CONFIG_GRKERNSEC_MODHARDEN
76656+ if (is_fs_load && !register_filesystem_found) {
76657+ printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
76658+ ret = -EPERM;
76659+ }
76660+#endif
76661+
76662 return ret;
76663 }
76664
76665@@ -2095,22 +2133,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
76666 || s->sh_entsize != ~0UL
76667 || strstarts(sname, ".init"))
76668 continue;
76669- s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
76670+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76671+ s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
76672+ else
76673+ s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
76674 pr_debug("\t%s\n", sname);
76675 }
76676- switch (m) {
76677- case 0: /* executable */
76678- mod->core_size = debug_align(mod->core_size);
76679- mod->core_text_size = mod->core_size;
76680- break;
76681- case 1: /* RO: text and ro-data */
76682- mod->core_size = debug_align(mod->core_size);
76683- mod->core_ro_size = mod->core_size;
76684- break;
76685- case 3: /* whole core */
76686- mod->core_size = debug_align(mod->core_size);
76687- break;
76688- }
76689 }
76690
76691 pr_debug("Init section allocation order:\n");
76692@@ -2124,23 +2152,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
76693 || s->sh_entsize != ~0UL
76694 || !strstarts(sname, ".init"))
76695 continue;
76696- s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
76697- | INIT_OFFSET_MASK);
76698+ if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
76699+ s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
76700+ else
76701+ s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
76702+ s->sh_entsize |= INIT_OFFSET_MASK;
76703 pr_debug("\t%s\n", sname);
76704 }
76705- switch (m) {
76706- case 0: /* executable */
76707- mod->init_size = debug_align(mod->init_size);
76708- mod->init_text_size = mod->init_size;
76709- break;
76710- case 1: /* RO: text and ro-data */
76711- mod->init_size = debug_align(mod->init_size);
76712- mod->init_ro_size = mod->init_size;
76713- break;
76714- case 3: /* whole init */
76715- mod->init_size = debug_align(mod->init_size);
76716- break;
76717- }
76718 }
76719 }
76720
76721@@ -2313,7 +2331,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76722
76723 /* Put symbol section at end of init part of module. */
76724 symsect->sh_flags |= SHF_ALLOC;
76725- symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
76726+ symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
76727 info->index.sym) | INIT_OFFSET_MASK;
76728 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
76729
76730@@ -2330,13 +2348,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
76731 }
76732
76733 /* Append room for core symbols at end of core part. */
76734- info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
76735- info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
76736- mod->core_size += strtab_size;
76737+ info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
76738+ info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
76739+ mod->core_size_rx += strtab_size;
76740
76741 /* Put string table section at end of init part of module. */
76742 strsect->sh_flags |= SHF_ALLOC;
76743- strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
76744+ strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
76745 info->index.str) | INIT_OFFSET_MASK;
76746 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
76747 }
76748@@ -2354,12 +2372,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76749 /* Make sure we get permanent strtab: don't use info->strtab. */
76750 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
76751
76752+ pax_open_kernel();
76753+
76754 /* Set types up while we still have access to sections. */
76755 for (i = 0; i < mod->num_symtab; i++)
76756 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
76757
76758- mod->core_symtab = dst = mod->module_core + info->symoffs;
76759- mod->core_strtab = s = mod->module_core + info->stroffs;
76760+ mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
76761+ mod->core_strtab = s = mod->module_core_rx + info->stroffs;
76762 src = mod->symtab;
76763 for (ndst = i = 0; i < mod->num_symtab; i++) {
76764 if (i == 0 ||
76765@@ -2371,6 +2391,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
76766 }
76767 }
76768 mod->core_num_syms = ndst;
76769+
76770+ pax_close_kernel();
76771 }
76772 #else
76773 static inline void layout_symtab(struct module *mod, struct load_info *info)
76774@@ -2404,17 +2426,33 @@ void * __weak module_alloc(unsigned long size)
76775 return vmalloc_exec(size);
76776 }
76777
76778-static void *module_alloc_update_bounds(unsigned long size)
76779+static void *module_alloc_update_bounds_rw(unsigned long size)
76780 {
76781 void *ret = module_alloc(size);
76782
76783 if (ret) {
76784 mutex_lock(&module_mutex);
76785 /* Update module bounds. */
76786- if ((unsigned long)ret < module_addr_min)
76787- module_addr_min = (unsigned long)ret;
76788- if ((unsigned long)ret + size > module_addr_max)
76789- module_addr_max = (unsigned long)ret + size;
76790+ if ((unsigned long)ret < module_addr_min_rw)
76791+ module_addr_min_rw = (unsigned long)ret;
76792+ if ((unsigned long)ret + size > module_addr_max_rw)
76793+ module_addr_max_rw = (unsigned long)ret + size;
76794+ mutex_unlock(&module_mutex);
76795+ }
76796+ return ret;
76797+}
76798+
76799+static void *module_alloc_update_bounds_rx(unsigned long size)
76800+{
76801+ void *ret = module_alloc_exec(size);
76802+
76803+ if (ret) {
76804+ mutex_lock(&module_mutex);
76805+ /* Update module bounds. */
76806+ if ((unsigned long)ret < module_addr_min_rx)
76807+ module_addr_min_rx = (unsigned long)ret;
76808+ if ((unsigned long)ret + size > module_addr_max_rx)
76809+ module_addr_max_rx = (unsigned long)ret + size;
76810 mutex_unlock(&module_mutex);
76811 }
76812 return ret;
76813@@ -2690,8 +2728,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
76814 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76815 {
76816 const char *modmagic = get_modinfo(info, "vermagic");
76817+ const char *license = get_modinfo(info, "license");
76818 int err;
76819
76820+#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
76821+ if (!license || !license_is_gpl_compatible(license))
76822+ return -ENOEXEC;
76823+#endif
76824+
76825 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
76826 modmagic = NULL;
76827
76828@@ -2717,7 +2761,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
76829 }
76830
76831 /* Set up license info based on the info section */
76832- set_license(mod, get_modinfo(info, "license"));
76833+ set_license(mod, license);
76834
76835 return 0;
76836 }
76837@@ -2811,7 +2855,7 @@ static int move_module(struct module *mod, struct load_info *info)
76838 void *ptr;
76839
76840 /* Do the allocs. */
76841- ptr = module_alloc_update_bounds(mod->core_size);
76842+ ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
76843 /*
76844 * The pointer to this block is stored in the module structure
76845 * which is inside the block. Just mark it as not being a
76846@@ -2821,11 +2865,11 @@ static int move_module(struct module *mod, struct load_info *info)
76847 if (!ptr)
76848 return -ENOMEM;
76849
76850- memset(ptr, 0, mod->core_size);
76851- mod->module_core = ptr;
76852+ memset(ptr, 0, mod->core_size_rw);
76853+ mod->module_core_rw = ptr;
76854
76855- if (mod->init_size) {
76856- ptr = module_alloc_update_bounds(mod->init_size);
76857+ if (mod->init_size_rw) {
76858+ ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
76859 /*
76860 * The pointer to this block is stored in the module structure
76861 * which is inside the block. This block doesn't need to be
76862@@ -2834,13 +2878,45 @@ static int move_module(struct module *mod, struct load_info *info)
76863 */
76864 kmemleak_ignore(ptr);
76865 if (!ptr) {
76866- module_free(mod, mod->module_core);
76867+ module_free(mod, mod->module_core_rw);
76868 return -ENOMEM;
76869 }
76870- memset(ptr, 0, mod->init_size);
76871- mod->module_init = ptr;
76872+ memset(ptr, 0, mod->init_size_rw);
76873+ mod->module_init_rw = ptr;
76874 } else
76875- mod->module_init = NULL;
76876+ mod->module_init_rw = NULL;
76877+
76878+ ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
76879+ kmemleak_not_leak(ptr);
76880+ if (!ptr) {
76881+ if (mod->module_init_rw)
76882+ module_free(mod, mod->module_init_rw);
76883+ module_free(mod, mod->module_core_rw);
76884+ return -ENOMEM;
76885+ }
76886+
76887+ pax_open_kernel();
76888+ memset(ptr, 0, mod->core_size_rx);
76889+ pax_close_kernel();
76890+ mod->module_core_rx = ptr;
76891+
76892+ if (mod->init_size_rx) {
76893+ ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
76894+ kmemleak_ignore(ptr);
76895+ if (!ptr && mod->init_size_rx) {
76896+ module_free_exec(mod, mod->module_core_rx);
76897+ if (mod->module_init_rw)
76898+ module_free(mod, mod->module_init_rw);
76899+ module_free(mod, mod->module_core_rw);
76900+ return -ENOMEM;
76901+ }
76902+
76903+ pax_open_kernel();
76904+ memset(ptr, 0, mod->init_size_rx);
76905+ pax_close_kernel();
76906+ mod->module_init_rx = ptr;
76907+ } else
76908+ mod->module_init_rx = NULL;
76909
76910 /* Transfer each section which specifies SHF_ALLOC */
76911 pr_debug("final section addresses:\n");
76912@@ -2851,16 +2927,45 @@ static int move_module(struct module *mod, struct load_info *info)
76913 if (!(shdr->sh_flags & SHF_ALLOC))
76914 continue;
76915
76916- if (shdr->sh_entsize & INIT_OFFSET_MASK)
76917- dest = mod->module_init
76918- + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76919- else
76920- dest = mod->module_core + shdr->sh_entsize;
76921+ if (shdr->sh_entsize & INIT_OFFSET_MASK) {
76922+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76923+ dest = mod->module_init_rw
76924+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76925+ else
76926+ dest = mod->module_init_rx
76927+ + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
76928+ } else {
76929+ if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
76930+ dest = mod->module_core_rw + shdr->sh_entsize;
76931+ else
76932+ dest = mod->module_core_rx + shdr->sh_entsize;
76933+ }
76934+
76935+ if (shdr->sh_type != SHT_NOBITS) {
76936+
76937+#ifdef CONFIG_PAX_KERNEXEC
76938+#ifdef CONFIG_X86_64
76939+ if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
76940+ set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
76941+#endif
76942+ if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
76943+ pax_open_kernel();
76944+ memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76945+ pax_close_kernel();
76946+ } else
76947+#endif
76948
76949- if (shdr->sh_type != SHT_NOBITS)
76950 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
76951+ }
76952 /* Update sh_addr to point to copy in image. */
76953- shdr->sh_addr = (unsigned long)dest;
76954+
76955+#ifdef CONFIG_PAX_KERNEXEC
76956+ if (shdr->sh_flags & SHF_EXECINSTR)
76957+ shdr->sh_addr = ktva_ktla((unsigned long)dest);
76958+ else
76959+#endif
76960+
76961+ shdr->sh_addr = (unsigned long)dest;
76962 pr_debug("\t0x%lx %s\n",
76963 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
76964 }
76965@@ -2917,12 +3022,12 @@ static void flush_module_icache(const struct module *mod)
76966 * Do it before processing of module parameters, so the module
76967 * can provide parameter accessor functions of its own.
76968 */
76969- if (mod->module_init)
76970- flush_icache_range((unsigned long)mod->module_init,
76971- (unsigned long)mod->module_init
76972- + mod->init_size);
76973- flush_icache_range((unsigned long)mod->module_core,
76974- (unsigned long)mod->module_core + mod->core_size);
76975+ if (mod->module_init_rx)
76976+ flush_icache_range((unsigned long)mod->module_init_rx,
76977+ (unsigned long)mod->module_init_rx
76978+ + mod->init_size_rx);
76979+ flush_icache_range((unsigned long)mod->module_core_rx,
76980+ (unsigned long)mod->module_core_rx + mod->core_size_rx);
76981
76982 set_fs(old_fs);
76983 }
76984@@ -2992,8 +3097,10 @@ out:
76985 static void module_deallocate(struct module *mod, struct load_info *info)
76986 {
76987 percpu_modfree(mod);
76988- module_free(mod, mod->module_init);
76989- module_free(mod, mod->module_core);
76990+ module_free_exec(mod, mod->module_init_rx);
76991+ module_free_exec(mod, mod->module_core_rx);
76992+ module_free(mod, mod->module_init_rw);
76993+ module_free(mod, mod->module_core_rw);
76994 }
76995
76996 int __weak module_finalize(const Elf_Ehdr *hdr,
76997@@ -3006,7 +3113,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
76998 static int post_relocation(struct module *mod, const struct load_info *info)
76999 {
77000 /* Sort exception table now relocations are done. */
77001+ pax_open_kernel();
77002 sort_extable(mod->extable, mod->extable + mod->num_exentries);
77003+ pax_close_kernel();
77004
77005 /* Copy relocated percpu area over. */
77006 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
77007@@ -3060,16 +3169,16 @@ static int do_init_module(struct module *mod)
77008 MODULE_STATE_COMING, mod);
77009
77010 /* Set RO and NX regions for core */
77011- set_section_ro_nx(mod->module_core,
77012- mod->core_text_size,
77013- mod->core_ro_size,
77014- mod->core_size);
77015+ set_section_ro_nx(mod->module_core_rx,
77016+ mod->core_size_rx,
77017+ mod->core_size_rx,
77018+ mod->core_size_rx);
77019
77020 /* Set RO and NX regions for init */
77021- set_section_ro_nx(mod->module_init,
77022- mod->init_text_size,
77023- mod->init_ro_size,
77024- mod->init_size);
77025+ set_section_ro_nx(mod->module_init_rx,
77026+ mod->init_size_rx,
77027+ mod->init_size_rx,
77028+ mod->init_size_rx);
77029
77030 do_mod_ctors(mod);
77031 /* Start the module */
77032@@ -3131,11 +3240,12 @@ static int do_init_module(struct module *mod)
77033 mod->strtab = mod->core_strtab;
77034 #endif
77035 unset_module_init_ro_nx(mod);
77036- module_free(mod, mod->module_init);
77037- mod->module_init = NULL;
77038- mod->init_size = 0;
77039- mod->init_ro_size = 0;
77040- mod->init_text_size = 0;
77041+ module_free(mod, mod->module_init_rw);
77042+ module_free_exec(mod, mod->module_init_rx);
77043+ mod->module_init_rw = NULL;
77044+ mod->module_init_rx = NULL;
77045+ mod->init_size_rw = 0;
77046+ mod->init_size_rx = 0;
77047 mutex_unlock(&module_mutex);
77048 wake_up_all(&module_wq);
77049
77050@@ -3262,9 +3372,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
77051 if (err)
77052 goto free_unload;
77053
77054+ /* Now copy in args */
77055+ mod->args = strndup_user(uargs, ~0UL >> 1);
77056+ if (IS_ERR(mod->args)) {
77057+ err = PTR_ERR(mod->args);
77058+ goto free_unload;
77059+ }
77060+
77061 /* Set up MODINFO_ATTR fields */
77062 setup_modinfo(mod, info);
77063
77064+#ifdef CONFIG_GRKERNSEC_MODHARDEN
77065+ {
77066+ char *p, *p2;
77067+
77068+ if (strstr(mod->args, "grsec_modharden_netdev")) {
77069+ 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);
77070+ err = -EPERM;
77071+ goto free_modinfo;
77072+ } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
77073+ p += sizeof("grsec_modharden_normal") - 1;
77074+ p2 = strstr(p, "_");
77075+ if (p2) {
77076+ *p2 = '\0';
77077+ printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
77078+ *p2 = '_';
77079+ }
77080+ err = -EPERM;
77081+ goto free_modinfo;
77082+ }
77083+ }
77084+#endif
77085+
77086 /* Fix up syms, so that st_value is a pointer to location. */
77087 err = simplify_symbols(mod, info);
77088 if (err < 0)
77089@@ -3280,13 +3419,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
77090
77091 flush_module_icache(mod);
77092
77093- /* Now copy in args */
77094- mod->args = strndup_user(uargs, ~0UL >> 1);
77095- if (IS_ERR(mod->args)) {
77096- err = PTR_ERR(mod->args);
77097- goto free_arch_cleanup;
77098- }
77099-
77100 dynamic_debug_setup(info->debug, info->num_debug);
77101
77102 /* Finally it's fully formed, ready to start executing. */
77103@@ -3321,11 +3453,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
77104 ddebug_cleanup:
77105 dynamic_debug_remove(info->debug);
77106 synchronize_sched();
77107- kfree(mod->args);
77108- free_arch_cleanup:
77109 module_arch_cleanup(mod);
77110 free_modinfo:
77111 free_modinfo(mod);
77112+ kfree(mod->args);
77113 free_unload:
77114 module_unload_free(mod);
77115 unlink_mod:
77116@@ -3408,10 +3539,16 @@ static const char *get_ksymbol(struct module *mod,
77117 unsigned long nextval;
77118
77119 /* At worse, next value is at end of module */
77120- if (within_module_init(addr, mod))
77121- nextval = (unsigned long)mod->module_init+mod->init_text_size;
77122+ if (within_module_init_rx(addr, mod))
77123+ nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
77124+ else if (within_module_init_rw(addr, mod))
77125+ nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
77126+ else if (within_module_core_rx(addr, mod))
77127+ nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
77128+ else if (within_module_core_rw(addr, mod))
77129+ nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
77130 else
77131- nextval = (unsigned long)mod->module_core+mod->core_text_size;
77132+ return NULL;
77133
77134 /* Scan for closest preceding symbol, and next symbol. (ELF
77135 starts real symbols at 1). */
77136@@ -3664,7 +3801,7 @@ static int m_show(struct seq_file *m, void *p)
77137 return 0;
77138
77139 seq_printf(m, "%s %u",
77140- mod->name, mod->init_size + mod->core_size);
77141+ mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
77142 print_unload_info(m, mod);
77143
77144 /* Informative for users. */
77145@@ -3673,7 +3810,7 @@ static int m_show(struct seq_file *m, void *p)
77146 mod->state == MODULE_STATE_COMING ? "Loading":
77147 "Live");
77148 /* Used by oprofile and other similar tools. */
77149- seq_printf(m, " 0x%pK", mod->module_core);
77150+ seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
77151
77152 /* Taints info */
77153 if (mod->taints)
77154@@ -3709,7 +3846,17 @@ static const struct file_operations proc_modules_operations = {
77155
77156 static int __init proc_modules_init(void)
77157 {
77158+#ifndef CONFIG_GRKERNSEC_HIDESYM
77159+#ifdef CONFIG_GRKERNSEC_PROC_USER
77160+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77161+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
77162+ proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
77163+#else
77164 proc_create("modules", 0, NULL, &proc_modules_operations);
77165+#endif
77166+#else
77167+ proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
77168+#endif
77169 return 0;
77170 }
77171 module_init(proc_modules_init);
77172@@ -3770,14 +3917,14 @@ struct module *__module_address(unsigned long addr)
77173 {
77174 struct module *mod;
77175
77176- if (addr < module_addr_min || addr > module_addr_max)
77177+ if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
77178+ (addr < module_addr_min_rw || addr > module_addr_max_rw))
77179 return NULL;
77180
77181 list_for_each_entry_rcu(mod, &modules, list) {
77182 if (mod->state == MODULE_STATE_UNFORMED)
77183 continue;
77184- if (within_module_core(addr, mod)
77185- || within_module_init(addr, mod))
77186+ if (within_module_init(addr, mod) || within_module_core(addr, mod))
77187 return mod;
77188 }
77189 return NULL;
77190@@ -3812,11 +3959,20 @@ bool is_module_text_address(unsigned long addr)
77191 */
77192 struct module *__module_text_address(unsigned long addr)
77193 {
77194- struct module *mod = __module_address(addr);
77195+ struct module *mod;
77196+
77197+#ifdef CONFIG_X86_32
77198+ addr = ktla_ktva(addr);
77199+#endif
77200+
77201+ if (addr < module_addr_min_rx || addr > module_addr_max_rx)
77202+ return NULL;
77203+
77204+ mod = __module_address(addr);
77205+
77206 if (mod) {
77207 /* Make sure it's within the text section. */
77208- if (!within(addr, mod->module_init, mod->init_text_size)
77209- && !within(addr, mod->module_core, mod->core_text_size))
77210+ if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
77211 mod = NULL;
77212 }
77213 return mod;
77214diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
77215index 7e3443f..b2a1e6b 100644
77216--- a/kernel/mutex-debug.c
77217+++ b/kernel/mutex-debug.c
77218@@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
77219 }
77220
77221 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77222- struct thread_info *ti)
77223+ struct task_struct *task)
77224 {
77225 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
77226
77227 /* Mark the current thread as blocked on the lock: */
77228- ti->task->blocked_on = waiter;
77229+ task->blocked_on = waiter;
77230 }
77231
77232 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77233- struct thread_info *ti)
77234+ struct task_struct *task)
77235 {
77236 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
77237- DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
77238- DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
77239- ti->task->blocked_on = NULL;
77240+ DEBUG_LOCKS_WARN_ON(waiter->task != task);
77241+ DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
77242+ task->blocked_on = NULL;
77243
77244 list_del_init(&waiter->list);
77245 waiter->task = NULL;
77246diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
77247index 0799fd3..d06ae3b 100644
77248--- a/kernel/mutex-debug.h
77249+++ b/kernel/mutex-debug.h
77250@@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
77251 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
77252 extern void debug_mutex_add_waiter(struct mutex *lock,
77253 struct mutex_waiter *waiter,
77254- struct thread_info *ti);
77255+ struct task_struct *task);
77256 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
77257- struct thread_info *ti);
77258+ struct task_struct *task);
77259 extern void debug_mutex_unlock(struct mutex *lock);
77260 extern void debug_mutex_init(struct mutex *lock, const char *name,
77261 struct lock_class_key *key);
77262diff --git a/kernel/mutex.c b/kernel/mutex.c
77263index 52f2301..73f7528 100644
77264--- a/kernel/mutex.c
77265+++ b/kernel/mutex.c
77266@@ -199,7 +199,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77267 spin_lock_mutex(&lock->wait_lock, flags);
77268
77269 debug_mutex_lock_common(lock, &waiter);
77270- debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
77271+ debug_mutex_add_waiter(lock, &waiter, task);
77272
77273 /* add waiting tasks to the end of the waitqueue (FIFO): */
77274 list_add_tail(&waiter.list, &lock->wait_list);
77275@@ -228,8 +228,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77276 * TASK_UNINTERRUPTIBLE case.)
77277 */
77278 if (unlikely(signal_pending_state(state, task))) {
77279- mutex_remove_waiter(lock, &waiter,
77280- task_thread_info(task));
77281+ mutex_remove_waiter(lock, &waiter, task);
77282 mutex_release(&lock->dep_map, 1, ip);
77283 spin_unlock_mutex(&lock->wait_lock, flags);
77284
77285@@ -248,7 +247,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
77286 done:
77287 lock_acquired(&lock->dep_map, ip);
77288 /* got the lock - rejoice! */
77289- mutex_remove_waiter(lock, &waiter, current_thread_info());
77290+ mutex_remove_waiter(lock, &waiter, task);
77291 mutex_set_owner(lock);
77292
77293 /* set it to 0 if there are no waiters left: */
77294diff --git a/kernel/notifier.c b/kernel/notifier.c
77295index 2d5cc4c..d9ea600 100644
77296--- a/kernel/notifier.c
77297+++ b/kernel/notifier.c
77298@@ -5,6 +5,7 @@
77299 #include <linux/rcupdate.h>
77300 #include <linux/vmalloc.h>
77301 #include <linux/reboot.h>
77302+#include <linux/mm.h>
77303
77304 /*
77305 * Notifier list for kernel code which wants to be called
77306@@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
77307 while ((*nl) != NULL) {
77308 if (n->priority > (*nl)->priority)
77309 break;
77310- nl = &((*nl)->next);
77311+ nl = (struct notifier_block **)&((*nl)->next);
77312 }
77313- n->next = *nl;
77314+ pax_open_kernel();
77315+ *(const void **)&n->next = *nl;
77316 rcu_assign_pointer(*nl, n);
77317+ pax_close_kernel();
77318 return 0;
77319 }
77320
77321@@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
77322 return 0;
77323 if (n->priority > (*nl)->priority)
77324 break;
77325- nl = &((*nl)->next);
77326+ nl = (struct notifier_block **)&((*nl)->next);
77327 }
77328- n->next = *nl;
77329+ pax_open_kernel();
77330+ *(const void **)&n->next = *nl;
77331 rcu_assign_pointer(*nl, n);
77332+ pax_close_kernel();
77333 return 0;
77334 }
77335
77336@@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
77337 {
77338 while ((*nl) != NULL) {
77339 if ((*nl) == n) {
77340+ pax_open_kernel();
77341 rcu_assign_pointer(*nl, n->next);
77342+ pax_close_kernel();
77343 return 0;
77344 }
77345- nl = &((*nl)->next);
77346+ nl = (struct notifier_block **)&((*nl)->next);
77347 }
77348 return -ENOENT;
77349 }
77350diff --git a/kernel/panic.c b/kernel/panic.c
77351index 7c57cc9..28f1b3f 100644
77352--- a/kernel/panic.c
77353+++ b/kernel/panic.c
77354@@ -403,7 +403,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
77355 const char *board;
77356
77357 printk(KERN_WARNING "------------[ cut here ]------------\n");
77358- printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
77359+ printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
77360 board = dmi_get_system_info(DMI_PRODUCT_NAME);
77361 if (board)
77362 printk(KERN_WARNING "Hardware name: %s\n", board);
77363@@ -459,7 +459,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
77364 */
77365 void __stack_chk_fail(void)
77366 {
77367- panic("stack-protector: Kernel stack is corrupted in: %p\n",
77368+ dump_stack();
77369+ panic("stack-protector: Kernel stack is corrupted in: %pA\n",
77370 __builtin_return_address(0));
77371 }
77372 EXPORT_SYMBOL(__stack_chk_fail);
77373diff --git a/kernel/pid.c b/kernel/pid.c
77374index 047dc62..418d74b 100644
77375--- a/kernel/pid.c
77376+++ b/kernel/pid.c
77377@@ -33,6 +33,7 @@
77378 #include <linux/rculist.h>
77379 #include <linux/bootmem.h>
77380 #include <linux/hash.h>
77381+#include <linux/security.h>
77382 #include <linux/pid_namespace.h>
77383 #include <linux/init_task.h>
77384 #include <linux/syscalls.h>
77385@@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
77386
77387 int pid_max = PID_MAX_DEFAULT;
77388
77389-#define RESERVED_PIDS 300
77390+#define RESERVED_PIDS 500
77391
77392 int pid_max_min = RESERVED_PIDS + 1;
77393 int pid_max_max = PID_MAX_LIMIT;
77394@@ -440,10 +441,18 @@ EXPORT_SYMBOL(pid_task);
77395 */
77396 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
77397 {
77398+ struct task_struct *task;
77399+
77400 rcu_lockdep_assert(rcu_read_lock_held(),
77401 "find_task_by_pid_ns() needs rcu_read_lock()"
77402 " protection");
77403- return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77404+
77405+ task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
77406+
77407+ if (gr_pid_is_chrooted(task))
77408+ return NULL;
77409+
77410+ return task;
77411 }
77412
77413 struct task_struct *find_task_by_vpid(pid_t vnr)
77414@@ -451,6 +460,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
77415 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
77416 }
77417
77418+struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
77419+{
77420+ rcu_lockdep_assert(rcu_read_lock_held(),
77421+ "find_task_by_pid_ns() needs rcu_read_lock()"
77422+ " protection");
77423+ return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
77424+}
77425+
77426 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
77427 {
77428 struct pid *pid;
77429diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
77430index bea15bd..789f3d0 100644
77431--- a/kernel/pid_namespace.c
77432+++ b/kernel/pid_namespace.c
77433@@ -249,7 +249,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
77434 void __user *buffer, size_t *lenp, loff_t *ppos)
77435 {
77436 struct pid_namespace *pid_ns = task_active_pid_ns(current);
77437- struct ctl_table tmp = *table;
77438+ ctl_table_no_const tmp = *table;
77439
77440 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
77441 return -EPERM;
77442diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
77443index 8fd709c..542bf4b 100644
77444--- a/kernel/posix-cpu-timers.c
77445+++ b/kernel/posix-cpu-timers.c
77446@@ -1592,14 +1592,14 @@ struct k_clock clock_posix_cpu = {
77447
77448 static __init int init_posix_cpu_timers(void)
77449 {
77450- struct k_clock process = {
77451+ static struct k_clock process = {
77452 .clock_getres = process_cpu_clock_getres,
77453 .clock_get = process_cpu_clock_get,
77454 .timer_create = process_cpu_timer_create,
77455 .nsleep = process_cpu_nsleep,
77456 .nsleep_restart = process_cpu_nsleep_restart,
77457 };
77458- struct k_clock thread = {
77459+ static struct k_clock thread = {
77460 .clock_getres = thread_cpu_clock_getres,
77461 .clock_get = thread_cpu_clock_get,
77462 .timer_create = thread_cpu_timer_create,
77463diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
77464index 6edbb2c..334f085 100644
77465--- a/kernel/posix-timers.c
77466+++ b/kernel/posix-timers.c
77467@@ -43,6 +43,7 @@
77468 #include <linux/idr.h>
77469 #include <linux/posix-clock.h>
77470 #include <linux/posix-timers.h>
77471+#include <linux/grsecurity.h>
77472 #include <linux/syscalls.h>
77473 #include <linux/wait.h>
77474 #include <linux/workqueue.h>
77475@@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
77476 * which we beg off on and pass to do_sys_settimeofday().
77477 */
77478
77479-static struct k_clock posix_clocks[MAX_CLOCKS];
77480+static struct k_clock *posix_clocks[MAX_CLOCKS];
77481
77482 /*
77483 * These ones are defined below.
77484@@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
77485 */
77486 static __init int init_posix_timers(void)
77487 {
77488- struct k_clock clock_realtime = {
77489+ static struct k_clock clock_realtime = {
77490 .clock_getres = hrtimer_get_res,
77491 .clock_get = posix_clock_realtime_get,
77492 .clock_set = posix_clock_realtime_set,
77493@@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
77494 .timer_get = common_timer_get,
77495 .timer_del = common_timer_del,
77496 };
77497- struct k_clock clock_monotonic = {
77498+ static struct k_clock clock_monotonic = {
77499 .clock_getres = hrtimer_get_res,
77500 .clock_get = posix_ktime_get_ts,
77501 .nsleep = common_nsleep,
77502@@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
77503 .timer_get = common_timer_get,
77504 .timer_del = common_timer_del,
77505 };
77506- struct k_clock clock_monotonic_raw = {
77507+ static struct k_clock clock_monotonic_raw = {
77508 .clock_getres = hrtimer_get_res,
77509 .clock_get = posix_get_monotonic_raw,
77510 };
77511- struct k_clock clock_realtime_coarse = {
77512+ static struct k_clock clock_realtime_coarse = {
77513 .clock_getres = posix_get_coarse_res,
77514 .clock_get = posix_get_realtime_coarse,
77515 };
77516- struct k_clock clock_monotonic_coarse = {
77517+ static struct k_clock clock_monotonic_coarse = {
77518 .clock_getres = posix_get_coarse_res,
77519 .clock_get = posix_get_monotonic_coarse,
77520 };
77521- struct k_clock clock_boottime = {
77522+ static struct k_clock clock_boottime = {
77523 .clock_getres = hrtimer_get_res,
77524 .clock_get = posix_get_boottime,
77525 .nsleep = common_nsleep,
77526@@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
77527 return;
77528 }
77529
77530- posix_clocks[clock_id] = *new_clock;
77531+ posix_clocks[clock_id] = new_clock;
77532 }
77533 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
77534
77535@@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
77536 return (id & CLOCKFD_MASK) == CLOCKFD ?
77537 &clock_posix_dynamic : &clock_posix_cpu;
77538
77539- if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
77540+ if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
77541 return NULL;
77542- return &posix_clocks[id];
77543+ return posix_clocks[id];
77544 }
77545
77546 static int common_timer_create(struct k_itimer *new_timer)
77547@@ -964,6 +965,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
77548 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
77549 return -EFAULT;
77550
77551+ /* only the CLOCK_REALTIME clock can be set, all other clocks
77552+ have their clock_set fptr set to a nosettime dummy function
77553+ CLOCK_REALTIME has a NULL clock_set fptr which causes it to
77554+ call common_clock_set, which calls do_sys_settimeofday, which
77555+ we hook
77556+ */
77557+
77558 return kc->clock_set(which_clock, &new_tp);
77559 }
77560
77561diff --git a/kernel/power/process.c b/kernel/power/process.c
77562index 98088e0..aaf95c0 100644
77563--- a/kernel/power/process.c
77564+++ b/kernel/power/process.c
77565@@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
77566 u64 elapsed_csecs64;
77567 unsigned int elapsed_csecs;
77568 bool wakeup = false;
77569+ bool timedout = false;
77570
77571 do_gettimeofday(&start);
77572
77573@@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
77574
77575 while (true) {
77576 todo = 0;
77577+ if (time_after(jiffies, end_time))
77578+ timedout = true;
77579 read_lock(&tasklist_lock);
77580 do_each_thread(g, p) {
77581 if (p == current || !freeze_task(p))
77582 continue;
77583
77584- if (!freezer_should_skip(p))
77585+ if (!freezer_should_skip(p)) {
77586 todo++;
77587+ if (timedout) {
77588+ printk(KERN_ERR "Task refusing to freeze:\n");
77589+ sched_show_task(p);
77590+ }
77591+ }
77592 } while_each_thread(g, p);
77593 read_unlock(&tasklist_lock);
77594
77595@@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
77596 todo += wq_busy;
77597 }
77598
77599- if (!todo || time_after(jiffies, end_time))
77600+ if (!todo || timedout)
77601 break;
77602
77603 if (pm_wakeup_pending()) {
77604diff --git a/kernel/printk.c b/kernel/printk.c
77605index 0e4eba6a..d58ebf0 100644
77606--- a/kernel/printk.c
77607+++ b/kernel/printk.c
77608@@ -395,6 +395,11 @@ static int check_syslog_permissions(int type, bool from_file)
77609 if (from_file && type != SYSLOG_ACTION_OPEN)
77610 return 0;
77611
77612+#ifdef CONFIG_GRKERNSEC_DMESG
77613+ if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
77614+ return -EPERM;
77615+#endif
77616+
77617 if (syslog_action_restricted(type)) {
77618 if (capable(CAP_SYSLOG))
77619 return 0;
77620diff --git a/kernel/profile.c b/kernel/profile.c
77621index dc3384e..0de5b49 100644
77622--- a/kernel/profile.c
77623+++ b/kernel/profile.c
77624@@ -37,7 +37,7 @@ struct profile_hit {
77625 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
77626 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
77627
77628-static atomic_t *prof_buffer;
77629+static atomic_unchecked_t *prof_buffer;
77630 static unsigned long prof_len, prof_shift;
77631
77632 int prof_on __read_mostly;
77633@@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
77634 hits[i].pc = 0;
77635 continue;
77636 }
77637- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77638+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77639 hits[i].hits = hits[i].pc = 0;
77640 }
77641 }
77642@@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77643 * Add the current hit(s) and flush the write-queue out
77644 * to the global buffer:
77645 */
77646- atomic_add(nr_hits, &prof_buffer[pc]);
77647+ atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
77648 for (i = 0; i < NR_PROFILE_HIT; ++i) {
77649- atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
77650+ atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
77651 hits[i].pc = hits[i].hits = 0;
77652 }
77653 out:
77654@@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
77655 {
77656 unsigned long pc;
77657 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
77658- atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77659+ atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
77660 }
77661 #endif /* !CONFIG_SMP */
77662
77663@@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
77664 return -EFAULT;
77665 buf++; p++; count--; read++;
77666 }
77667- pnt = (char *)prof_buffer + p - sizeof(atomic_t);
77668+ pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
77669 if (copy_to_user(buf, (void *)pnt, count))
77670 return -EFAULT;
77671 read += count;
77672@@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
77673 }
77674 #endif
77675 profile_discard_flip_buffers();
77676- memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
77677+ memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
77678 return count;
77679 }
77680
77681diff --git a/kernel/ptrace.c b/kernel/ptrace.c
77682index acbd284..00bb0c9 100644
77683--- a/kernel/ptrace.c
77684+++ b/kernel/ptrace.c
77685@@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
77686 if (seize)
77687 flags |= PT_SEIZED;
77688 rcu_read_lock();
77689- if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77690+ if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
77691 flags |= PT_PTRACE_CAP;
77692 rcu_read_unlock();
77693 task->ptrace = flags;
77694@@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
77695 break;
77696 return -EIO;
77697 }
77698- if (copy_to_user(dst, buf, retval))
77699+ if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
77700 return -EFAULT;
77701 copied += retval;
77702 src += retval;
77703@@ -726,7 +726,7 @@ int ptrace_request(struct task_struct *child, long request,
77704 bool seized = child->ptrace & PT_SEIZED;
77705 int ret = -EIO;
77706 siginfo_t siginfo, *si;
77707- void __user *datavp = (void __user *) data;
77708+ void __user *datavp = (__force void __user *) data;
77709 unsigned long __user *datalp = datavp;
77710 unsigned long flags;
77711
77712@@ -928,14 +928,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
77713 goto out;
77714 }
77715
77716+ if (gr_handle_ptrace(child, request)) {
77717+ ret = -EPERM;
77718+ goto out_put_task_struct;
77719+ }
77720+
77721 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77722 ret = ptrace_attach(child, request, addr, data);
77723 /*
77724 * Some architectures need to do book-keeping after
77725 * a ptrace attach.
77726 */
77727- if (!ret)
77728+ if (!ret) {
77729 arch_ptrace_attach(child);
77730+ gr_audit_ptrace(child);
77731+ }
77732 goto out_put_task_struct;
77733 }
77734
77735@@ -963,7 +970,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
77736 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
77737 if (copied != sizeof(tmp))
77738 return -EIO;
77739- return put_user(tmp, (unsigned long __user *)data);
77740+ return put_user(tmp, (__force unsigned long __user *)data);
77741 }
77742
77743 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
77744@@ -1057,7 +1064,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
77745 }
77746
77747 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77748- compat_long_t addr, compat_long_t data)
77749+ compat_ulong_t addr, compat_ulong_t data)
77750 {
77751 struct task_struct *child;
77752 long ret;
77753@@ -1073,14 +1080,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77754 goto out;
77755 }
77756
77757+ if (gr_handle_ptrace(child, request)) {
77758+ ret = -EPERM;
77759+ goto out_put_task_struct;
77760+ }
77761+
77762 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
77763 ret = ptrace_attach(child, request, addr, data);
77764 /*
77765 * Some architectures need to do book-keeping after
77766 * a ptrace attach.
77767 */
77768- if (!ret)
77769+ if (!ret) {
77770 arch_ptrace_attach(child);
77771+ gr_audit_ptrace(child);
77772+ }
77773 goto out_put_task_struct;
77774 }
77775
77776diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
77777index 48ab703..07561d4 100644
77778--- a/kernel/rcupdate.c
77779+++ b/kernel/rcupdate.c
77780@@ -439,10 +439,10 @@ int rcu_jiffies_till_stall_check(void)
77781 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
77782 */
77783 if (till_stall_check < 3) {
77784- ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
77785+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
77786 till_stall_check = 3;
77787 } else if (till_stall_check > 300) {
77788- ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
77789+ ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
77790 till_stall_check = 300;
77791 }
77792 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
77793diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
77794index a0714a5..2ab5e34 100644
77795--- a/kernel/rcutiny.c
77796+++ b/kernel/rcutiny.c
77797@@ -46,7 +46,7 @@
77798 struct rcu_ctrlblk;
77799 static void invoke_rcu_callbacks(void);
77800 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
77801-static void rcu_process_callbacks(struct softirq_action *unused);
77802+static void rcu_process_callbacks(void);
77803 static void __call_rcu(struct rcu_head *head,
77804 void (*func)(struct rcu_head *rcu),
77805 struct rcu_ctrlblk *rcp);
77806@@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
77807 rcu_is_callbacks_kthread()));
77808 }
77809
77810-static void rcu_process_callbacks(struct softirq_action *unused)
77811+static void rcu_process_callbacks(void)
77812 {
77813 __rcu_process_callbacks(&rcu_sched_ctrlblk);
77814 __rcu_process_callbacks(&rcu_bh_ctrlblk);
77815diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
77816index 8a23300..4255818 100644
77817--- a/kernel/rcutiny_plugin.h
77818+++ b/kernel/rcutiny_plugin.h
77819@@ -945,7 +945,7 @@ static int rcu_kthread(void *arg)
77820 have_rcu_kthread_work = morework;
77821 local_irq_restore(flags);
77822 if (work)
77823- rcu_process_callbacks(NULL);
77824+ rcu_process_callbacks();
77825 schedule_timeout_interruptible(1); /* Leave CPU for others. */
77826 }
77827
77828diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
77829index e1f3a8c..42c94a2 100644
77830--- a/kernel/rcutorture.c
77831+++ b/kernel/rcutorture.c
77832@@ -164,12 +164,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
77833 { 0 };
77834 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
77835 { 0 };
77836-static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77837-static atomic_t n_rcu_torture_alloc;
77838-static atomic_t n_rcu_torture_alloc_fail;
77839-static atomic_t n_rcu_torture_free;
77840-static atomic_t n_rcu_torture_mberror;
77841-static atomic_t n_rcu_torture_error;
77842+static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
77843+static atomic_unchecked_t n_rcu_torture_alloc;
77844+static atomic_unchecked_t n_rcu_torture_alloc_fail;
77845+static atomic_unchecked_t n_rcu_torture_free;
77846+static atomic_unchecked_t n_rcu_torture_mberror;
77847+static atomic_unchecked_t n_rcu_torture_error;
77848 static long n_rcu_torture_barrier_error;
77849 static long n_rcu_torture_boost_ktrerror;
77850 static long n_rcu_torture_boost_rterror;
77851@@ -287,11 +287,11 @@ rcu_torture_alloc(void)
77852
77853 spin_lock_bh(&rcu_torture_lock);
77854 if (list_empty(&rcu_torture_freelist)) {
77855- atomic_inc(&n_rcu_torture_alloc_fail);
77856+ atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
77857 spin_unlock_bh(&rcu_torture_lock);
77858 return NULL;
77859 }
77860- atomic_inc(&n_rcu_torture_alloc);
77861+ atomic_inc_unchecked(&n_rcu_torture_alloc);
77862 p = rcu_torture_freelist.next;
77863 list_del_init(p);
77864 spin_unlock_bh(&rcu_torture_lock);
77865@@ -304,7 +304,7 @@ rcu_torture_alloc(void)
77866 static void
77867 rcu_torture_free(struct rcu_torture *p)
77868 {
77869- atomic_inc(&n_rcu_torture_free);
77870+ atomic_inc_unchecked(&n_rcu_torture_free);
77871 spin_lock_bh(&rcu_torture_lock);
77872 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
77873 spin_unlock_bh(&rcu_torture_lock);
77874@@ -424,7 +424,7 @@ rcu_torture_cb(struct rcu_head *p)
77875 i = rp->rtort_pipe_count;
77876 if (i > RCU_TORTURE_PIPE_LEN)
77877 i = RCU_TORTURE_PIPE_LEN;
77878- atomic_inc(&rcu_torture_wcount[i]);
77879+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77880 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77881 rp->rtort_mbtest = 0;
77882 rcu_torture_free(rp);
77883@@ -472,7 +472,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
77884 i = rp->rtort_pipe_count;
77885 if (i > RCU_TORTURE_PIPE_LEN)
77886 i = RCU_TORTURE_PIPE_LEN;
77887- atomic_inc(&rcu_torture_wcount[i]);
77888+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77889 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
77890 rp->rtort_mbtest = 0;
77891 list_del(&rp->rtort_free);
77892@@ -990,7 +990,7 @@ rcu_torture_writer(void *arg)
77893 i = old_rp->rtort_pipe_count;
77894 if (i > RCU_TORTURE_PIPE_LEN)
77895 i = RCU_TORTURE_PIPE_LEN;
77896- atomic_inc(&rcu_torture_wcount[i]);
77897+ atomic_inc_unchecked(&rcu_torture_wcount[i]);
77898 old_rp->rtort_pipe_count++;
77899 cur_ops->deferred_free(old_rp);
77900 }
77901@@ -1076,7 +1076,7 @@ static void rcu_torture_timer(unsigned long unused)
77902 return;
77903 }
77904 if (p->rtort_mbtest == 0)
77905- atomic_inc(&n_rcu_torture_mberror);
77906+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77907 spin_lock(&rand_lock);
77908 cur_ops->read_delay(&rand);
77909 n_rcu_torture_timers++;
77910@@ -1146,7 +1146,7 @@ rcu_torture_reader(void *arg)
77911 continue;
77912 }
77913 if (p->rtort_mbtest == 0)
77914- atomic_inc(&n_rcu_torture_mberror);
77915+ atomic_inc_unchecked(&n_rcu_torture_mberror);
77916 cur_ops->read_delay(&rand);
77917 preempt_disable();
77918 pipe_count = p->rtort_pipe_count;
77919@@ -1209,11 +1209,11 @@ rcu_torture_printk(char *page)
77920 rcu_torture_current,
77921 rcu_torture_current_version,
77922 list_empty(&rcu_torture_freelist),
77923- atomic_read(&n_rcu_torture_alloc),
77924- atomic_read(&n_rcu_torture_alloc_fail),
77925- atomic_read(&n_rcu_torture_free));
77926+ atomic_read_unchecked(&n_rcu_torture_alloc),
77927+ atomic_read_unchecked(&n_rcu_torture_alloc_fail),
77928+ atomic_read_unchecked(&n_rcu_torture_free));
77929 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
77930- atomic_read(&n_rcu_torture_mberror),
77931+ atomic_read_unchecked(&n_rcu_torture_mberror),
77932 n_rcu_torture_boost_ktrerror,
77933 n_rcu_torture_boost_rterror);
77934 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
77935@@ -1232,14 +1232,14 @@ rcu_torture_printk(char *page)
77936 n_barrier_attempts,
77937 n_rcu_torture_barrier_error);
77938 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
77939- if (atomic_read(&n_rcu_torture_mberror) != 0 ||
77940+ if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
77941 n_rcu_torture_barrier_error != 0 ||
77942 n_rcu_torture_boost_ktrerror != 0 ||
77943 n_rcu_torture_boost_rterror != 0 ||
77944 n_rcu_torture_boost_failure != 0 ||
77945 i > 1) {
77946 cnt += sprintf(&page[cnt], "!!! ");
77947- atomic_inc(&n_rcu_torture_error);
77948+ atomic_inc_unchecked(&n_rcu_torture_error);
77949 WARN_ON_ONCE(1);
77950 }
77951 cnt += sprintf(&page[cnt], "Reader Pipe: ");
77952@@ -1253,7 +1253,7 @@ rcu_torture_printk(char *page)
77953 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
77954 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77955 cnt += sprintf(&page[cnt], " %d",
77956- atomic_read(&rcu_torture_wcount[i]));
77957+ atomic_read_unchecked(&rcu_torture_wcount[i]));
77958 }
77959 cnt += sprintf(&page[cnt], "\n");
77960 if (cur_ops->stats)
77961@@ -1962,7 +1962,7 @@ rcu_torture_cleanup(void)
77962
77963 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
77964
77965- if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77966+ if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
77967 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
77968 else if (n_online_successes != n_online_attempts ||
77969 n_offline_successes != n_offline_attempts)
77970@@ -2031,18 +2031,18 @@ rcu_torture_init(void)
77971
77972 rcu_torture_current = NULL;
77973 rcu_torture_current_version = 0;
77974- atomic_set(&n_rcu_torture_alloc, 0);
77975- atomic_set(&n_rcu_torture_alloc_fail, 0);
77976- atomic_set(&n_rcu_torture_free, 0);
77977- atomic_set(&n_rcu_torture_mberror, 0);
77978- atomic_set(&n_rcu_torture_error, 0);
77979+ atomic_set_unchecked(&n_rcu_torture_alloc, 0);
77980+ atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
77981+ atomic_set_unchecked(&n_rcu_torture_free, 0);
77982+ atomic_set_unchecked(&n_rcu_torture_mberror, 0);
77983+ atomic_set_unchecked(&n_rcu_torture_error, 0);
77984 n_rcu_torture_barrier_error = 0;
77985 n_rcu_torture_boost_ktrerror = 0;
77986 n_rcu_torture_boost_rterror = 0;
77987 n_rcu_torture_boost_failure = 0;
77988 n_rcu_torture_boosts = 0;
77989 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
77990- atomic_set(&rcu_torture_wcount[i], 0);
77991+ atomic_set_unchecked(&rcu_torture_wcount[i], 0);
77992 for_each_possible_cpu(cpu) {
77993 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
77994 per_cpu(rcu_torture_count, cpu)[i] = 0;
77995diff --git a/kernel/rcutree.c b/kernel/rcutree.c
77996index 5b8ad82..59e1f64 100644
77997--- a/kernel/rcutree.c
77998+++ b/kernel/rcutree.c
77999@@ -353,9 +353,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
78000 rcu_prepare_for_idle(smp_processor_id());
78001 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78002 smp_mb__before_atomic_inc(); /* See above. */
78003- atomic_inc(&rdtp->dynticks);
78004+ atomic_inc_unchecked(&rdtp->dynticks);
78005 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
78006- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78007+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78008
78009 /*
78010 * It is illegal to enter an extended quiescent state while
78011@@ -491,10 +491,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
78012 int user)
78013 {
78014 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
78015- atomic_inc(&rdtp->dynticks);
78016+ atomic_inc_unchecked(&rdtp->dynticks);
78017 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78018 smp_mb__after_atomic_inc(); /* See above. */
78019- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78020+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78021 rcu_cleanup_after_idle(smp_processor_id());
78022 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
78023 if (!user && !is_idle_task(current)) {
78024@@ -633,14 +633,14 @@ void rcu_nmi_enter(void)
78025 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
78026
78027 if (rdtp->dynticks_nmi_nesting == 0 &&
78028- (atomic_read(&rdtp->dynticks) & 0x1))
78029+ (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
78030 return;
78031 rdtp->dynticks_nmi_nesting++;
78032 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
78033- atomic_inc(&rdtp->dynticks);
78034+ atomic_inc_unchecked(&rdtp->dynticks);
78035 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
78036 smp_mb__after_atomic_inc(); /* See above. */
78037- WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
78038+ WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
78039 }
78040
78041 /**
78042@@ -659,9 +659,9 @@ void rcu_nmi_exit(void)
78043 return;
78044 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
78045 smp_mb__before_atomic_inc(); /* See above. */
78046- atomic_inc(&rdtp->dynticks);
78047+ atomic_inc_unchecked(&rdtp->dynticks);
78048 smp_mb__after_atomic_inc(); /* Force delay to next write. */
78049- WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
78050+ WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
78051 }
78052
78053 /**
78054@@ -675,7 +675,7 @@ int rcu_is_cpu_idle(void)
78055 int ret;
78056
78057 preempt_disable();
78058- ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78059+ ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
78060 preempt_enable();
78061 return ret;
78062 }
78063@@ -743,7 +743,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
78064 */
78065 static int dyntick_save_progress_counter(struct rcu_data *rdp)
78066 {
78067- rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
78068+ rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78069 return (rdp->dynticks_snap & 0x1) == 0;
78070 }
78071
78072@@ -758,7 +758,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
78073 unsigned int curr;
78074 unsigned int snap;
78075
78076- curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
78077+ curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
78078 snap = (unsigned int)rdp->dynticks_snap;
78079
78080 /*
78081@@ -1698,7 +1698,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
78082 rsp->qlen += rdp->qlen;
78083 rdp->n_cbs_orphaned += rdp->qlen;
78084 rdp->qlen_lazy = 0;
78085- ACCESS_ONCE(rdp->qlen) = 0;
78086+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78087 }
78088
78089 /*
78090@@ -1944,7 +1944,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
78091 }
78092 smp_mb(); /* List handling before counting for rcu_barrier(). */
78093 rdp->qlen_lazy -= count_lazy;
78094- ACCESS_ONCE(rdp->qlen) -= count;
78095+ ACCESS_ONCE_RW(rdp->qlen) -= count;
78096 rdp->n_cbs_invoked += count;
78097
78098 /* Reinstate batch limit if we have worked down the excess. */
78099@@ -2137,7 +2137,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
78100 /*
78101 * Do RCU core processing for the current CPU.
78102 */
78103-static void rcu_process_callbacks(struct softirq_action *unused)
78104+static void rcu_process_callbacks(void)
78105 {
78106 struct rcu_state *rsp;
78107
78108@@ -2260,7 +2260,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
78109 local_irq_restore(flags);
78110 return;
78111 }
78112- ACCESS_ONCE(rdp->qlen)++;
78113+ ACCESS_ONCE_RW(rdp->qlen)++;
78114 if (lazy)
78115 rdp->qlen_lazy++;
78116 else
78117@@ -2469,11 +2469,11 @@ void synchronize_sched_expedited(void)
78118 * counter wrap on a 32-bit system. Quite a few more CPUs would of
78119 * course be required on a 64-bit system.
78120 */
78121- if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
78122+ if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
78123 (ulong)atomic_long_read(&rsp->expedited_done) +
78124 ULONG_MAX / 8)) {
78125 synchronize_sched();
78126- atomic_long_inc(&rsp->expedited_wrap);
78127+ atomic_long_inc_unchecked(&rsp->expedited_wrap);
78128 return;
78129 }
78130
78131@@ -2481,7 +2481,7 @@ void synchronize_sched_expedited(void)
78132 * Take a ticket. Note that atomic_inc_return() implies a
78133 * full memory barrier.
78134 */
78135- snap = atomic_long_inc_return(&rsp->expedited_start);
78136+ snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
78137 firstsnap = snap;
78138 get_online_cpus();
78139 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
78140@@ -2494,14 +2494,14 @@ void synchronize_sched_expedited(void)
78141 synchronize_sched_expedited_cpu_stop,
78142 NULL) == -EAGAIN) {
78143 put_online_cpus();
78144- atomic_long_inc(&rsp->expedited_tryfail);
78145+ atomic_long_inc_unchecked(&rsp->expedited_tryfail);
78146
78147 /* Check to see if someone else did our work for us. */
78148 s = atomic_long_read(&rsp->expedited_done);
78149 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78150 /* ensure test happens before caller kfree */
78151 smp_mb__before_atomic_inc(); /* ^^^ */
78152- atomic_long_inc(&rsp->expedited_workdone1);
78153+ atomic_long_inc_unchecked(&rsp->expedited_workdone1);
78154 return;
78155 }
78156
78157@@ -2510,7 +2510,7 @@ void synchronize_sched_expedited(void)
78158 udelay(trycount * num_online_cpus());
78159 } else {
78160 wait_rcu_gp(call_rcu_sched);
78161- atomic_long_inc(&rsp->expedited_normal);
78162+ atomic_long_inc_unchecked(&rsp->expedited_normal);
78163 return;
78164 }
78165
78166@@ -2519,7 +2519,7 @@ void synchronize_sched_expedited(void)
78167 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
78168 /* ensure test happens before caller kfree */
78169 smp_mb__before_atomic_inc(); /* ^^^ */
78170- atomic_long_inc(&rsp->expedited_workdone2);
78171+ atomic_long_inc_unchecked(&rsp->expedited_workdone2);
78172 return;
78173 }
78174
78175@@ -2531,10 +2531,10 @@ void synchronize_sched_expedited(void)
78176 * period works for us.
78177 */
78178 get_online_cpus();
78179- snap = atomic_long_read(&rsp->expedited_start);
78180+ snap = atomic_long_read_unchecked(&rsp->expedited_start);
78181 smp_mb(); /* ensure read is before try_stop_cpus(). */
78182 }
78183- atomic_long_inc(&rsp->expedited_stoppedcpus);
78184+ atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
78185
78186 /*
78187 * Everyone up to our most recent fetch is covered by our grace
78188@@ -2543,16 +2543,16 @@ void synchronize_sched_expedited(void)
78189 * than we did already did their update.
78190 */
78191 do {
78192- atomic_long_inc(&rsp->expedited_done_tries);
78193+ atomic_long_inc_unchecked(&rsp->expedited_done_tries);
78194 s = atomic_long_read(&rsp->expedited_done);
78195 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
78196 /* ensure test happens before caller kfree */
78197 smp_mb__before_atomic_inc(); /* ^^^ */
78198- atomic_long_inc(&rsp->expedited_done_lost);
78199+ atomic_long_inc_unchecked(&rsp->expedited_done_lost);
78200 break;
78201 }
78202 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
78203- atomic_long_inc(&rsp->expedited_done_exit);
78204+ atomic_long_inc_unchecked(&rsp->expedited_done_exit);
78205
78206 put_online_cpus();
78207 }
78208@@ -2726,7 +2726,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78209 * ACCESS_ONCE() to prevent the compiler from speculating
78210 * the increment to precede the early-exit check.
78211 */
78212- ACCESS_ONCE(rsp->n_barrier_done)++;
78213+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78214 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
78215 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
78216 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
78217@@ -2776,7 +2776,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
78218
78219 /* Increment ->n_barrier_done to prevent duplicate work. */
78220 smp_mb(); /* Keep increment after above mechanism. */
78221- ACCESS_ONCE(rsp->n_barrier_done)++;
78222+ ACCESS_ONCE_RW(rsp->n_barrier_done)++;
78223 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
78224 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
78225 smp_mb(); /* Keep increment before caller's subsequent code. */
78226@@ -2821,10 +2821,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
78227 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
78228 init_callback_list(rdp);
78229 rdp->qlen_lazy = 0;
78230- ACCESS_ONCE(rdp->qlen) = 0;
78231+ ACCESS_ONCE_RW(rdp->qlen) = 0;
78232 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
78233 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
78234- WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
78235+ WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
78236 rdp->cpu = cpu;
78237 rdp->rsp = rsp;
78238 rcu_boot_init_nocb_percpu_data(rdp);
78239@@ -2857,8 +2857,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
78240 rdp->blimit = blimit;
78241 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
78242 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
78243- atomic_set(&rdp->dynticks->dynticks,
78244- (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
78245+ atomic_set_unchecked(&rdp->dynticks->dynticks,
78246+ (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
78247 rcu_prepare_for_idle_init(cpu);
78248 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
78249
78250@@ -2964,7 +2964,7 @@ static int __init rcu_spawn_gp_kthread(void)
78251 struct task_struct *t;
78252
78253 for_each_rcu_flavor(rsp) {
78254- t = kthread_run(rcu_gp_kthread, rsp, rsp->name);
78255+ t = kthread_run(rcu_gp_kthread, rsp, "%s", rsp->name);
78256 BUG_ON(IS_ERR(t));
78257 rnp = rcu_get_root(rsp);
78258 raw_spin_lock_irqsave(&rnp->lock, flags);
78259diff --git a/kernel/rcutree.h b/kernel/rcutree.h
78260index c896b50..c357252 100644
78261--- a/kernel/rcutree.h
78262+++ b/kernel/rcutree.h
78263@@ -86,7 +86,7 @@ struct rcu_dynticks {
78264 long long dynticks_nesting; /* Track irq/process nesting level. */
78265 /* Process level is worth LLONG_MAX/2. */
78266 int dynticks_nmi_nesting; /* Track NMI nesting level. */
78267- atomic_t dynticks; /* Even value for idle, else odd. */
78268+ atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
78269 #ifdef CONFIG_RCU_FAST_NO_HZ
78270 int dyntick_drain; /* Prepare-for-idle state variable. */
78271 unsigned long dyntick_holdoff;
78272@@ -416,17 +416,17 @@ struct rcu_state {
78273 /* _rcu_barrier(). */
78274 /* End of fields guarded by barrier_mutex. */
78275
78276- atomic_long_t expedited_start; /* Starting ticket. */
78277- atomic_long_t expedited_done; /* Done ticket. */
78278- atomic_long_t expedited_wrap; /* # near-wrap incidents. */
78279- atomic_long_t expedited_tryfail; /* # acquisition failures. */
78280- atomic_long_t expedited_workdone1; /* # done by others #1. */
78281- atomic_long_t expedited_workdone2; /* # done by others #2. */
78282- atomic_long_t expedited_normal; /* # fallbacks to normal. */
78283- atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
78284- atomic_long_t expedited_done_tries; /* # tries to update _done. */
78285- atomic_long_t expedited_done_lost; /* # times beaten to _done. */
78286- atomic_long_t expedited_done_exit; /* # times exited _done loop. */
78287+ atomic_long_unchecked_t expedited_start; /* Starting ticket. */
78288+ atomic_long_t expedited_done; /* Done ticket. */
78289+ atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
78290+ atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
78291+ atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
78292+ atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
78293+ atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
78294+ atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
78295+ atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
78296+ atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
78297+ atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
78298
78299 unsigned long jiffies_force_qs; /* Time at which to invoke */
78300 /* force_quiescent_state(). */
78301diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
78302index c1cc7e1..f62e436 100644
78303--- a/kernel/rcutree_plugin.h
78304+++ b/kernel/rcutree_plugin.h
78305@@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
78306
78307 /* Clean up and exit. */
78308 smp_mb(); /* ensure expedited GP seen before counter increment. */
78309- ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
78310+ ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
78311 unlock_mb_ret:
78312 mutex_unlock(&sync_rcu_preempt_exp_mutex);
78313 mb_ret:
78314@@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
78315 free_cpumask_var(cm);
78316 }
78317
78318-static struct smp_hotplug_thread rcu_cpu_thread_spec = {
78319+static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
78320 .store = &rcu_cpu_kthread_task,
78321 .thread_should_run = rcu_cpu_kthread_should_run,
78322 .thread_fn = rcu_cpu_kthread,
78323@@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
78324 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
78325 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
78326 cpu, ticks_value, ticks_title,
78327- atomic_read(&rdtp->dynticks) & 0xfff,
78328+ atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
78329 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
78330 fast_no_hz);
78331 }
78332@@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
78333
78334 /* Enqueue the callback on the nocb list and update counts. */
78335 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
78336- ACCESS_ONCE(*old_rhpp) = rhp;
78337+ ACCESS_ONCE_RW(*old_rhpp) = rhp;
78338 atomic_long_add(rhcount, &rdp->nocb_q_count);
78339 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
78340
78341@@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
78342 * Extract queued callbacks, update counts, and wait
78343 * for a grace period to elapse.
78344 */
78345- ACCESS_ONCE(rdp->nocb_head) = NULL;
78346+ ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
78347 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
78348 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
78349 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
78350- ACCESS_ONCE(rdp->nocb_p_count) += c;
78351- ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
78352+ ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
78353+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
78354 wait_rcu_gp(rdp->rsp->call_remote);
78355
78356 /* Each pass through the following loop invokes a callback. */
78357@@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
78358 list = next;
78359 }
78360 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
78361- ACCESS_ONCE(rdp->nocb_p_count) -= c;
78362- ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
78363+ ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
78364+ ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
78365 rdp->n_nocbs_invoked += c;
78366 }
78367 return 0;
78368@@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
78369 rdp = per_cpu_ptr(rsp->rda, cpu);
78370 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
78371 BUG_ON(IS_ERR(t));
78372- ACCESS_ONCE(rdp->nocb_kthread) = t;
78373+ ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
78374 }
78375 }
78376
78377diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
78378index 93f8e8f..cf812ae 100644
78379--- a/kernel/rcutree_trace.c
78380+++ b/kernel/rcutree_trace.c
78381@@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
78382 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
78383 rdp->passed_quiesce, rdp->qs_pending);
78384 seq_printf(m, " dt=%d/%llx/%d df=%lu",
78385- atomic_read(&rdp->dynticks->dynticks),
78386+ atomic_read_unchecked(&rdp->dynticks->dynticks),
78387 rdp->dynticks->dynticks_nesting,
78388 rdp->dynticks->dynticks_nmi_nesting,
78389 rdp->dynticks_fqs);
78390@@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
78391 struct rcu_state *rsp = (struct rcu_state *)m->private;
78392
78393 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",
78394- atomic_long_read(&rsp->expedited_start),
78395+ atomic_long_read_unchecked(&rsp->expedited_start),
78396 atomic_long_read(&rsp->expedited_done),
78397- atomic_long_read(&rsp->expedited_wrap),
78398- atomic_long_read(&rsp->expedited_tryfail),
78399- atomic_long_read(&rsp->expedited_workdone1),
78400- atomic_long_read(&rsp->expedited_workdone2),
78401- atomic_long_read(&rsp->expedited_normal),
78402- atomic_long_read(&rsp->expedited_stoppedcpus),
78403- atomic_long_read(&rsp->expedited_done_tries),
78404- atomic_long_read(&rsp->expedited_done_lost),
78405- atomic_long_read(&rsp->expedited_done_exit));
78406+ atomic_long_read_unchecked(&rsp->expedited_wrap),
78407+ atomic_long_read_unchecked(&rsp->expedited_tryfail),
78408+ atomic_long_read_unchecked(&rsp->expedited_workdone1),
78409+ atomic_long_read_unchecked(&rsp->expedited_workdone2),
78410+ atomic_long_read_unchecked(&rsp->expedited_normal),
78411+ atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
78412+ atomic_long_read_unchecked(&rsp->expedited_done_tries),
78413+ atomic_long_read_unchecked(&rsp->expedited_done_lost),
78414+ atomic_long_read_unchecked(&rsp->expedited_done_exit));
78415 return 0;
78416 }
78417
78418diff --git a/kernel/resource.c b/kernel/resource.c
78419index 73f35d4..4684fc4 100644
78420--- a/kernel/resource.c
78421+++ b/kernel/resource.c
78422@@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
78423
78424 static int __init ioresources_init(void)
78425 {
78426+#ifdef CONFIG_GRKERNSEC_PROC_ADD
78427+#ifdef CONFIG_GRKERNSEC_PROC_USER
78428+ proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
78429+ proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
78430+#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78431+ proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
78432+ proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
78433+#endif
78434+#else
78435 proc_create("ioports", 0, NULL, &proc_ioports_operations);
78436 proc_create("iomem", 0, NULL, &proc_iomem_operations);
78437+#endif
78438 return 0;
78439 }
78440 __initcall(ioresources_init);
78441diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
78442index 7890b10..8b68605f 100644
78443--- a/kernel/rtmutex-tester.c
78444+++ b/kernel/rtmutex-tester.c
78445@@ -21,7 +21,7 @@
78446 #define MAX_RT_TEST_MUTEXES 8
78447
78448 static spinlock_t rttest_lock;
78449-static atomic_t rttest_event;
78450+static atomic_unchecked_t rttest_event;
78451
78452 struct test_thread_data {
78453 int opcode;
78454@@ -62,7 +62,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78455
78456 case RTTEST_LOCKCONT:
78457 td->mutexes[td->opdata] = 1;
78458- td->event = atomic_add_return(1, &rttest_event);
78459+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78460 return 0;
78461
78462 case RTTEST_RESET:
78463@@ -75,7 +75,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78464 return 0;
78465
78466 case RTTEST_RESETEVENT:
78467- atomic_set(&rttest_event, 0);
78468+ atomic_set_unchecked(&rttest_event, 0);
78469 return 0;
78470
78471 default:
78472@@ -92,9 +92,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78473 return ret;
78474
78475 td->mutexes[id] = 1;
78476- td->event = atomic_add_return(1, &rttest_event);
78477+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78478 rt_mutex_lock(&mutexes[id]);
78479- td->event = atomic_add_return(1, &rttest_event);
78480+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78481 td->mutexes[id] = 4;
78482 return 0;
78483
78484@@ -105,9 +105,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78485 return ret;
78486
78487 td->mutexes[id] = 1;
78488- td->event = atomic_add_return(1, &rttest_event);
78489+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78490 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
78491- td->event = atomic_add_return(1, &rttest_event);
78492+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78493 td->mutexes[id] = ret ? 0 : 4;
78494 return ret ? -EINTR : 0;
78495
78496@@ -116,9 +116,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
78497 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
78498 return ret;
78499
78500- td->event = atomic_add_return(1, &rttest_event);
78501+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78502 rt_mutex_unlock(&mutexes[id]);
78503- td->event = atomic_add_return(1, &rttest_event);
78504+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78505 td->mutexes[id] = 0;
78506 return 0;
78507
78508@@ -165,7 +165,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78509 break;
78510
78511 td->mutexes[dat] = 2;
78512- td->event = atomic_add_return(1, &rttest_event);
78513+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78514 break;
78515
78516 default:
78517@@ -185,7 +185,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78518 return;
78519
78520 td->mutexes[dat] = 3;
78521- td->event = atomic_add_return(1, &rttest_event);
78522+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78523 break;
78524
78525 case RTTEST_LOCKNOWAIT:
78526@@ -197,7 +197,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
78527 return;
78528
78529 td->mutexes[dat] = 1;
78530- td->event = atomic_add_return(1, &rttest_event);
78531+ td->event = atomic_add_return_unchecked(1, &rttest_event);
78532 return;
78533
78534 default:
78535diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
78536index 64de5f8..7735e12 100644
78537--- a/kernel/sched/auto_group.c
78538+++ b/kernel/sched/auto_group.c
78539@@ -11,7 +11,7 @@
78540
78541 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
78542 static struct autogroup autogroup_default;
78543-static atomic_t autogroup_seq_nr;
78544+static atomic_unchecked_t autogroup_seq_nr;
78545
78546 void __init autogroup_init(struct task_struct *init_task)
78547 {
78548@@ -81,7 +81,7 @@ static inline struct autogroup *autogroup_create(void)
78549
78550 kref_init(&ag->kref);
78551 init_rwsem(&ag->lock);
78552- ag->id = atomic_inc_return(&autogroup_seq_nr);
78553+ ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
78554 ag->tg = tg;
78555 #ifdef CONFIG_RT_GROUP_SCHED
78556 /*
78557diff --git a/kernel/sched/core.c b/kernel/sched/core.c
78558index 67d0465..4cf9361 100644
78559--- a/kernel/sched/core.c
78560+++ b/kernel/sched/core.c
78561@@ -3406,7 +3406,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
78562 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78563 * positive (at least 1, or number of jiffies left till timeout) if completed.
78564 */
78565-long __sched
78566+long __sched __intentional_overflow(-1)
78567 wait_for_completion_interruptible_timeout(struct completion *x,
78568 unsigned long timeout)
78569 {
78570@@ -3423,7 +3423,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
78571 *
78572 * The return value is -ERESTARTSYS if interrupted, 0 if completed.
78573 */
78574-int __sched wait_for_completion_killable(struct completion *x)
78575+int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
78576 {
78577 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
78578 if (t == -ERESTARTSYS)
78579@@ -3444,7 +3444,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
78580 * The return value is -ERESTARTSYS if interrupted, 0 if timed out,
78581 * positive (at least 1, or number of jiffies left till timeout) if completed.
78582 */
78583-long __sched
78584+long __sched __intentional_overflow(-1)
78585 wait_for_completion_killable_timeout(struct completion *x,
78586 unsigned long timeout)
78587 {
78588@@ -3670,6 +3670,8 @@ int can_nice(const struct task_struct *p, const int nice)
78589 /* convert nice value [19,-20] to rlimit style value [1,40] */
78590 int nice_rlim = 20 - nice;
78591
78592+ gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
78593+
78594 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
78595 capable(CAP_SYS_NICE));
78596 }
78597@@ -3703,7 +3705,8 @@ SYSCALL_DEFINE1(nice, int, increment)
78598 if (nice > 19)
78599 nice = 19;
78600
78601- if (increment < 0 && !can_nice(current, nice))
78602+ if (increment < 0 && (!can_nice(current, nice) ||
78603+ gr_handle_chroot_nice()))
78604 return -EPERM;
78605
78606 retval = security_task_setnice(current, nice);
78607@@ -3857,6 +3860,7 @@ recheck:
78608 unsigned long rlim_rtprio =
78609 task_rlimit(p, RLIMIT_RTPRIO);
78610
78611+ gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
78612 /* can't set/change the rt policy */
78613 if (policy != p->policy && !rlim_rtprio)
78614 return -EPERM;
78615@@ -4954,7 +4958,7 @@ static void migrate_tasks(unsigned int dead_cpu)
78616
78617 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
78618
78619-static struct ctl_table sd_ctl_dir[] = {
78620+static ctl_table_no_const sd_ctl_dir[] __read_only = {
78621 {
78622 .procname = "sched_domain",
78623 .mode = 0555,
78624@@ -4971,17 +4975,17 @@ static struct ctl_table sd_ctl_root[] = {
78625 {}
78626 };
78627
78628-static struct ctl_table *sd_alloc_ctl_entry(int n)
78629+static ctl_table_no_const *sd_alloc_ctl_entry(int n)
78630 {
78631- struct ctl_table *entry =
78632+ ctl_table_no_const *entry =
78633 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
78634
78635 return entry;
78636 }
78637
78638-static void sd_free_ctl_entry(struct ctl_table **tablep)
78639+static void sd_free_ctl_entry(ctl_table_no_const *tablep)
78640 {
78641- struct ctl_table *entry;
78642+ ctl_table_no_const *entry;
78643
78644 /*
78645 * In the intermediate directories, both the child directory and
78646@@ -4989,22 +4993,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
78647 * will always be set. In the lowest directory the names are
78648 * static strings and all have proc handlers.
78649 */
78650- for (entry = *tablep; entry->mode; entry++) {
78651- if (entry->child)
78652- sd_free_ctl_entry(&entry->child);
78653+ for (entry = tablep; entry->mode; entry++) {
78654+ if (entry->child) {
78655+ sd_free_ctl_entry(entry->child);
78656+ pax_open_kernel();
78657+ entry->child = NULL;
78658+ pax_close_kernel();
78659+ }
78660 if (entry->proc_handler == NULL)
78661 kfree(entry->procname);
78662 }
78663
78664- kfree(*tablep);
78665- *tablep = NULL;
78666+ kfree(tablep);
78667 }
78668
78669 static int min_load_idx = 0;
78670 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
78671
78672 static void
78673-set_table_entry(struct ctl_table *entry,
78674+set_table_entry(ctl_table_no_const *entry,
78675 const char *procname, void *data, int maxlen,
78676 umode_t mode, proc_handler *proc_handler,
78677 bool load_idx)
78678@@ -5024,7 +5031,7 @@ set_table_entry(struct ctl_table *entry,
78679 static struct ctl_table *
78680 sd_alloc_ctl_domain_table(struct sched_domain *sd)
78681 {
78682- struct ctl_table *table = sd_alloc_ctl_entry(13);
78683+ ctl_table_no_const *table = sd_alloc_ctl_entry(13);
78684
78685 if (table == NULL)
78686 return NULL;
78687@@ -5059,9 +5066,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
78688 return table;
78689 }
78690
78691-static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
78692+static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
78693 {
78694- struct ctl_table *entry, *table;
78695+ ctl_table_no_const *entry, *table;
78696 struct sched_domain *sd;
78697 int domain_num = 0, i;
78698 char buf[32];
78699@@ -5088,11 +5095,13 @@ static struct ctl_table_header *sd_sysctl_header;
78700 static void register_sched_domain_sysctl(void)
78701 {
78702 int i, cpu_num = num_possible_cpus();
78703- struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
78704+ ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
78705 char buf[32];
78706
78707 WARN_ON(sd_ctl_dir[0].child);
78708+ pax_open_kernel();
78709 sd_ctl_dir[0].child = entry;
78710+ pax_close_kernel();
78711
78712 if (entry == NULL)
78713 return;
78714@@ -5115,8 +5124,12 @@ static void unregister_sched_domain_sysctl(void)
78715 if (sd_sysctl_header)
78716 unregister_sysctl_table(sd_sysctl_header);
78717 sd_sysctl_header = NULL;
78718- if (sd_ctl_dir[0].child)
78719- sd_free_ctl_entry(&sd_ctl_dir[0].child);
78720+ if (sd_ctl_dir[0].child) {
78721+ sd_free_ctl_entry(sd_ctl_dir[0].child);
78722+ pax_open_kernel();
78723+ sd_ctl_dir[0].child = NULL;
78724+ pax_close_kernel();
78725+ }
78726 }
78727 #else
78728 static void register_sched_domain_sysctl(void)
78729@@ -5215,7 +5228,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
78730 * happens before everything else. This has to be lower priority than
78731 * the notifier in the perf_event subsystem, though.
78732 */
78733-static struct notifier_block __cpuinitdata migration_notifier = {
78734+static struct notifier_block migration_notifier = {
78735 .notifier_call = migration_call,
78736 .priority = CPU_PRI_MIGRATION,
78737 };
78738diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
78739index 7a33e59..2f7730c 100644
78740--- a/kernel/sched/fair.c
78741+++ b/kernel/sched/fair.c
78742@@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
78743
78744 static void reset_ptenuma_scan(struct task_struct *p)
78745 {
78746- ACCESS_ONCE(p->mm->numa_scan_seq)++;
78747+ ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
78748 p->mm->numa_scan_offset = 0;
78749 }
78750
78751@@ -5654,7 +5654,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
78752 * run_rebalance_domains is triggered when needed from the scheduler tick.
78753 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
78754 */
78755-static void run_rebalance_domains(struct softirq_action *h)
78756+static void run_rebalance_domains(void)
78757 {
78758 int this_cpu = smp_processor_id();
78759 struct rq *this_rq = cpu_rq(this_cpu);
78760diff --git a/kernel/signal.c b/kernel/signal.c
78761index 598dc06..471310a 100644
78762--- a/kernel/signal.c
78763+++ b/kernel/signal.c
78764@@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
78765
78766 int print_fatal_signals __read_mostly;
78767
78768-static void __user *sig_handler(struct task_struct *t, int sig)
78769+static __sighandler_t sig_handler(struct task_struct *t, int sig)
78770 {
78771 return t->sighand->action[sig - 1].sa.sa_handler;
78772 }
78773
78774-static int sig_handler_ignored(void __user *handler, int sig)
78775+static int sig_handler_ignored(__sighandler_t handler, int sig)
78776 {
78777 /* Is it explicitly or implicitly ignored? */
78778 return handler == SIG_IGN ||
78779@@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
78780
78781 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
78782 {
78783- void __user *handler;
78784+ __sighandler_t handler;
78785
78786 handler = sig_handler(t, sig);
78787
78788@@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
78789 atomic_inc(&user->sigpending);
78790 rcu_read_unlock();
78791
78792+ if (!override_rlimit)
78793+ gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
78794+
78795 if (override_rlimit ||
78796 atomic_read(&user->sigpending) <=
78797 task_rlimit(t, RLIMIT_SIGPENDING)) {
78798@@ -495,7 +498,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
78799
78800 int unhandled_signal(struct task_struct *tsk, int sig)
78801 {
78802- void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
78803+ __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
78804 if (is_global_init(tsk))
78805 return 1;
78806 if (handler != SIG_IGN && handler != SIG_DFL)
78807@@ -815,6 +818,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
78808 }
78809 }
78810
78811+ /* allow glibc communication via tgkill to other threads in our
78812+ thread group */
78813+ if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
78814+ sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
78815+ && gr_handle_signal(t, sig))
78816+ return -EPERM;
78817+
78818 return security_task_kill(t, info, sig, 0);
78819 }
78820
78821@@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78822 return send_signal(sig, info, p, 1);
78823 }
78824
78825-static int
78826+int
78827 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78828 {
78829 return send_signal(sig, info, t, 0);
78830@@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78831 unsigned long int flags;
78832 int ret, blocked, ignored;
78833 struct k_sigaction *action;
78834+ int is_unhandled = 0;
78835
78836 spin_lock_irqsave(&t->sighand->siglock, flags);
78837 action = &t->sighand->action[sig-1];
78838@@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
78839 }
78840 if (action->sa.sa_handler == SIG_DFL)
78841 t->signal->flags &= ~SIGNAL_UNKILLABLE;
78842+ if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
78843+ is_unhandled = 1;
78844 ret = specific_send_sig_info(sig, info, t);
78845 spin_unlock_irqrestore(&t->sighand->siglock, flags);
78846
78847+ /* only deal with unhandled signals, java etc trigger SIGSEGV during
78848+ normal operation */
78849+ if (is_unhandled) {
78850+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
78851+ gr_handle_crash(t, sig);
78852+ }
78853+
78854 return ret;
78855 }
78856
78857@@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
78858 ret = check_kill_permission(sig, info, p);
78859 rcu_read_unlock();
78860
78861- if (!ret && sig)
78862+ if (!ret && sig) {
78863 ret = do_send_sig_info(sig, info, p, true);
78864+ if (!ret)
78865+ gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
78866+ }
78867
78868 return ret;
78869 }
78870@@ -2923,7 +2946,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
78871 int error = -ESRCH;
78872
78873 rcu_read_lock();
78874- p = find_task_by_vpid(pid);
78875+#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78876+ /* allow glibc communication via tgkill to other threads in our
78877+ thread group */
78878+ if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
78879+ sig == (SIGRTMIN+1) && tgid == info->si_pid)
78880+ p = find_task_by_vpid_unrestricted(pid);
78881+ else
78882+#endif
78883+ p = find_task_by_vpid(pid);
78884 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
78885 error = check_kill_permission(sig, info, p);
78886 /*
78887@@ -3237,8 +3268,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
78888 }
78889 seg = get_fs();
78890 set_fs(KERNEL_DS);
78891- ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
78892- (stack_t __force __user *) &uoss,
78893+ ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
78894+ (stack_t __force_user *) &uoss,
78895 compat_user_stack_pointer());
78896 set_fs(seg);
78897 if (ret >= 0 && uoss_ptr) {
78898diff --git a/kernel/smp.c b/kernel/smp.c
78899index 8e451f3..8322029 100644
78900--- a/kernel/smp.c
78901+++ b/kernel/smp.c
78902@@ -73,7 +73,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
78903 return NOTIFY_OK;
78904 }
78905
78906-static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
78907+static struct notifier_block hotplug_cfd_notifier = {
78908 .notifier_call = hotplug_cfd,
78909 };
78910
78911diff --git a/kernel/smpboot.c b/kernel/smpboot.c
78912index 02fc5c9..e54c335 100644
78913--- a/kernel/smpboot.c
78914+++ b/kernel/smpboot.c
78915@@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
78916 }
78917 smpboot_unpark_thread(plug_thread, cpu);
78918 }
78919- list_add(&plug_thread->list, &hotplug_threads);
78920+ pax_list_add(&plug_thread->list, &hotplug_threads);
78921 out:
78922 mutex_unlock(&smpboot_threads_lock);
78923 return ret;
78924@@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
78925 {
78926 get_online_cpus();
78927 mutex_lock(&smpboot_threads_lock);
78928- list_del(&plug_thread->list);
78929+ pax_list_del(&plug_thread->list);
78930 smpboot_destroy_threads(plug_thread);
78931 mutex_unlock(&smpboot_threads_lock);
78932 put_online_cpus();
78933diff --git a/kernel/softirq.c b/kernel/softirq.c
78934index d93dcb1..1cd8a71 100644
78935--- a/kernel/softirq.c
78936+++ b/kernel/softirq.c
78937@@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
78938 EXPORT_SYMBOL(irq_stat);
78939 #endif
78940
78941-static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
78942+static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
78943
78944 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
78945
78946-char *softirq_to_name[NR_SOFTIRQS] = {
78947+const char * const softirq_to_name[NR_SOFTIRQS] = {
78948 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
78949 "TASKLET", "SCHED", "HRTIMER", "RCU"
78950 };
78951@@ -250,7 +250,7 @@ restart:
78952 kstat_incr_softirqs_this_cpu(vec_nr);
78953
78954 trace_softirq_entry(vec_nr);
78955- h->action(h);
78956+ h->action();
78957 trace_softirq_exit(vec_nr);
78958 if (unlikely(prev_count != preempt_count())) {
78959 printk(KERN_ERR "huh, entered softirq %u %s %p"
78960@@ -396,7 +396,7 @@ void __raise_softirq_irqoff(unsigned int nr)
78961 or_softirq_pending(1UL << nr);
78962 }
78963
78964-void open_softirq(int nr, void (*action)(struct softirq_action *))
78965+void __init open_softirq(int nr, void (*action)(void))
78966 {
78967 softirq_vec[nr].action = action;
78968 }
78969@@ -452,7 +452,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
78970
78971 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
78972
78973-static void tasklet_action(struct softirq_action *a)
78974+static void tasklet_action(void)
78975 {
78976 struct tasklet_struct *list;
78977
78978@@ -487,7 +487,7 @@ static void tasklet_action(struct softirq_action *a)
78979 }
78980 }
78981
78982-static void tasklet_hi_action(struct softirq_action *a)
78983+static void tasklet_hi_action(void)
78984 {
78985 struct tasklet_struct *list;
78986
78987@@ -723,7 +723,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
78988 return NOTIFY_OK;
78989 }
78990
78991-static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
78992+static struct notifier_block remote_softirq_cpu_notifier = {
78993 .notifier_call = remote_softirq_cpu_notify,
78994 };
78995
78996@@ -840,11 +840,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
78997 return NOTIFY_OK;
78998 }
78999
79000-static struct notifier_block __cpuinitdata cpu_nfb = {
79001+static struct notifier_block cpu_nfb = {
79002 .notifier_call = cpu_callback
79003 };
79004
79005-static struct smp_hotplug_thread softirq_threads = {
79006+static struct smp_hotplug_thread softirq_threads __read_only = {
79007 .store = &ksoftirqd,
79008 .thread_should_run = ksoftirqd_should_run,
79009 .thread_fn = run_ksoftirqd,
79010diff --git a/kernel/srcu.c b/kernel/srcu.c
79011index 01d5ccb..cdcbee6 100644
79012--- a/kernel/srcu.c
79013+++ b/kernel/srcu.c
79014@@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
79015
79016 idx = ACCESS_ONCE(sp->completed) & 0x1;
79017 preempt_disable();
79018- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79019+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
79020 smp_mb(); /* B */ /* Avoid leaking the critical section. */
79021- ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79022+ ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
79023 preempt_enable();
79024 return idx;
79025 }
79026diff --git a/kernel/sys.c b/kernel/sys.c
79027index e5f0aca..8d58b1f 100644
79028--- a/kernel/sys.c
79029+++ b/kernel/sys.c
79030@@ -158,6 +158,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
79031 error = -EACCES;
79032 goto out;
79033 }
79034+
79035+ if (gr_handle_chroot_setpriority(p, niceval)) {
79036+ error = -EACCES;
79037+ goto out;
79038+ }
79039+
79040 no_nice = security_task_setnice(p, niceval);
79041 if (no_nice) {
79042 error = no_nice;
79043@@ -621,6 +627,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
79044 goto error;
79045 }
79046
79047+ if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
79048+ goto error;
79049+
79050 if (rgid != (gid_t) -1 ||
79051 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
79052 new->sgid = new->egid;
79053@@ -656,6 +665,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
79054 old = current_cred();
79055
79056 retval = -EPERM;
79057+
79058+ if (gr_check_group_change(kgid, kgid, kgid))
79059+ goto error;
79060+
79061 if (nsown_capable(CAP_SETGID))
79062 new->gid = new->egid = new->sgid = new->fsgid = kgid;
79063 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
79064@@ -673,7 +686,7 @@ error:
79065 /*
79066 * change the user struct in a credentials set to match the new UID
79067 */
79068-static int set_user(struct cred *new)
79069+int set_user(struct cred *new)
79070 {
79071 struct user_struct *new_user;
79072
79073@@ -753,6 +766,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
79074 goto error;
79075 }
79076
79077+ if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
79078+ goto error;
79079+
79080 if (!uid_eq(new->uid, old->uid)) {
79081 retval = set_user(new);
79082 if (retval < 0)
79083@@ -803,6 +819,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
79084 old = current_cred();
79085
79086 retval = -EPERM;
79087+
79088+ if (gr_check_crash_uid(kuid))
79089+ goto error;
79090+ if (gr_check_user_change(kuid, kuid, kuid))
79091+ goto error;
79092+
79093 if (nsown_capable(CAP_SETUID)) {
79094 new->suid = new->uid = kuid;
79095 if (!uid_eq(kuid, old->uid)) {
79096@@ -872,6 +894,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
79097 goto error;
79098 }
79099
79100+ if (gr_check_user_change(kruid, keuid, INVALID_UID))
79101+ goto error;
79102+
79103 if (ruid != (uid_t) -1) {
79104 new->uid = kruid;
79105 if (!uid_eq(kruid, old->uid)) {
79106@@ -954,6 +979,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
79107 goto error;
79108 }
79109
79110+ if (gr_check_group_change(krgid, kegid, INVALID_GID))
79111+ goto error;
79112+
79113 if (rgid != (gid_t) -1)
79114 new->gid = krgid;
79115 if (egid != (gid_t) -1)
79116@@ -1015,12 +1043,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
79117 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
79118 nsown_capable(CAP_SETUID)) {
79119 if (!uid_eq(kuid, old->fsuid)) {
79120+ if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
79121+ goto error;
79122+
79123 new->fsuid = kuid;
79124 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
79125 goto change_okay;
79126 }
79127 }
79128
79129+error:
79130 abort_creds(new);
79131 return old_fsuid;
79132
79133@@ -1053,12 +1085,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
79134 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
79135 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
79136 nsown_capable(CAP_SETGID)) {
79137+ if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
79138+ goto error;
79139+
79140 if (!gid_eq(kgid, old->fsgid)) {
79141 new->fsgid = kgid;
79142 goto change_okay;
79143 }
79144 }
79145
79146+error:
79147 abort_creds(new);
79148 return old_fsgid;
79149
79150@@ -1366,19 +1402,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
79151 return -EFAULT;
79152
79153 down_read(&uts_sem);
79154- error = __copy_to_user(&name->sysname, &utsname()->sysname,
79155+ error = __copy_to_user(name->sysname, &utsname()->sysname,
79156 __OLD_UTS_LEN);
79157 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
79158- error |= __copy_to_user(&name->nodename, &utsname()->nodename,
79159+ error |= __copy_to_user(name->nodename, &utsname()->nodename,
79160 __OLD_UTS_LEN);
79161 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
79162- error |= __copy_to_user(&name->release, &utsname()->release,
79163+ error |= __copy_to_user(name->release, &utsname()->release,
79164 __OLD_UTS_LEN);
79165 error |= __put_user(0, name->release + __OLD_UTS_LEN);
79166- error |= __copy_to_user(&name->version, &utsname()->version,
79167+ error |= __copy_to_user(name->version, &utsname()->version,
79168 __OLD_UTS_LEN);
79169 error |= __put_user(0, name->version + __OLD_UTS_LEN);
79170- error |= __copy_to_user(&name->machine, &utsname()->machine,
79171+ error |= __copy_to_user(name->machine, &utsname()->machine,
79172 __OLD_UTS_LEN);
79173 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
79174 up_read(&uts_sem);
79175@@ -1580,6 +1616,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
79176 */
79177 new_rlim->rlim_cur = 1;
79178 }
79179+ /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
79180+ is changed to a lower value. Since tasks can be created by the same
79181+ user in between this limit change and an execve by this task, force
79182+ a recheck only for this task by setting PF_NPROC_EXCEEDED
79183+ */
79184+ if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
79185+ tsk->flags |= PF_NPROC_EXCEEDED;
79186 }
79187 if (!retval) {
79188 if (old_rlim)
79189diff --git a/kernel/sysctl.c b/kernel/sysctl.c
79190index afc1dc6..f6cf355 100644
79191--- a/kernel/sysctl.c
79192+++ b/kernel/sysctl.c
79193@@ -93,7 +93,6 @@
79194
79195
79196 #if defined(CONFIG_SYSCTL)
79197-
79198 /* External variables not in a header file. */
79199 extern int sysctl_overcommit_memory;
79200 extern int sysctl_overcommit_ratio;
79201@@ -120,18 +119,18 @@ extern int blk_iopoll_enabled;
79202
79203 /* Constants used for minimum and maximum */
79204 #ifdef CONFIG_LOCKUP_DETECTOR
79205-static int sixty = 60;
79206-static int neg_one = -1;
79207+static int sixty __read_only = 60;
79208 #endif
79209
79210-static int zero;
79211-static int __maybe_unused one = 1;
79212-static int __maybe_unused two = 2;
79213-static int __maybe_unused three = 3;
79214-static unsigned long one_ul = 1;
79215-static int one_hundred = 100;
79216+static int neg_one __read_only = -1;
79217+static int zero __read_only = 0;
79218+static int __maybe_unused one __read_only = 1;
79219+static int __maybe_unused two __read_only = 2;
79220+static int __maybe_unused three __read_only = 3;
79221+static unsigned long one_ul __read_only = 1;
79222+static int one_hundred __read_only = 100;
79223 #ifdef CONFIG_PRINTK
79224-static int ten_thousand = 10000;
79225+static int ten_thousand __read_only = 10000;
79226 #endif
79227
79228 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
79229@@ -178,10 +177,8 @@ static int proc_taint(struct ctl_table *table, int write,
79230 void __user *buffer, size_t *lenp, loff_t *ppos);
79231 #endif
79232
79233-#ifdef CONFIG_PRINTK
79234 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79235 void __user *buffer, size_t *lenp, loff_t *ppos);
79236-#endif
79237
79238 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
79239 void __user *buffer, size_t *lenp, loff_t *ppos);
79240@@ -212,6 +209,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
79241
79242 #endif
79243
79244+extern struct ctl_table grsecurity_table[];
79245+
79246 static struct ctl_table kern_table[];
79247 static struct ctl_table vm_table[];
79248 static struct ctl_table fs_table[];
79249@@ -226,6 +225,20 @@ extern struct ctl_table epoll_table[];
79250 int sysctl_legacy_va_layout;
79251 #endif
79252
79253+#ifdef CONFIG_PAX_SOFTMODE
79254+static ctl_table pax_table[] = {
79255+ {
79256+ .procname = "softmode",
79257+ .data = &pax_softmode,
79258+ .maxlen = sizeof(unsigned int),
79259+ .mode = 0600,
79260+ .proc_handler = &proc_dointvec,
79261+ },
79262+
79263+ { }
79264+};
79265+#endif
79266+
79267 /* The default sysctl tables: */
79268
79269 static struct ctl_table sysctl_base_table[] = {
79270@@ -274,6 +287,22 @@ static int max_extfrag_threshold = 1000;
79271 #endif
79272
79273 static struct ctl_table kern_table[] = {
79274+#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
79275+ {
79276+ .procname = "grsecurity",
79277+ .mode = 0500,
79278+ .child = grsecurity_table,
79279+ },
79280+#endif
79281+
79282+#ifdef CONFIG_PAX_SOFTMODE
79283+ {
79284+ .procname = "pax",
79285+ .mode = 0500,
79286+ .child = pax_table,
79287+ },
79288+#endif
79289+
79290 {
79291 .procname = "sched_child_runs_first",
79292 .data = &sysctl_sched_child_runs_first,
79293@@ -608,7 +637,7 @@ static struct ctl_table kern_table[] = {
79294 .data = &modprobe_path,
79295 .maxlen = KMOD_PATH_LEN,
79296 .mode = 0644,
79297- .proc_handler = proc_dostring,
79298+ .proc_handler = proc_dostring_modpriv,
79299 },
79300 {
79301 .procname = "modules_disabled",
79302@@ -775,16 +804,20 @@ static struct ctl_table kern_table[] = {
79303 .extra1 = &zero,
79304 .extra2 = &one,
79305 },
79306+#endif
79307 {
79308 .procname = "kptr_restrict",
79309 .data = &kptr_restrict,
79310 .maxlen = sizeof(int),
79311 .mode = 0644,
79312 .proc_handler = proc_dointvec_minmax_sysadmin,
79313+#ifdef CONFIG_GRKERNSEC_HIDESYM
79314+ .extra1 = &two,
79315+#else
79316 .extra1 = &zero,
79317+#endif
79318 .extra2 = &two,
79319 },
79320-#endif
79321 {
79322 .procname = "ngroups_max",
79323 .data = &ngroups_max,
79324@@ -1026,10 +1059,17 @@ static struct ctl_table kern_table[] = {
79325 */
79326 {
79327 .procname = "perf_event_paranoid",
79328- .data = &sysctl_perf_event_paranoid,
79329- .maxlen = sizeof(sysctl_perf_event_paranoid),
79330+ .data = &sysctl_perf_event_legitimately_concerned,
79331+ .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
79332 .mode = 0644,
79333- .proc_handler = proc_dointvec,
79334+ /* go ahead, be a hero */
79335+ .proc_handler = proc_dointvec_minmax_sysadmin,
79336+ .extra1 = &neg_one,
79337+#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
79338+ .extra2 = &three,
79339+#else
79340+ .extra2 = &two,
79341+#endif
79342 },
79343 {
79344 .procname = "perf_event_mlock_kb",
79345@@ -1283,6 +1323,13 @@ static struct ctl_table vm_table[] = {
79346 .proc_handler = proc_dointvec_minmax,
79347 .extra1 = &zero,
79348 },
79349+ {
79350+ .procname = "heap_stack_gap",
79351+ .data = &sysctl_heap_stack_gap,
79352+ .maxlen = sizeof(sysctl_heap_stack_gap),
79353+ .mode = 0644,
79354+ .proc_handler = proc_doulongvec_minmax,
79355+ },
79356 #else
79357 {
79358 .procname = "nr_trim_pages",
79359@@ -1733,6 +1780,16 @@ int proc_dostring(struct ctl_table *table, int write,
79360 buffer, lenp, ppos);
79361 }
79362
79363+int proc_dostring_modpriv(struct ctl_table *table, int write,
79364+ void __user *buffer, size_t *lenp, loff_t *ppos)
79365+{
79366+ if (write && !capable(CAP_SYS_MODULE))
79367+ return -EPERM;
79368+
79369+ return _proc_do_string(table->data, table->maxlen, write,
79370+ buffer, lenp, ppos);
79371+}
79372+
79373 static size_t proc_skip_spaces(char **buf)
79374 {
79375 size_t ret;
79376@@ -1838,6 +1895,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
79377 len = strlen(tmp);
79378 if (len > *size)
79379 len = *size;
79380+ if (len > sizeof(tmp))
79381+ len = sizeof(tmp);
79382 if (copy_to_user(*buf, tmp, len))
79383 return -EFAULT;
79384 *size -= len;
79385@@ -2002,7 +2061,7 @@ int proc_dointvec(struct ctl_table *table, int write,
79386 static int proc_taint(struct ctl_table *table, int write,
79387 void __user *buffer, size_t *lenp, loff_t *ppos)
79388 {
79389- struct ctl_table t;
79390+ ctl_table_no_const t;
79391 unsigned long tmptaint = get_taint();
79392 int err;
79393
79394@@ -2030,7 +2089,6 @@ static int proc_taint(struct ctl_table *table, int write,
79395 return err;
79396 }
79397
79398-#ifdef CONFIG_PRINTK
79399 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79400 void __user *buffer, size_t *lenp, loff_t *ppos)
79401 {
79402@@ -2039,7 +2097,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
79403
79404 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
79405 }
79406-#endif
79407
79408 struct do_proc_dointvec_minmax_conv_param {
79409 int *min;
79410@@ -2186,8 +2243,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
79411 *i = val;
79412 } else {
79413 val = convdiv * (*i) / convmul;
79414- if (!first)
79415+ if (!first) {
79416 err = proc_put_char(&buffer, &left, '\t');
79417+ if (err)
79418+ break;
79419+ }
79420 err = proc_put_long(&buffer, &left, val, false);
79421 if (err)
79422 break;
79423@@ -2579,6 +2639,12 @@ int proc_dostring(struct ctl_table *table, int write,
79424 return -ENOSYS;
79425 }
79426
79427+int proc_dostring_modpriv(struct ctl_table *table, int write,
79428+ void __user *buffer, size_t *lenp, loff_t *ppos)
79429+{
79430+ return -ENOSYS;
79431+}
79432+
79433 int proc_dointvec(struct ctl_table *table, int write,
79434 void __user *buffer, size_t *lenp, loff_t *ppos)
79435 {
79436@@ -2635,5 +2701,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
79437 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
79438 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
79439 EXPORT_SYMBOL(proc_dostring);
79440+EXPORT_SYMBOL(proc_dostring_modpriv);
79441 EXPORT_SYMBOL(proc_doulongvec_minmax);
79442 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
79443diff --git a/kernel/taskstats.c b/kernel/taskstats.c
79444index 145bb4d..b2aa969 100644
79445--- a/kernel/taskstats.c
79446+++ b/kernel/taskstats.c
79447@@ -28,9 +28,12 @@
79448 #include <linux/fs.h>
79449 #include <linux/file.h>
79450 #include <linux/pid_namespace.h>
79451+#include <linux/grsecurity.h>
79452 #include <net/genetlink.h>
79453 #include <linux/atomic.h>
79454
79455+extern int gr_is_taskstats_denied(int pid);
79456+
79457 /*
79458 * Maximum length of a cpumask that can be specified in
79459 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
79460@@ -570,6 +573,9 @@ err:
79461
79462 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
79463 {
79464+ if (gr_is_taskstats_denied(current->pid))
79465+ return -EACCES;
79466+
79467 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
79468 return cmd_attr_register_cpumask(info);
79469 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
79470diff --git a/kernel/time.c b/kernel/time.c
79471index f8342a4..288f13b 100644
79472--- a/kernel/time.c
79473+++ b/kernel/time.c
79474@@ -171,6 +171,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
79475 return error;
79476
79477 if (tz) {
79478+ /* we log in do_settimeofday called below, so don't log twice
79479+ */
79480+ if (!tv)
79481+ gr_log_timechange();
79482+
79483 sys_tz = *tz;
79484 update_vsyscall_tz();
79485 if (firsttime) {
79486@@ -501,7 +506,7 @@ EXPORT_SYMBOL(usecs_to_jiffies);
79487 * The >> (NSEC_JIFFIE_SC - SEC_JIFFIE_SC) converts the scaled nsec
79488 * value to a scaled second value.
79489 */
79490-unsigned long
79491+unsigned long __intentional_overflow(-1)
79492 timespec_to_jiffies(const struct timespec *value)
79493 {
79494 unsigned long sec = value->tv_sec;
79495diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
79496index f11d83b..d016d91 100644
79497--- a/kernel/time/alarmtimer.c
79498+++ b/kernel/time/alarmtimer.c
79499@@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
79500 struct platform_device *pdev;
79501 int error = 0;
79502 int i;
79503- struct k_clock alarm_clock = {
79504+ static struct k_clock alarm_clock = {
79505 .clock_getres = alarm_clock_getres,
79506 .clock_get = alarm_clock_get,
79507 .timer_create = alarm_timer_create,
79508diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
79509index 90ad470..1814e9a 100644
79510--- a/kernel/time/tick-broadcast.c
79511+++ b/kernel/time/tick-broadcast.c
79512@@ -138,7 +138,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
79513 * then clear the broadcast bit.
79514 */
79515 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
79516- int cpu = smp_processor_id();
79517+ cpu = smp_processor_id();
79518 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
79519 tick_broadcast_clear_oneshot(cpu);
79520 } else {
79521diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
79522index 183df62..59b1442 100644
79523--- a/kernel/time/timekeeping.c
79524+++ b/kernel/time/timekeeping.c
79525@@ -15,6 +15,7 @@
79526 #include <linux/init.h>
79527 #include <linux/mm.h>
79528 #include <linux/sched.h>
79529+#include <linux/grsecurity.h>
79530 #include <linux/syscore_ops.h>
79531 #include <linux/clocksource.h>
79532 #include <linux/jiffies.h>
79533@@ -448,6 +449,8 @@ int do_settimeofday(const struct timespec *tv)
79534 if (!timespec_valid_strict(tv))
79535 return -EINVAL;
79536
79537+ gr_log_timechange();
79538+
79539 write_seqlock_irqsave(&tk->lock, flags);
79540
79541 timekeeping_forward_now(tk);
79542diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
79543index af5a7e9..715611a 100644
79544--- a/kernel/time/timer_list.c
79545+++ b/kernel/time/timer_list.c
79546@@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
79547
79548 static void print_name_offset(struct seq_file *m, void *sym)
79549 {
79550+#ifdef CONFIG_GRKERNSEC_HIDESYM
79551+ SEQ_printf(m, "<%p>", NULL);
79552+#else
79553 char symname[KSYM_NAME_LEN];
79554
79555 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
79556 SEQ_printf(m, "<%pK>", sym);
79557 else
79558 SEQ_printf(m, "%s", symname);
79559+#endif
79560 }
79561
79562 static void
79563@@ -112,7 +116,11 @@ next_one:
79564 static void
79565 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
79566 {
79567+#ifdef CONFIG_GRKERNSEC_HIDESYM
79568+ SEQ_printf(m, " .base: %p\n", NULL);
79569+#else
79570 SEQ_printf(m, " .base: %pK\n", base);
79571+#endif
79572 SEQ_printf(m, " .index: %d\n",
79573 base->index);
79574 SEQ_printf(m, " .resolution: %Lu nsecs\n",
79575@@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
79576 {
79577 struct proc_dir_entry *pe;
79578
79579+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79580+ pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
79581+#else
79582 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
79583+#endif
79584 if (!pe)
79585 return -ENOMEM;
79586 return 0;
79587diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
79588index 0b537f2..40d6c20 100644
79589--- a/kernel/time/timer_stats.c
79590+++ b/kernel/time/timer_stats.c
79591@@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
79592 static unsigned long nr_entries;
79593 static struct entry entries[MAX_ENTRIES];
79594
79595-static atomic_t overflow_count;
79596+static atomic_unchecked_t overflow_count;
79597
79598 /*
79599 * The entries are in a hash-table, for fast lookup:
79600@@ -140,7 +140,7 @@ static void reset_entries(void)
79601 nr_entries = 0;
79602 memset(entries, 0, sizeof(entries));
79603 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
79604- atomic_set(&overflow_count, 0);
79605+ atomic_set_unchecked(&overflow_count, 0);
79606 }
79607
79608 static struct entry *alloc_entry(void)
79609@@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79610 if (likely(entry))
79611 entry->count++;
79612 else
79613- atomic_inc(&overflow_count);
79614+ atomic_inc_unchecked(&overflow_count);
79615
79616 out_unlock:
79617 raw_spin_unlock_irqrestore(lock, flags);
79618@@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
79619
79620 static void print_name_offset(struct seq_file *m, unsigned long addr)
79621 {
79622+#ifdef CONFIG_GRKERNSEC_HIDESYM
79623+ seq_printf(m, "<%p>", NULL);
79624+#else
79625 char symname[KSYM_NAME_LEN];
79626
79627 if (lookup_symbol_name(addr, symname) < 0)
79628- seq_printf(m, "<%p>", (void *)addr);
79629+ seq_printf(m, "<%pK>", (void *)addr);
79630 else
79631 seq_printf(m, "%s", symname);
79632+#endif
79633 }
79634
79635 static int tstats_show(struct seq_file *m, void *v)
79636@@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
79637
79638 seq_puts(m, "Timer Stats Version: v0.2\n");
79639 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
79640- if (atomic_read(&overflow_count))
79641+ if (atomic_read_unchecked(&overflow_count))
79642 seq_printf(m, "Overflow: %d entries\n",
79643- atomic_read(&overflow_count));
79644+ atomic_read_unchecked(&overflow_count));
79645
79646 for (i = 0; i < nr_entries; i++) {
79647 entry = entries + i;
79648@@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
79649 {
79650 struct proc_dir_entry *pe;
79651
79652+#ifdef CONFIG_GRKERNSEC_PROC_ADD
79653+ pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
79654+#else
79655 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
79656+#endif
79657 if (!pe)
79658 return -ENOMEM;
79659 return 0;
79660diff --git a/kernel/timer.c b/kernel/timer.c
79661index 1b399c8..90e1849 100644
79662--- a/kernel/timer.c
79663+++ b/kernel/timer.c
79664@@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
79665 /*
79666 * This function runs timers and the timer-tq in bottom half context.
79667 */
79668-static void run_timer_softirq(struct softirq_action *h)
79669+static void run_timer_softirq(void)
79670 {
79671 struct tvec_base *base = __this_cpu_read(tvec_bases);
79672
79673@@ -1481,7 +1481,7 @@ static void process_timeout(unsigned long __data)
79674 *
79675 * In all cases the return value is guaranteed to be non-negative.
79676 */
79677-signed long __sched schedule_timeout(signed long timeout)
79678+signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
79679 {
79680 struct timer_list timer;
79681 unsigned long expire;
79682@@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
79683 return NOTIFY_OK;
79684 }
79685
79686-static struct notifier_block __cpuinitdata timers_nb = {
79687+static struct notifier_block timers_nb = {
79688 .notifier_call = timer_cpu_notify,
79689 };
79690
79691diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
79692index 5a0f781..1497f95 100644
79693--- a/kernel/trace/blktrace.c
79694+++ b/kernel/trace/blktrace.c
79695@@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
79696 struct blk_trace *bt = filp->private_data;
79697 char buf[16];
79698
79699- snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
79700+ snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
79701
79702 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
79703 }
79704@@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
79705 return 1;
79706
79707 bt = buf->chan->private_data;
79708- atomic_inc(&bt->dropped);
79709+ atomic_inc_unchecked(&bt->dropped);
79710 return 0;
79711 }
79712
79713@@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
79714
79715 bt->dir = dir;
79716 bt->dev = dev;
79717- atomic_set(&bt->dropped, 0);
79718+ atomic_set_unchecked(&bt->dropped, 0);
79719
79720 ret = -EIO;
79721 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
79722diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
79723index 0a0e2a6..943495e 100644
79724--- a/kernel/trace/ftrace.c
79725+++ b/kernel/trace/ftrace.c
79726@@ -1909,12 +1909,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
79727 if (unlikely(ftrace_disabled))
79728 return 0;
79729
79730+ ret = ftrace_arch_code_modify_prepare();
79731+ FTRACE_WARN_ON(ret);
79732+ if (ret)
79733+ return 0;
79734+
79735 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
79736+ FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
79737 if (ret) {
79738 ftrace_bug(ret, ip);
79739- return 0;
79740 }
79741- return 1;
79742+ return ret ? 0 : 1;
79743 }
79744
79745 /*
79746@@ -2986,7 +2991,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
79747
79748 int
79749 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
79750- void *data)
79751+ void *data)
79752 {
79753 struct ftrace_func_probe *entry;
79754 struct ftrace_page *pg;
79755@@ -3854,8 +3859,10 @@ static int ftrace_process_locs(struct module *mod,
79756 if (!count)
79757 return 0;
79758
79759+ pax_open_kernel();
79760 sort(start, count, sizeof(*start),
79761 ftrace_cmp_ips, ftrace_swap_ips);
79762+ pax_close_kernel();
79763
79764 start_pg = ftrace_allocate_pages(count);
79765 if (!start_pg)
79766@@ -4574,8 +4581,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
79767 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
79768
79769 static int ftrace_graph_active;
79770-static struct notifier_block ftrace_suspend_notifier;
79771-
79772 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
79773 {
79774 return 0;
79775@@ -4719,6 +4724,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
79776 return NOTIFY_DONE;
79777 }
79778
79779+static struct notifier_block ftrace_suspend_notifier = {
79780+ .notifier_call = ftrace_suspend_notifier_call
79781+};
79782+
79783 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79784 trace_func_graph_ent_t entryfunc)
79785 {
79786@@ -4732,7 +4741,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
79787 goto out;
79788 }
79789
79790- ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
79791 register_pm_notifier(&ftrace_suspend_notifier);
79792
79793 ftrace_graph_active++;
79794diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
79795index 6989df2..c2265cf 100644
79796--- a/kernel/trace/ring_buffer.c
79797+++ b/kernel/trace/ring_buffer.c
79798@@ -349,9 +349,9 @@ struct buffer_data_page {
79799 */
79800 struct buffer_page {
79801 struct list_head list; /* list of buffer pages */
79802- local_t write; /* index for next write */
79803+ local_unchecked_t write; /* index for next write */
79804 unsigned read; /* index for next read */
79805- local_t entries; /* entries on this page */
79806+ local_unchecked_t entries; /* entries on this page */
79807 unsigned long real_end; /* real end of data */
79808 struct buffer_data_page *page; /* Actual data page */
79809 };
79810@@ -464,8 +464,8 @@ struct ring_buffer_per_cpu {
79811 unsigned long last_overrun;
79812 local_t entries_bytes;
79813 local_t entries;
79814- local_t overrun;
79815- local_t commit_overrun;
79816+ local_unchecked_t overrun;
79817+ local_unchecked_t commit_overrun;
79818 local_t dropped_events;
79819 local_t committing;
79820 local_t commits;
79821@@ -864,8 +864,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79822 *
79823 * We add a counter to the write field to denote this.
79824 */
79825- old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
79826- old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
79827+ old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
79828+ old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
79829
79830 /*
79831 * Just make sure we have seen our old_write and synchronize
79832@@ -893,8 +893,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
79833 * cmpxchg to only update if an interrupt did not already
79834 * do it for us. If the cmpxchg fails, we don't care.
79835 */
79836- (void)local_cmpxchg(&next_page->write, old_write, val);
79837- (void)local_cmpxchg(&next_page->entries, old_entries, eval);
79838+ (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
79839+ (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
79840
79841 /*
79842 * No need to worry about races with clearing out the commit.
79843@@ -1253,12 +1253,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
79844
79845 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
79846 {
79847- return local_read(&bpage->entries) & RB_WRITE_MASK;
79848+ return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
79849 }
79850
79851 static inline unsigned long rb_page_write(struct buffer_page *bpage)
79852 {
79853- return local_read(&bpage->write) & RB_WRITE_MASK;
79854+ return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
79855 }
79856
79857 static int
79858@@ -1353,7 +1353,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
79859 * bytes consumed in ring buffer from here.
79860 * Increment overrun to account for the lost events.
79861 */
79862- local_add(page_entries, &cpu_buffer->overrun);
79863+ local_add_unchecked(page_entries, &cpu_buffer->overrun);
79864 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79865 }
79866
79867@@ -1909,7 +1909,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
79868 * it is our responsibility to update
79869 * the counters.
79870 */
79871- local_add(entries, &cpu_buffer->overrun);
79872+ local_add_unchecked(entries, &cpu_buffer->overrun);
79873 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
79874
79875 /*
79876@@ -2059,7 +2059,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79877 if (tail == BUF_PAGE_SIZE)
79878 tail_page->real_end = 0;
79879
79880- local_sub(length, &tail_page->write);
79881+ local_sub_unchecked(length, &tail_page->write);
79882 return;
79883 }
79884
79885@@ -2094,7 +2094,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79886 rb_event_set_padding(event);
79887
79888 /* Set the write back to the previous setting */
79889- local_sub(length, &tail_page->write);
79890+ local_sub_unchecked(length, &tail_page->write);
79891 return;
79892 }
79893
79894@@ -2106,7 +2106,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
79895
79896 /* Set write to end of buffer */
79897 length = (tail + length) - BUF_PAGE_SIZE;
79898- local_sub(length, &tail_page->write);
79899+ local_sub_unchecked(length, &tail_page->write);
79900 }
79901
79902 /*
79903@@ -2132,7 +2132,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79904 * about it.
79905 */
79906 if (unlikely(next_page == commit_page)) {
79907- local_inc(&cpu_buffer->commit_overrun);
79908+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79909 goto out_reset;
79910 }
79911
79912@@ -2188,7 +2188,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
79913 cpu_buffer->tail_page) &&
79914 (cpu_buffer->commit_page ==
79915 cpu_buffer->reader_page))) {
79916- local_inc(&cpu_buffer->commit_overrun);
79917+ local_inc_unchecked(&cpu_buffer->commit_overrun);
79918 goto out_reset;
79919 }
79920 }
79921@@ -2236,7 +2236,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79922 length += RB_LEN_TIME_EXTEND;
79923
79924 tail_page = cpu_buffer->tail_page;
79925- write = local_add_return(length, &tail_page->write);
79926+ write = local_add_return_unchecked(length, &tail_page->write);
79927
79928 /* set write to only the index of the write */
79929 write &= RB_WRITE_MASK;
79930@@ -2253,7 +2253,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
79931 kmemcheck_annotate_bitfield(event, bitfield);
79932 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
79933
79934- local_inc(&tail_page->entries);
79935+ local_inc_unchecked(&tail_page->entries);
79936
79937 /*
79938 * If this is the first commit on the page, then update
79939@@ -2286,7 +2286,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79940
79941 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
79942 unsigned long write_mask =
79943- local_read(&bpage->write) & ~RB_WRITE_MASK;
79944+ local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
79945 unsigned long event_length = rb_event_length(event);
79946 /*
79947 * This is on the tail page. It is possible that
79948@@ -2296,7 +2296,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
79949 */
79950 old_index += write_mask;
79951 new_index += write_mask;
79952- index = local_cmpxchg(&bpage->write, old_index, new_index);
79953+ index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
79954 if (index == old_index) {
79955 /* update counters */
79956 local_sub(event_length, &cpu_buffer->entries_bytes);
79957@@ -2670,7 +2670,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79958
79959 /* Do the likely case first */
79960 if (likely(bpage->page == (void *)addr)) {
79961- local_dec(&bpage->entries);
79962+ local_dec_unchecked(&bpage->entries);
79963 return;
79964 }
79965
79966@@ -2682,7 +2682,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
79967 start = bpage;
79968 do {
79969 if (bpage->page == (void *)addr) {
79970- local_dec(&bpage->entries);
79971+ local_dec_unchecked(&bpage->entries);
79972 return;
79973 }
79974 rb_inc_page(cpu_buffer, &bpage);
79975@@ -2964,7 +2964,7 @@ static inline unsigned long
79976 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
79977 {
79978 return local_read(&cpu_buffer->entries) -
79979- (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
79980+ (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
79981 }
79982
79983 /**
79984@@ -3053,7 +3053,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
79985 return 0;
79986
79987 cpu_buffer = buffer->buffers[cpu];
79988- ret = local_read(&cpu_buffer->overrun);
79989+ ret = local_read_unchecked(&cpu_buffer->overrun);
79990
79991 return ret;
79992 }
79993@@ -3076,7 +3076,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
79994 return 0;
79995
79996 cpu_buffer = buffer->buffers[cpu];
79997- ret = local_read(&cpu_buffer->commit_overrun);
79998+ ret = local_read_unchecked(&cpu_buffer->commit_overrun);
79999
80000 return ret;
80001 }
80002@@ -3161,7 +3161,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
80003 /* if you care about this being correct, lock the buffer */
80004 for_each_buffer_cpu(buffer, cpu) {
80005 cpu_buffer = buffer->buffers[cpu];
80006- overruns += local_read(&cpu_buffer->overrun);
80007+ overruns += local_read_unchecked(&cpu_buffer->overrun);
80008 }
80009
80010 return overruns;
80011@@ -3337,8 +3337,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80012 /*
80013 * Reset the reader page to size zero.
80014 */
80015- local_set(&cpu_buffer->reader_page->write, 0);
80016- local_set(&cpu_buffer->reader_page->entries, 0);
80017+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80018+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80019 local_set(&cpu_buffer->reader_page->page->commit, 0);
80020 cpu_buffer->reader_page->real_end = 0;
80021
80022@@ -3372,7 +3372,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
80023 * want to compare with the last_overrun.
80024 */
80025 smp_mb();
80026- overwrite = local_read(&(cpu_buffer->overrun));
80027+ overwrite = local_read_unchecked(&(cpu_buffer->overrun));
80028
80029 /*
80030 * Here's the tricky part.
80031@@ -3942,8 +3942,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80032
80033 cpu_buffer->head_page
80034 = list_entry(cpu_buffer->pages, struct buffer_page, list);
80035- local_set(&cpu_buffer->head_page->write, 0);
80036- local_set(&cpu_buffer->head_page->entries, 0);
80037+ local_set_unchecked(&cpu_buffer->head_page->write, 0);
80038+ local_set_unchecked(&cpu_buffer->head_page->entries, 0);
80039 local_set(&cpu_buffer->head_page->page->commit, 0);
80040
80041 cpu_buffer->head_page->read = 0;
80042@@ -3953,14 +3953,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
80043
80044 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
80045 INIT_LIST_HEAD(&cpu_buffer->new_pages);
80046- local_set(&cpu_buffer->reader_page->write, 0);
80047- local_set(&cpu_buffer->reader_page->entries, 0);
80048+ local_set_unchecked(&cpu_buffer->reader_page->write, 0);
80049+ local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
80050 local_set(&cpu_buffer->reader_page->page->commit, 0);
80051 cpu_buffer->reader_page->read = 0;
80052
80053 local_set(&cpu_buffer->entries_bytes, 0);
80054- local_set(&cpu_buffer->overrun, 0);
80055- local_set(&cpu_buffer->commit_overrun, 0);
80056+ local_set_unchecked(&cpu_buffer->overrun, 0);
80057+ local_set_unchecked(&cpu_buffer->commit_overrun, 0);
80058 local_set(&cpu_buffer->dropped_events, 0);
80059 local_set(&cpu_buffer->entries, 0);
80060 local_set(&cpu_buffer->committing, 0);
80061@@ -4364,8 +4364,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
80062 rb_init_page(bpage);
80063 bpage = reader->page;
80064 reader->page = *data_page;
80065- local_set(&reader->write, 0);
80066- local_set(&reader->entries, 0);
80067+ local_set_unchecked(&reader->write, 0);
80068+ local_set_unchecked(&reader->entries, 0);
80069 reader->read = 0;
80070 *data_page = bpage;
80071
80072diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
80073index 3f28192..a29e8b0 100644
80074--- a/kernel/trace/trace.c
80075+++ b/kernel/trace/trace.c
80076@@ -2893,7 +2893,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
80077 return 0;
80078 }
80079
80080-int set_tracer_flag(unsigned int mask, int enabled)
80081+int set_tracer_flag(unsigned long mask, int enabled)
80082 {
80083 /* do nothing if flag is already set */
80084 if (!!(trace_flags & mask) == !!enabled)
80085@@ -4637,10 +4637,9 @@ static const struct file_operations tracing_dyn_info_fops = {
80086 };
80087 #endif
80088
80089-static struct dentry *d_tracer;
80090-
80091 struct dentry *tracing_init_dentry(void)
80092 {
80093+ static struct dentry *d_tracer;
80094 static int once;
80095
80096 if (d_tracer)
80097@@ -4660,10 +4659,9 @@ struct dentry *tracing_init_dentry(void)
80098 return d_tracer;
80099 }
80100
80101-static struct dentry *d_percpu;
80102-
80103 static struct dentry *tracing_dentry_percpu(void)
80104 {
80105+ static struct dentry *d_percpu;
80106 static int once;
80107 struct dentry *d_tracer;
80108
80109diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
80110index 2081971..09f861e 100644
80111--- a/kernel/trace/trace.h
80112+++ b/kernel/trace/trace.h
80113@@ -948,7 +948,7 @@ extern const char *__stop___trace_bprintk_fmt[];
80114 void trace_printk_init_buffers(void);
80115 void trace_printk_start_comm(void);
80116 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
80117-int set_tracer_flag(unsigned int mask, int enabled);
80118+int set_tracer_flag(unsigned long mask, int enabled);
80119
80120 #undef FTRACE_ENTRY
80121 #define FTRACE_ENTRY(call, struct_name, id, tstruct, print, filter) \
80122diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
80123index 57e9b28..eebe41c 100644
80124--- a/kernel/trace/trace_events.c
80125+++ b/kernel/trace/trace_events.c
80126@@ -1329,10 +1329,6 @@ static LIST_HEAD(ftrace_module_file_list);
80127 struct ftrace_module_file_ops {
80128 struct list_head list;
80129 struct module *mod;
80130- struct file_operations id;
80131- struct file_operations enable;
80132- struct file_operations format;
80133- struct file_operations filter;
80134 };
80135
80136 static struct ftrace_module_file_ops *
80137@@ -1353,17 +1349,12 @@ trace_create_file_ops(struct module *mod)
80138
80139 file_ops->mod = mod;
80140
80141- file_ops->id = ftrace_event_id_fops;
80142- file_ops->id.owner = mod;
80143-
80144- file_ops->enable = ftrace_enable_fops;
80145- file_ops->enable.owner = mod;
80146-
80147- file_ops->filter = ftrace_event_filter_fops;
80148- file_ops->filter.owner = mod;
80149-
80150- file_ops->format = ftrace_event_format_fops;
80151- file_ops->format.owner = mod;
80152+ pax_open_kernel();
80153+ mod->trace_id.owner = mod;
80154+ mod->trace_enable.owner = mod;
80155+ mod->trace_filter.owner = mod;
80156+ mod->trace_format.owner = mod;
80157+ pax_close_kernel();
80158
80159 list_add(&file_ops->list, &ftrace_module_file_list);
80160
80161@@ -1387,8 +1378,8 @@ static void trace_module_add_events(struct module *mod)
80162
80163 for_each_event(call, start, end) {
80164 __trace_add_event_call(*call, mod,
80165- &file_ops->id, &file_ops->enable,
80166- &file_ops->filter, &file_ops->format);
80167+ &mod->trace_id, &mod->trace_enable,
80168+ &mod->trace_filter, &mod->trace_format);
80169 }
80170 }
80171
80172diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
80173index fd3c8aa..5f324a6 100644
80174--- a/kernel/trace/trace_mmiotrace.c
80175+++ b/kernel/trace/trace_mmiotrace.c
80176@@ -24,7 +24,7 @@ struct header_iter {
80177 static struct trace_array *mmio_trace_array;
80178 static bool overrun_detected;
80179 static unsigned long prev_overruns;
80180-static atomic_t dropped_count;
80181+static atomic_unchecked_t dropped_count;
80182
80183 static void mmio_reset_data(struct trace_array *tr)
80184 {
80185@@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
80186
80187 static unsigned long count_overruns(struct trace_iterator *iter)
80188 {
80189- unsigned long cnt = atomic_xchg(&dropped_count, 0);
80190+ unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
80191 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
80192
80193 if (over > prev_overruns)
80194@@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
80195 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
80196 sizeof(*entry), 0, pc);
80197 if (!event) {
80198- atomic_inc(&dropped_count);
80199+ atomic_inc_unchecked(&dropped_count);
80200 return;
80201 }
80202 entry = ring_buffer_event_data(event);
80203@@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
80204 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
80205 sizeof(*entry), 0, pc);
80206 if (!event) {
80207- atomic_inc(&dropped_count);
80208+ atomic_inc_unchecked(&dropped_count);
80209 return;
80210 }
80211 entry = ring_buffer_event_data(event);
80212diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
80213index 697e88d..1a79993 100644
80214--- a/kernel/trace/trace_output.c
80215+++ b/kernel/trace/trace_output.c
80216@@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
80217
80218 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
80219 if (!IS_ERR(p)) {
80220- p = mangle_path(s->buffer + s->len, p, "\n");
80221+ p = mangle_path(s->buffer + s->len, p, "\n\\");
80222 if (p) {
80223 s->len = p - s->buffer;
80224 return 1;
80225@@ -851,14 +851,16 @@ int register_ftrace_event(struct trace_event *event)
80226 goto out;
80227 }
80228
80229+ pax_open_kernel();
80230 if (event->funcs->trace == NULL)
80231- event->funcs->trace = trace_nop_print;
80232+ *(void **)&event->funcs->trace = trace_nop_print;
80233 if (event->funcs->raw == NULL)
80234- event->funcs->raw = trace_nop_print;
80235+ *(void **)&event->funcs->raw = trace_nop_print;
80236 if (event->funcs->hex == NULL)
80237- event->funcs->hex = trace_nop_print;
80238+ *(void **)&event->funcs->hex = trace_nop_print;
80239 if (event->funcs->binary == NULL)
80240- event->funcs->binary = trace_nop_print;
80241+ *(void **)&event->funcs->binary = trace_nop_print;
80242+ pax_close_kernel();
80243
80244 key = event->type & (EVENT_HASHSIZE - 1);
80245
80246diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
80247index b20428c..4845a10 100644
80248--- a/kernel/trace/trace_stack.c
80249+++ b/kernel/trace/trace_stack.c
80250@@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
80251 return;
80252
80253 /* we do not handle interrupt stacks yet */
80254- if (!object_is_on_stack(stack))
80255+ if (!object_starts_on_stack(stack))
80256 return;
80257
80258 local_irq_save(flags);
80259diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
80260index e134d8f..a018cdd 100644
80261--- a/kernel/user_namespace.c
80262+++ b/kernel/user_namespace.c
80263@@ -853,7 +853,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
80264 if (atomic_read(&current->mm->mm_users) > 1)
80265 return -EINVAL;
80266
80267- if (current->fs->users != 1)
80268+ if (atomic_read(&current->fs->users) != 1)
80269 return -EINVAL;
80270
80271 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
80272diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
80273index 4f69f9a..7c6f8f8 100644
80274--- a/kernel/utsname_sysctl.c
80275+++ b/kernel/utsname_sysctl.c
80276@@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
80277 static int proc_do_uts_string(ctl_table *table, int write,
80278 void __user *buffer, size_t *lenp, loff_t *ppos)
80279 {
80280- struct ctl_table uts_table;
80281+ ctl_table_no_const uts_table;
80282 int r;
80283 memcpy(&uts_table, table, sizeof(uts_table));
80284 uts_table.data = get_uts(table, write);
80285diff --git a/kernel/watchdog.c b/kernel/watchdog.c
80286index 4a94467..80a6f9c 100644
80287--- a/kernel/watchdog.c
80288+++ b/kernel/watchdog.c
80289@@ -526,7 +526,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
80290 }
80291 #endif /* CONFIG_SYSCTL */
80292
80293-static struct smp_hotplug_thread watchdog_threads = {
80294+static struct smp_hotplug_thread watchdog_threads __read_only = {
80295 .store = &softlockup_watchdog,
80296 .thread_should_run = watchdog_should_run,
80297 .thread_fn = watchdog,
80298diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
80299index 28be08c..47bab92 100644
80300--- a/lib/Kconfig.debug
80301+++ b/lib/Kconfig.debug
80302@@ -549,7 +549,7 @@ config DEBUG_MUTEXES
80303
80304 config DEBUG_LOCK_ALLOC
80305 bool "Lock debugging: detect incorrect freeing of live locks"
80306- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80307+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80308 select DEBUG_SPINLOCK
80309 select DEBUG_MUTEXES
80310 select LOCKDEP
80311@@ -563,7 +563,7 @@ config DEBUG_LOCK_ALLOC
80312
80313 config PROVE_LOCKING
80314 bool "Lock debugging: prove locking correctness"
80315- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80316+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80317 select LOCKDEP
80318 select DEBUG_SPINLOCK
80319 select DEBUG_MUTEXES
80320@@ -614,7 +614,7 @@ config LOCKDEP
80321
80322 config LOCK_STAT
80323 bool "Lock usage statistics"
80324- depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
80325+ depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
80326 select LOCKDEP
80327 select DEBUG_SPINLOCK
80328 select DEBUG_MUTEXES
80329@@ -1282,6 +1282,7 @@ config LATENCYTOP
80330 depends on DEBUG_KERNEL
80331 depends on STACKTRACE_SUPPORT
80332 depends on PROC_FS
80333+ depends on !GRKERNSEC_HIDESYM
80334 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
80335 select KALLSYMS
80336 select KALLSYMS_ALL
80337@@ -1310,7 +1311,7 @@ config INTERVAL_TREE_TEST
80338
80339 config PROVIDE_OHCI1394_DMA_INIT
80340 bool "Remote debugging over FireWire early on boot"
80341- depends on PCI && X86
80342+ depends on PCI && X86 && !GRKERNSEC
80343 help
80344 If you want to debug problems which hang or crash the kernel early
80345 on boot and the crashing machine has a FireWire port, you can use
80346@@ -1339,7 +1340,7 @@ config PROVIDE_OHCI1394_DMA_INIT
80347
80348 config FIREWIRE_OHCI_REMOTE_DMA
80349 bool "Remote debugging over FireWire with firewire-ohci"
80350- depends on FIREWIRE_OHCI
80351+ depends on FIREWIRE_OHCI && !GRKERNSEC
80352 help
80353 This option lets you use the FireWire bus for remote debugging
80354 with help of the firewire-ohci driver. It enables unfiltered
80355diff --git a/lib/Makefile b/lib/Makefile
80356index 6e2cc56..9b13738 100644
80357--- a/lib/Makefile
80358+++ b/lib/Makefile
80359@@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
80360
80361 obj-$(CONFIG_BTREE) += btree.o
80362 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
80363-obj-$(CONFIG_DEBUG_LIST) += list_debug.o
80364+obj-y += list_debug.o
80365 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
80366
80367 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
80368diff --git a/lib/bitmap.c b/lib/bitmap.c
80369index 06f7e4f..f3cf2b0 100644
80370--- a/lib/bitmap.c
80371+++ b/lib/bitmap.c
80372@@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
80373 {
80374 int c, old_c, totaldigits, ndigits, nchunks, nbits;
80375 u32 chunk;
80376- const char __user __force *ubuf = (const char __user __force *)buf;
80377+ const char __user *ubuf = (const char __force_user *)buf;
80378
80379 bitmap_zero(maskp, nmaskbits);
80380
80381@@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
80382 {
80383 if (!access_ok(VERIFY_READ, ubuf, ulen))
80384 return -EFAULT;
80385- return __bitmap_parse((const char __force *)ubuf,
80386+ return __bitmap_parse((const char __force_kernel *)ubuf,
80387 ulen, 1, maskp, nmaskbits);
80388
80389 }
80390@@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
80391 {
80392 unsigned a, b;
80393 int c, old_c, totaldigits;
80394- const char __user __force *ubuf = (const char __user __force *)buf;
80395+ const char __user *ubuf = (const char __force_user *)buf;
80396 int exp_digit, in_range;
80397
80398 totaldigits = c = 0;
80399@@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
80400 {
80401 if (!access_ok(VERIFY_READ, ubuf, ulen))
80402 return -EFAULT;
80403- return __bitmap_parselist((const char __force *)ubuf,
80404+ return __bitmap_parselist((const char __force_kernel *)ubuf,
80405 ulen, 1, maskp, nmaskbits);
80406 }
80407 EXPORT_SYMBOL(bitmap_parselist_user);
80408diff --git a/lib/bug.c b/lib/bug.c
80409index 1686034..a9c00c8 100644
80410--- a/lib/bug.c
80411+++ b/lib/bug.c
80412@@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
80413 return BUG_TRAP_TYPE_NONE;
80414
80415 bug = find_bug(bugaddr);
80416+ if (!bug)
80417+ return BUG_TRAP_TYPE_NONE;
80418
80419 file = NULL;
80420 line = 0;
80421diff --git a/lib/debugobjects.c b/lib/debugobjects.c
80422index 37061ed..da83f48 100644
80423--- a/lib/debugobjects.c
80424+++ b/lib/debugobjects.c
80425@@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
80426 if (limit > 4)
80427 return;
80428
80429- is_on_stack = object_is_on_stack(addr);
80430+ is_on_stack = object_starts_on_stack(addr);
80431 if (is_on_stack == onstack)
80432 return;
80433
80434diff --git a/lib/devres.c b/lib/devres.c
80435index 8235331..5881053 100644
80436--- a/lib/devres.c
80437+++ b/lib/devres.c
80438@@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
80439 void devm_iounmap(struct device *dev, void __iomem *addr)
80440 {
80441 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
80442- (void *)addr));
80443+ (void __force *)addr));
80444 iounmap(addr);
80445 }
80446 EXPORT_SYMBOL(devm_iounmap);
80447@@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
80448 {
80449 ioport_unmap(addr);
80450 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
80451- devm_ioport_map_match, (void *)addr));
80452+ devm_ioport_map_match, (void __force *)addr));
80453 }
80454 EXPORT_SYMBOL(devm_ioport_unmap);
80455 #endif /* CONFIG_HAS_IOPORT */
80456diff --git a/lib/div64.c b/lib/div64.c
80457index a163b6c..9618fa5 100644
80458--- a/lib/div64.c
80459+++ b/lib/div64.c
80460@@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
80461 EXPORT_SYMBOL(__div64_32);
80462
80463 #ifndef div_s64_rem
80464-s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80465+s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
80466 {
80467 u64 quotient;
80468
80469@@ -90,7 +90,7 @@ EXPORT_SYMBOL(div_s64_rem);
80470 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
80471 */
80472 #ifndef div64_u64
80473-u64 div64_u64(u64 dividend, u64 divisor)
80474+u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80475 {
80476 u32 high = divisor >> 32;
80477 u64 quot;
80478diff --git a/lib/dma-debug.c b/lib/dma-debug.c
80479index d87a17a..ac0d79a 100644
80480--- a/lib/dma-debug.c
80481+++ b/lib/dma-debug.c
80482@@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
80483
80484 void dma_debug_add_bus(struct bus_type *bus)
80485 {
80486- struct notifier_block *nb;
80487+ notifier_block_no_const *nb;
80488
80489 if (global_disable)
80490 return;
80491@@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
80492
80493 static void check_for_stack(struct device *dev, void *addr)
80494 {
80495- if (object_is_on_stack(addr))
80496+ if (object_starts_on_stack(addr))
80497 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
80498 "stack [addr=%p]\n", addr);
80499 }
80500diff --git a/lib/inflate.c b/lib/inflate.c
80501index 013a761..c28f3fc 100644
80502--- a/lib/inflate.c
80503+++ b/lib/inflate.c
80504@@ -269,7 +269,7 @@ static void free(void *where)
80505 malloc_ptr = free_mem_ptr;
80506 }
80507 #else
80508-#define malloc(a) kmalloc(a, GFP_KERNEL)
80509+#define malloc(a) kmalloc((a), GFP_KERNEL)
80510 #define free(a) kfree(a)
80511 #endif
80512
80513diff --git a/lib/ioremap.c b/lib/ioremap.c
80514index 0c9216c..863bd89 100644
80515--- a/lib/ioremap.c
80516+++ b/lib/ioremap.c
80517@@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
80518 unsigned long next;
80519
80520 phys_addr -= addr;
80521- pmd = pmd_alloc(&init_mm, pud, addr);
80522+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
80523 if (!pmd)
80524 return -ENOMEM;
80525 do {
80526@@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
80527 unsigned long next;
80528
80529 phys_addr -= addr;
80530- pud = pud_alloc(&init_mm, pgd, addr);
80531+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
80532 if (!pud)
80533 return -ENOMEM;
80534 do {
80535diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
80536index bd2bea9..6b3c95e 100644
80537--- a/lib/is_single_threaded.c
80538+++ b/lib/is_single_threaded.c
80539@@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
80540 struct task_struct *p, *t;
80541 bool ret;
80542
80543+ if (!mm)
80544+ return true;
80545+
80546 if (atomic_read(&task->signal->live) != 1)
80547 return false;
80548
80549diff --git a/lib/kobject.c b/lib/kobject.c
80550index a654866..d8bb115 100644
80551--- a/lib/kobject.c
80552+++ b/lib/kobject.c
80553@@ -805,7 +805,7 @@ static struct kset *kset_create(const char *name,
80554 kset = kzalloc(sizeof(*kset), GFP_KERNEL);
80555 if (!kset)
80556 return NULL;
80557- retval = kobject_set_name(&kset->kobj, name);
80558+ retval = kobject_set_name(&kset->kobj, "%s", name);
80559 if (retval) {
80560 kfree(kset);
80561 return NULL;
80562@@ -859,9 +859,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
80563
80564
80565 static DEFINE_SPINLOCK(kobj_ns_type_lock);
80566-static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
80567+static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
80568
80569-int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80570+int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
80571 {
80572 enum kobj_ns_type type = ops->type;
80573 int error;
80574diff --git a/lib/list_debug.c b/lib/list_debug.c
80575index c24c2f7..06e070b 100644
80576--- a/lib/list_debug.c
80577+++ b/lib/list_debug.c
80578@@ -11,7 +11,9 @@
80579 #include <linux/bug.h>
80580 #include <linux/kernel.h>
80581 #include <linux/rculist.h>
80582+#include <linux/mm.h>
80583
80584+#ifdef CONFIG_DEBUG_LIST
80585 /*
80586 * Insert a new entry between two known consecutive entries.
80587 *
80588@@ -19,21 +21,32 @@
80589 * the prev/next entries already!
80590 */
80591
80592-void __list_add(struct list_head *new,
80593- struct list_head *prev,
80594- struct list_head *next)
80595+static bool __list_add_debug(struct list_head *new,
80596+ struct list_head *prev,
80597+ struct list_head *next)
80598 {
80599- WARN(next->prev != prev,
80600+ if (WARN(next->prev != prev,
80601 "list_add corruption. next->prev should be "
80602 "prev (%p), but was %p. (next=%p).\n",
80603- prev, next->prev, next);
80604- WARN(prev->next != next,
80605+ prev, next->prev, next) ||
80606+ WARN(prev->next != next,
80607 "list_add corruption. prev->next should be "
80608 "next (%p), but was %p. (prev=%p).\n",
80609- next, prev->next, prev);
80610- WARN(new == prev || new == next,
80611- "list_add double add: new=%p, prev=%p, next=%p.\n",
80612- new, prev, next);
80613+ next, prev->next, prev) ||
80614+ WARN(new == prev || new == next,
80615+ "list_add double add: new=%p, prev=%p, next=%p.\n",
80616+ new, prev, next))
80617+ return false;
80618+ return true;
80619+}
80620+
80621+void __list_add(struct list_head *new,
80622+ struct list_head *prev,
80623+ struct list_head *next)
80624+{
80625+ if (!__list_add_debug(new, prev, next))
80626+ return;
80627+
80628 next->prev = new;
80629 new->next = next;
80630 new->prev = prev;
80631@@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
80632 }
80633 EXPORT_SYMBOL(__list_add);
80634
80635-void __list_del_entry(struct list_head *entry)
80636+static bool __list_del_entry_debug(struct list_head *entry)
80637 {
80638 struct list_head *prev, *next;
80639
80640@@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
80641 WARN(next->prev != entry,
80642 "list_del corruption. next->prev should be %p, "
80643 "but was %p\n", entry, next->prev))
80644+ return false;
80645+ return true;
80646+}
80647+
80648+void __list_del_entry(struct list_head *entry)
80649+{
80650+ if (!__list_del_entry_debug(entry))
80651 return;
80652
80653- __list_del(prev, next);
80654+ __list_del(entry->prev, entry->next);
80655 }
80656 EXPORT_SYMBOL(__list_del_entry);
80657
80658@@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
80659 void __list_add_rcu(struct list_head *new,
80660 struct list_head *prev, struct list_head *next)
80661 {
80662- WARN(next->prev != prev,
80663- "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
80664- prev, next->prev, next);
80665- WARN(prev->next != next,
80666- "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
80667- next, prev->next, prev);
80668+ if (!__list_add_debug(new, prev, next))
80669+ return;
80670+
80671 new->next = next;
80672 new->prev = prev;
80673 rcu_assign_pointer(list_next_rcu(prev), new);
80674 next->prev = new;
80675 }
80676 EXPORT_SYMBOL(__list_add_rcu);
80677+#endif
80678+
80679+void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
80680+{
80681+#ifdef CONFIG_DEBUG_LIST
80682+ if (!__list_add_debug(new, prev, next))
80683+ return;
80684+#endif
80685+
80686+ pax_open_kernel();
80687+ next->prev = new;
80688+ new->next = next;
80689+ new->prev = prev;
80690+ prev->next = new;
80691+ pax_close_kernel();
80692+}
80693+EXPORT_SYMBOL(__pax_list_add);
80694+
80695+void pax_list_del(struct list_head *entry)
80696+{
80697+#ifdef CONFIG_DEBUG_LIST
80698+ if (!__list_del_entry_debug(entry))
80699+ return;
80700+#endif
80701+
80702+ pax_open_kernel();
80703+ __list_del(entry->prev, entry->next);
80704+ entry->next = LIST_POISON1;
80705+ entry->prev = LIST_POISON2;
80706+ pax_close_kernel();
80707+}
80708+EXPORT_SYMBOL(pax_list_del);
80709+
80710+void pax_list_del_init(struct list_head *entry)
80711+{
80712+ pax_open_kernel();
80713+ __list_del(entry->prev, entry->next);
80714+ INIT_LIST_HEAD(entry);
80715+ pax_close_kernel();
80716+}
80717+EXPORT_SYMBOL(pax_list_del_init);
80718+
80719+void __pax_list_add_rcu(struct list_head *new,
80720+ struct list_head *prev, struct list_head *next)
80721+{
80722+#ifdef CONFIG_DEBUG_LIST
80723+ if (!__list_add_debug(new, prev, next))
80724+ return;
80725+#endif
80726+
80727+ pax_open_kernel();
80728+ new->next = next;
80729+ new->prev = prev;
80730+ rcu_assign_pointer(list_next_rcu(prev), new);
80731+ next->prev = new;
80732+ pax_close_kernel();
80733+}
80734+EXPORT_SYMBOL(__pax_list_add_rcu);
80735+
80736+void pax_list_del_rcu(struct list_head *entry)
80737+{
80738+#ifdef CONFIG_DEBUG_LIST
80739+ if (!__list_del_entry_debug(entry))
80740+ return;
80741+#endif
80742+
80743+ pax_open_kernel();
80744+ __list_del(entry->prev, entry->next);
80745+ entry->next = LIST_POISON1;
80746+ entry->prev = LIST_POISON2;
80747+ pax_close_kernel();
80748+}
80749+EXPORT_SYMBOL(pax_list_del_rcu);
80750diff --git a/lib/radix-tree.c b/lib/radix-tree.c
80751index e796429..6e38f9f 100644
80752--- a/lib/radix-tree.c
80753+++ b/lib/radix-tree.c
80754@@ -92,7 +92,7 @@ struct radix_tree_preload {
80755 int nr;
80756 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
80757 };
80758-static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
80759+static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
80760
80761 static inline void *ptr_to_indirect(void *ptr)
80762 {
80763diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
80764index bb2b201..46abaf9 100644
80765--- a/lib/strncpy_from_user.c
80766+++ b/lib/strncpy_from_user.c
80767@@ -21,7 +21,7 @@
80768 */
80769 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
80770 {
80771- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80772+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80773 long res = 0;
80774
80775 /*
80776diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
80777index a28df52..3d55877 100644
80778--- a/lib/strnlen_user.c
80779+++ b/lib/strnlen_user.c
80780@@ -26,7 +26,7 @@
80781 */
80782 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
80783 {
80784- const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80785+ static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
80786 long align, res = 0;
80787 unsigned long c;
80788
80789diff --git a/lib/swiotlb.c b/lib/swiotlb.c
80790index d23762e..e21eab2 100644
80791--- a/lib/swiotlb.c
80792+++ b/lib/swiotlb.c
80793@@ -664,7 +664,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
80794
80795 void
80796 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
80797- dma_addr_t dev_addr)
80798+ dma_addr_t dev_addr, struct dma_attrs *attrs)
80799 {
80800 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
80801
80802diff --git a/lib/vsprintf.c b/lib/vsprintf.c
80803index 0d62fd7..b7bc911 100644
80804--- a/lib/vsprintf.c
80805+++ b/lib/vsprintf.c
80806@@ -16,6 +16,9 @@
80807 * - scnprintf and vscnprintf
80808 */
80809
80810+#ifdef CONFIG_GRKERNSEC_HIDESYM
80811+#define __INCLUDED_BY_HIDESYM 1
80812+#endif
80813 #include <stdarg.h>
80814 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
80815 #include <linux/types.h>
80816@@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
80817 return number(buf, end, *(const netdev_features_t *)addr, spec);
80818 }
80819
80820+#ifdef CONFIG_GRKERNSEC_HIDESYM
80821+int kptr_restrict __read_mostly = 2;
80822+#else
80823 int kptr_restrict __read_mostly;
80824+#endif
80825
80826 /*
80827 * Show a '%p' thing. A kernel extension is that the '%p' is followed
80828@@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
80829 * - 'S' For symbolic direct pointers with offset
80830 * - 's' For symbolic direct pointers without offset
80831 * - 'B' For backtraced symbolic direct pointers with offset
80832+ * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
80833+ * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
80834 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
80835 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
80836 * - 'M' For a 6-byte MAC address, it prints the address in the
80837@@ -1044,12 +1053,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80838
80839 if (!ptr && *fmt != 'K') {
80840 /*
80841- * Print (null) with the same width as a pointer so it makes
80842+ * Print (nil) with the same width as a pointer so it makes
80843 * tabular output look nice.
80844 */
80845 if (spec.field_width == -1)
80846 spec.field_width = default_width;
80847- return string(buf, end, "(null)", spec);
80848+ return string(buf, end, "(nil)", spec);
80849 }
80850
80851 switch (*fmt) {
80852@@ -1059,6 +1068,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80853 /* Fallthrough */
80854 case 'S':
80855 case 's':
80856+#ifdef CONFIG_GRKERNSEC_HIDESYM
80857+ break;
80858+#else
80859+ return symbol_string(buf, end, ptr, spec, *fmt);
80860+#endif
80861+ case 'A':
80862 case 'B':
80863 return symbol_string(buf, end, ptr, spec, *fmt);
80864 case 'R':
80865@@ -1099,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80866 va_end(va);
80867 return buf;
80868 }
80869+ case 'P':
80870+ break;
80871 case 'K':
80872 /*
80873 * %pK cannot be used in IRQ context because its test
80874@@ -1128,6 +1145,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
80875 return number(buf, end,
80876 (unsigned long long) *((phys_addr_t *)ptr), spec);
80877 }
80878+
80879+#ifdef CONFIG_GRKERNSEC_HIDESYM
80880+ /* 'P' = approved pointers to copy to userland,
80881+ as in the /proc/kallsyms case, as we make it display nothing
80882+ for non-root users, and the real contents for root users
80883+ Also ignore 'K' pointers, since we force their NULLing for non-root users
80884+ above
80885+ */
80886+ if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
80887+ printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
80888+ dump_stack();
80889+ ptr = NULL;
80890+ }
80891+#endif
80892+
80893 spec.flags |= SMALL;
80894 if (spec.field_width == -1) {
80895 spec.field_width = default_width;
80896@@ -1849,11 +1881,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80897 typeof(type) value; \
80898 if (sizeof(type) == 8) { \
80899 args = PTR_ALIGN(args, sizeof(u32)); \
80900- *(u32 *)&value = *(u32 *)args; \
80901- *((u32 *)&value + 1) = *(u32 *)(args + 4); \
80902+ *(u32 *)&value = *(const u32 *)args; \
80903+ *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
80904 } else { \
80905 args = PTR_ALIGN(args, sizeof(type)); \
80906- value = *(typeof(type) *)args; \
80907+ value = *(const typeof(type) *)args; \
80908 } \
80909 args += sizeof(type); \
80910 value; \
80911@@ -1916,7 +1948,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
80912 case FORMAT_TYPE_STR: {
80913 const char *str_arg = args;
80914 args += strlen(str_arg) + 1;
80915- str = string(str, end, (char *)str_arg, spec);
80916+ str = string(str, end, str_arg, spec);
80917 break;
80918 }
80919
80920diff --git a/localversion-grsec b/localversion-grsec
80921new file mode 100644
80922index 0000000..7cd6065
80923--- /dev/null
80924+++ b/localversion-grsec
80925@@ -0,0 +1 @@
80926+-grsec
80927diff --git a/mm/Kconfig b/mm/Kconfig
80928index 3bea74f..e821c99 100644
80929--- a/mm/Kconfig
80930+++ b/mm/Kconfig
80931@@ -311,10 +311,10 @@ config KSM
80932 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
80933
80934 config DEFAULT_MMAP_MIN_ADDR
80935- int "Low address space to protect from user allocation"
80936+ int "Low address space to protect from user allocation"
80937 depends on MMU
80938- default 4096
80939- help
80940+ default 65536
80941+ help
80942 This is the portion of low virtual memory which should be protected
80943 from userspace allocation. Keeping a user from writing to low pages
80944 can help reduce the impact of kernel NULL pointer bugs.
80945@@ -345,7 +345,7 @@ config MEMORY_FAILURE
80946
80947 config HWPOISON_INJECT
80948 tristate "HWPoison pages injector"
80949- depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
80950+ depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
80951 select PROC_PAGE_MONITOR
80952
80953 config NOMMU_INITIAL_TRIM_EXCESS
80954diff --git a/mm/backing-dev.c b/mm/backing-dev.c
80955index 41733c5..d80d7a9 100644
80956--- a/mm/backing-dev.c
80957+++ b/mm/backing-dev.c
80958@@ -716,7 +716,6 @@ EXPORT_SYMBOL(bdi_destroy);
80959 int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
80960 unsigned int cap)
80961 {
80962- char tmp[32];
80963 int err;
80964
80965 bdi->name = name;
80966@@ -725,8 +724,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
80967 if (err)
80968 return err;
80969
80970- sprintf(tmp, "%.28s%s", name, "-%d");
80971- err = bdi_register(bdi, NULL, tmp, atomic_long_inc_return(&bdi_seq));
80972+ err = bdi_register(bdi, NULL, "%.28s-%ld", name, atomic_long_inc_return(&bdi_seq));
80973 if (err) {
80974 bdi_destroy(bdi);
80975 return err;
80976diff --git a/mm/filemap.c b/mm/filemap.c
80977index e1979fd..dda5120 100644
80978--- a/mm/filemap.c
80979+++ b/mm/filemap.c
80980@@ -1748,7 +1748,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
80981 struct address_space *mapping = file->f_mapping;
80982
80983 if (!mapping->a_ops->readpage)
80984- return -ENOEXEC;
80985+ return -ENODEV;
80986 file_accessed(file);
80987 vma->vm_ops = &generic_file_vm_ops;
80988 return 0;
80989@@ -2088,6 +2088,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
80990 *pos = i_size_read(inode);
80991
80992 if (limit != RLIM_INFINITY) {
80993+ gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
80994 if (*pos >= limit) {
80995 send_sig(SIGXFSZ, current, 0);
80996 return -EFBIG;
80997diff --git a/mm/fremap.c b/mm/fremap.c
80998index 87da359..3f41cb1 100644
80999--- a/mm/fremap.c
81000+++ b/mm/fremap.c
81001@@ -158,6 +158,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
81002 retry:
81003 vma = find_vma(mm, start);
81004
81005+#ifdef CONFIG_PAX_SEGMEXEC
81006+ if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
81007+ goto out;
81008+#endif
81009+
81010 /*
81011 * Make sure the vma is shared, that it supports prefaulting,
81012 * and that the remapped range is valid and fully within
81013diff --git a/mm/highmem.c b/mm/highmem.c
81014index b32b70c..e512eb0 100644
81015--- a/mm/highmem.c
81016+++ b/mm/highmem.c
81017@@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
81018 * So no dangers, even with speculative execution.
81019 */
81020 page = pte_page(pkmap_page_table[i]);
81021+ pax_open_kernel();
81022 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
81023-
81024+ pax_close_kernel();
81025 set_page_address(page, NULL);
81026 need_flush = 1;
81027 }
81028@@ -198,9 +199,11 @@ start:
81029 }
81030 }
81031 vaddr = PKMAP_ADDR(last_pkmap_nr);
81032+
81033+ pax_open_kernel();
81034 set_pte_at(&init_mm, vaddr,
81035 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
81036-
81037+ pax_close_kernel();
81038 pkmap_count[last_pkmap_nr] = 1;
81039 set_page_address(page, (void *)vaddr);
81040
81041diff --git a/mm/hugetlb.c b/mm/hugetlb.c
81042index ce4cb19..93899ef 100644
81043--- a/mm/hugetlb.c
81044+++ b/mm/hugetlb.c
81045@@ -2005,15 +2005,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
81046 struct hstate *h = &default_hstate;
81047 unsigned long tmp;
81048 int ret;
81049+ ctl_table_no_const hugetlb_table;
81050
81051 tmp = h->max_huge_pages;
81052
81053 if (write && h->order >= MAX_ORDER)
81054 return -EINVAL;
81055
81056- table->data = &tmp;
81057- table->maxlen = sizeof(unsigned long);
81058- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81059+ hugetlb_table = *table;
81060+ hugetlb_table.data = &tmp;
81061+ hugetlb_table.maxlen = sizeof(unsigned long);
81062+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81063 if (ret)
81064 goto out;
81065
81066@@ -2070,15 +2072,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
81067 struct hstate *h = &default_hstate;
81068 unsigned long tmp;
81069 int ret;
81070+ ctl_table_no_const hugetlb_table;
81071
81072 tmp = h->nr_overcommit_huge_pages;
81073
81074 if (write && h->order >= MAX_ORDER)
81075 return -EINVAL;
81076
81077- table->data = &tmp;
81078- table->maxlen = sizeof(unsigned long);
81079- ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
81080+ hugetlb_table = *table;
81081+ hugetlb_table.data = &tmp;
81082+ hugetlb_table.maxlen = sizeof(unsigned long);
81083+ ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
81084 if (ret)
81085 goto out;
81086
81087@@ -2512,6 +2516,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
81088 return 1;
81089 }
81090
81091+#ifdef CONFIG_PAX_SEGMEXEC
81092+static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
81093+{
81094+ struct mm_struct *mm = vma->vm_mm;
81095+ struct vm_area_struct *vma_m;
81096+ unsigned long address_m;
81097+ pte_t *ptep_m;
81098+
81099+ vma_m = pax_find_mirror_vma(vma);
81100+ if (!vma_m)
81101+ return;
81102+
81103+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81104+ address_m = address + SEGMEXEC_TASK_SIZE;
81105+ ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
81106+ get_page(page_m);
81107+ hugepage_add_anon_rmap(page_m, vma_m, address_m);
81108+ set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
81109+}
81110+#endif
81111+
81112 /*
81113 * Hugetlb_cow() should be called with page lock of the original hugepage held.
81114 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
81115@@ -2630,6 +2655,11 @@ retry_avoidcopy:
81116 make_huge_pte(vma, new_page, 1));
81117 page_remove_rmap(old_page);
81118 hugepage_add_new_anon_rmap(new_page, vma, address);
81119+
81120+#ifdef CONFIG_PAX_SEGMEXEC
81121+ pax_mirror_huge_pte(vma, address, new_page);
81122+#endif
81123+
81124 /* Make the old page be freed below */
81125 new_page = old_page;
81126 }
81127@@ -2788,6 +2818,10 @@ retry:
81128 && (vma->vm_flags & VM_SHARED)));
81129 set_huge_pte_at(mm, address, ptep, new_pte);
81130
81131+#ifdef CONFIG_PAX_SEGMEXEC
81132+ pax_mirror_huge_pte(vma, address, page);
81133+#endif
81134+
81135 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
81136 /* Optimization, do the COW without a second fault */
81137 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
81138@@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81139 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
81140 struct hstate *h = hstate_vma(vma);
81141
81142+#ifdef CONFIG_PAX_SEGMEXEC
81143+ struct vm_area_struct *vma_m;
81144+#endif
81145+
81146 address &= huge_page_mask(h);
81147
81148 ptep = huge_pte_offset(mm, address);
81149@@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81150 VM_FAULT_SET_HINDEX(hstate_index(h));
81151 }
81152
81153+#ifdef CONFIG_PAX_SEGMEXEC
81154+ vma_m = pax_find_mirror_vma(vma);
81155+ if (vma_m) {
81156+ unsigned long address_m;
81157+
81158+ if (vma->vm_start > vma_m->vm_start) {
81159+ address_m = address;
81160+ address -= SEGMEXEC_TASK_SIZE;
81161+ vma = vma_m;
81162+ h = hstate_vma(vma);
81163+ } else
81164+ address_m = address + SEGMEXEC_TASK_SIZE;
81165+
81166+ if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
81167+ return VM_FAULT_OOM;
81168+ address_m &= HPAGE_MASK;
81169+ unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
81170+ }
81171+#endif
81172+
81173 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
81174 if (!ptep)
81175 return VM_FAULT_OOM;
81176diff --git a/mm/internal.h b/mm/internal.h
81177index 8562de0..7fdfe92 100644
81178--- a/mm/internal.h
81179+++ b/mm/internal.h
81180@@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
81181 * in mm/page_alloc.c
81182 */
81183 extern void __free_pages_bootmem(struct page *page, unsigned int order);
81184+extern void free_compound_page(struct page *page);
81185 extern void prep_compound_page(struct page *page, unsigned long order);
81186 #ifdef CONFIG_MEMORY_FAILURE
81187 extern bool is_free_buddy_page(struct page *page);
81188diff --git a/mm/kmemleak.c b/mm/kmemleak.c
81189index c8d7f31..2dbeffd 100644
81190--- a/mm/kmemleak.c
81191+++ b/mm/kmemleak.c
81192@@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
81193
81194 for (i = 0; i < object->trace_len; i++) {
81195 void *ptr = (void *)object->trace[i];
81196- seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
81197+ seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
81198 }
81199 }
81200
81201@@ -1851,7 +1851,7 @@ static int __init kmemleak_late_init(void)
81202 return -ENOMEM;
81203 }
81204
81205- dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
81206+ dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
81207 &kmemleak_fops);
81208 if (!dentry)
81209 pr_warning("Failed to create the debugfs kmemleak file\n");
81210diff --git a/mm/maccess.c b/mm/maccess.c
81211index d53adf9..03a24bf 100644
81212--- a/mm/maccess.c
81213+++ b/mm/maccess.c
81214@@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
81215 set_fs(KERNEL_DS);
81216 pagefault_disable();
81217 ret = __copy_from_user_inatomic(dst,
81218- (__force const void __user *)src, size);
81219+ (const void __force_user *)src, size);
81220 pagefault_enable();
81221 set_fs(old_fs);
81222
81223@@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
81224
81225 set_fs(KERNEL_DS);
81226 pagefault_disable();
81227- ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
81228+ ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
81229 pagefault_enable();
81230 set_fs(old_fs);
81231
81232diff --git a/mm/madvise.c b/mm/madvise.c
81233index c58c94b..86ec14e 100644
81234--- a/mm/madvise.c
81235+++ b/mm/madvise.c
81236@@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
81237 pgoff_t pgoff;
81238 unsigned long new_flags = vma->vm_flags;
81239
81240+#ifdef CONFIG_PAX_SEGMEXEC
81241+ struct vm_area_struct *vma_m;
81242+#endif
81243+
81244 switch (behavior) {
81245 case MADV_NORMAL:
81246 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
81247@@ -126,6 +130,13 @@ success:
81248 /*
81249 * vm_flags is protected by the mmap_sem held in write mode.
81250 */
81251+
81252+#ifdef CONFIG_PAX_SEGMEXEC
81253+ vma_m = pax_find_mirror_vma(vma);
81254+ if (vma_m)
81255+ vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
81256+#endif
81257+
81258 vma->vm_flags = new_flags;
81259
81260 out:
81261@@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81262 struct vm_area_struct ** prev,
81263 unsigned long start, unsigned long end)
81264 {
81265+
81266+#ifdef CONFIG_PAX_SEGMEXEC
81267+ struct vm_area_struct *vma_m;
81268+#endif
81269+
81270 *prev = vma;
81271 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
81272 return -EINVAL;
81273@@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
81274 zap_page_range(vma, start, end - start, &details);
81275 } else
81276 zap_page_range(vma, start, end - start, NULL);
81277+
81278+#ifdef CONFIG_PAX_SEGMEXEC
81279+ vma_m = pax_find_mirror_vma(vma);
81280+ if (vma_m) {
81281+ if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
81282+ struct zap_details details = {
81283+ .nonlinear_vma = vma_m,
81284+ .last_index = ULONG_MAX,
81285+ };
81286+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
81287+ } else
81288+ zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
81289+ }
81290+#endif
81291+
81292 return 0;
81293 }
81294
81295@@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
81296 if (end < start)
81297 goto out;
81298
81299+#ifdef CONFIG_PAX_SEGMEXEC
81300+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81301+ if (end > SEGMEXEC_TASK_SIZE)
81302+ goto out;
81303+ } else
81304+#endif
81305+
81306+ if (end > TASK_SIZE)
81307+ goto out;
81308+
81309 error = 0;
81310 if (end == start)
81311 goto out;
81312diff --git a/mm/memory-failure.c b/mm/memory-failure.c
81313index df0694c..bc95539 100644
81314--- a/mm/memory-failure.c
81315+++ b/mm/memory-failure.c
81316@@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
81317
81318 int sysctl_memory_failure_recovery __read_mostly = 1;
81319
81320-atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81321+atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
81322
81323 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
81324
81325@@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
81326 pfn, t->comm, t->pid);
81327 si.si_signo = SIGBUS;
81328 si.si_errno = 0;
81329- si.si_addr = (void *)addr;
81330+ si.si_addr = (void __user *)addr;
81331 #ifdef __ARCH_SI_TRAPNO
81332 si.si_trapno = trapno;
81333 #endif
81334@@ -760,7 +760,7 @@ static struct page_state {
81335 unsigned long res;
81336 char *msg;
81337 int (*action)(struct page *p, unsigned long pfn);
81338-} error_states[] = {
81339+} __do_const error_states[] = {
81340 { reserved, reserved, "reserved kernel", me_kernel },
81341 /*
81342 * free pages are specially detected outside this table:
81343@@ -1051,7 +1051,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81344 nr_pages = 1 << compound_order(hpage);
81345 else /* normal page or thp */
81346 nr_pages = 1;
81347- atomic_long_add(nr_pages, &num_poisoned_pages);
81348+ atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
81349
81350 /*
81351 * We need/can do nothing about count=0 pages.
81352@@ -1081,7 +1081,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81353 if (!PageHWPoison(hpage)
81354 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
81355 || (p != hpage && TestSetPageHWPoison(hpage))) {
81356- atomic_long_sub(nr_pages, &num_poisoned_pages);
81357+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81358 return 0;
81359 }
81360 set_page_hwpoison_huge_page(hpage);
81361@@ -1148,7 +1148,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
81362 }
81363 if (hwpoison_filter(p)) {
81364 if (TestClearPageHWPoison(p))
81365- atomic_long_sub(nr_pages, &num_poisoned_pages);
81366+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81367 unlock_page(hpage);
81368 put_page(hpage);
81369 return 0;
81370@@ -1350,7 +1350,7 @@ int unpoison_memory(unsigned long pfn)
81371 return 0;
81372 }
81373 if (TestClearPageHWPoison(p))
81374- atomic_long_sub(nr_pages, &num_poisoned_pages);
81375+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81376 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
81377 return 0;
81378 }
81379@@ -1364,7 +1364,7 @@ int unpoison_memory(unsigned long pfn)
81380 */
81381 if (TestClearPageHWPoison(page)) {
81382 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
81383- atomic_long_sub(nr_pages, &num_poisoned_pages);
81384+ atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
81385 freeit = 1;
81386 if (PageHuge(page))
81387 clear_page_hwpoison_huge_page(page);
81388@@ -1491,7 +1491,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
81389 } else {
81390 set_page_hwpoison_huge_page(hpage);
81391 dequeue_hwpoisoned_huge_page(hpage);
81392- atomic_long_add(1 << compound_trans_order(hpage),
81393+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81394 &num_poisoned_pages);
81395 }
81396 /* keep elevated page count for bad page */
81397@@ -1552,11 +1552,11 @@ int soft_offline_page(struct page *page, int flags)
81398 if (PageHuge(page)) {
81399 set_page_hwpoison_huge_page(hpage);
81400 dequeue_hwpoisoned_huge_page(hpage);
81401- atomic_long_add(1 << compound_trans_order(hpage),
81402+ atomic_long_add_unchecked(1 << compound_trans_order(hpage),
81403 &num_poisoned_pages);
81404 } else {
81405 SetPageHWPoison(page);
81406- atomic_long_inc(&num_poisoned_pages);
81407+ atomic_long_inc_unchecked(&num_poisoned_pages);
81408 }
81409 }
81410 /* keep elevated page count for bad page */
81411@@ -1596,7 +1596,7 @@ static int __soft_offline_page(struct page *page, int flags)
81412 put_page(page);
81413 pr_info("soft_offline: %#lx: invalidated\n", pfn);
81414 SetPageHWPoison(page);
81415- atomic_long_inc(&num_poisoned_pages);
81416+ atomic_long_inc_unchecked(&num_poisoned_pages);
81417 return 0;
81418 }
81419
81420@@ -1626,7 +1626,7 @@ static int __soft_offline_page(struct page *page, int flags)
81421 ret = -EIO;
81422 } else {
81423 SetPageHWPoison(page);
81424- atomic_long_inc(&num_poisoned_pages);
81425+ atomic_long_inc_unchecked(&num_poisoned_pages);
81426 }
81427 } else {
81428 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
81429diff --git a/mm/memory.c b/mm/memory.c
81430index ba94dec..08ffe0d 100644
81431--- a/mm/memory.c
81432+++ b/mm/memory.c
81433@@ -438,6 +438,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81434 free_pte_range(tlb, pmd, addr);
81435 } while (pmd++, addr = next, addr != end);
81436
81437+#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
81438 start &= PUD_MASK;
81439 if (start < floor)
81440 return;
81441@@ -452,6 +453,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
81442 pmd = pmd_offset(pud, start);
81443 pud_clear(pud);
81444 pmd_free_tlb(tlb, pmd, start);
81445+#endif
81446+
81447 }
81448
81449 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81450@@ -471,6 +474,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81451 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
81452 } while (pud++, addr = next, addr != end);
81453
81454+#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
81455 start &= PGDIR_MASK;
81456 if (start < floor)
81457 return;
81458@@ -485,6 +489,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
81459 pud = pud_offset(pgd, start);
81460 pgd_clear(pgd);
81461 pud_free_tlb(tlb, pud, start);
81462+#endif
81463+
81464 }
81465
81466 /*
81467@@ -1644,12 +1650,6 @@ no_page_table:
81468 return page;
81469 }
81470
81471-static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
81472-{
81473- return stack_guard_page_start(vma, addr) ||
81474- stack_guard_page_end(vma, addr+PAGE_SIZE);
81475-}
81476-
81477 /**
81478 * __get_user_pages() - pin user pages in memory
81479 * @tsk: task_struct of target task
81480@@ -1736,10 +1736,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81481
81482 i = 0;
81483
81484- do {
81485+ while (nr_pages) {
81486 struct vm_area_struct *vma;
81487
81488- vma = find_extend_vma(mm, start);
81489+ vma = find_vma(mm, start);
81490 if (!vma && in_gate_area(mm, start)) {
81491 unsigned long pg = start & PAGE_MASK;
81492 pgd_t *pgd;
81493@@ -1788,7 +1788,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81494 goto next_page;
81495 }
81496
81497- if (!vma ||
81498+ if (!vma || start < vma->vm_start ||
81499 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
81500 !(vm_flags & vma->vm_flags))
81501 return i ? : -EFAULT;
81502@@ -1817,11 +1817,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
81503 int ret;
81504 unsigned int fault_flags = 0;
81505
81506- /* For mlock, just skip the stack guard page. */
81507- if (foll_flags & FOLL_MLOCK) {
81508- if (stack_guard_page(vma, start))
81509- goto next_page;
81510- }
81511 if (foll_flags & FOLL_WRITE)
81512 fault_flags |= FAULT_FLAG_WRITE;
81513 if (nonblocking)
81514@@ -1901,7 +1896,7 @@ next_page:
81515 start += page_increm * PAGE_SIZE;
81516 nr_pages -= page_increm;
81517 } while (nr_pages && start < vma->vm_end);
81518- } while (nr_pages);
81519+ }
81520 return i;
81521 }
81522 EXPORT_SYMBOL(__get_user_pages);
81523@@ -2108,6 +2103,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
81524 page_add_file_rmap(page);
81525 set_pte_at(mm, addr, pte, mk_pte(page, prot));
81526
81527+#ifdef CONFIG_PAX_SEGMEXEC
81528+ pax_mirror_file_pte(vma, addr, page, ptl);
81529+#endif
81530+
81531 retval = 0;
81532 pte_unmap_unlock(pte, ptl);
81533 return retval;
81534@@ -2152,9 +2151,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
81535 if (!page_count(page))
81536 return -EINVAL;
81537 if (!(vma->vm_flags & VM_MIXEDMAP)) {
81538+
81539+#ifdef CONFIG_PAX_SEGMEXEC
81540+ struct vm_area_struct *vma_m;
81541+#endif
81542+
81543 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
81544 BUG_ON(vma->vm_flags & VM_PFNMAP);
81545 vma->vm_flags |= VM_MIXEDMAP;
81546+
81547+#ifdef CONFIG_PAX_SEGMEXEC
81548+ vma_m = pax_find_mirror_vma(vma);
81549+ if (vma_m)
81550+ vma_m->vm_flags |= VM_MIXEDMAP;
81551+#endif
81552+
81553 }
81554 return insert_page(vma, addr, page, vma->vm_page_prot);
81555 }
81556@@ -2237,6 +2248,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
81557 unsigned long pfn)
81558 {
81559 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
81560+ BUG_ON(vma->vm_mirror);
81561
81562 if (addr < vma->vm_start || addr >= vma->vm_end)
81563 return -EFAULT;
81564@@ -2484,7 +2496,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
81565
81566 BUG_ON(pud_huge(*pud));
81567
81568- pmd = pmd_alloc(mm, pud, addr);
81569+ pmd = (mm == &init_mm) ?
81570+ pmd_alloc_kernel(mm, pud, addr) :
81571+ pmd_alloc(mm, pud, addr);
81572 if (!pmd)
81573 return -ENOMEM;
81574 do {
81575@@ -2504,7 +2518,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
81576 unsigned long next;
81577 int err;
81578
81579- pud = pud_alloc(mm, pgd, addr);
81580+ pud = (mm == &init_mm) ?
81581+ pud_alloc_kernel(mm, pgd, addr) :
81582+ pud_alloc(mm, pgd, addr);
81583 if (!pud)
81584 return -ENOMEM;
81585 do {
81586@@ -2592,6 +2608,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
81587 copy_user_highpage(dst, src, va, vma);
81588 }
81589
81590+#ifdef CONFIG_PAX_SEGMEXEC
81591+static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
81592+{
81593+ struct mm_struct *mm = vma->vm_mm;
81594+ spinlock_t *ptl;
81595+ pte_t *pte, entry;
81596+
81597+ pte = pte_offset_map_lock(mm, pmd, address, &ptl);
81598+ entry = *pte;
81599+ if (!pte_present(entry)) {
81600+ if (!pte_none(entry)) {
81601+ BUG_ON(pte_file(entry));
81602+ free_swap_and_cache(pte_to_swp_entry(entry));
81603+ pte_clear_not_present_full(mm, address, pte, 0);
81604+ }
81605+ } else {
81606+ struct page *page;
81607+
81608+ flush_cache_page(vma, address, pte_pfn(entry));
81609+ entry = ptep_clear_flush(vma, address, pte);
81610+ BUG_ON(pte_dirty(entry));
81611+ page = vm_normal_page(vma, address, entry);
81612+ if (page) {
81613+ update_hiwater_rss(mm);
81614+ if (PageAnon(page))
81615+ dec_mm_counter_fast(mm, MM_ANONPAGES);
81616+ else
81617+ dec_mm_counter_fast(mm, MM_FILEPAGES);
81618+ page_remove_rmap(page);
81619+ page_cache_release(page);
81620+ }
81621+ }
81622+ pte_unmap_unlock(pte, ptl);
81623+}
81624+
81625+/* PaX: if vma is mirrored, synchronize the mirror's PTE
81626+ *
81627+ * the ptl of the lower mapped page is held on entry and is not released on exit
81628+ * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
81629+ */
81630+static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81631+{
81632+ struct mm_struct *mm = vma->vm_mm;
81633+ unsigned long address_m;
81634+ spinlock_t *ptl_m;
81635+ struct vm_area_struct *vma_m;
81636+ pmd_t *pmd_m;
81637+ pte_t *pte_m, entry_m;
81638+
81639+ BUG_ON(!page_m || !PageAnon(page_m));
81640+
81641+ vma_m = pax_find_mirror_vma(vma);
81642+ if (!vma_m)
81643+ return;
81644+
81645+ BUG_ON(!PageLocked(page_m));
81646+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81647+ address_m = address + SEGMEXEC_TASK_SIZE;
81648+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81649+ pte_m = pte_offset_map(pmd_m, address_m);
81650+ ptl_m = pte_lockptr(mm, pmd_m);
81651+ if (ptl != ptl_m) {
81652+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81653+ if (!pte_none(*pte_m))
81654+ goto out;
81655+ }
81656+
81657+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81658+ page_cache_get(page_m);
81659+ page_add_anon_rmap(page_m, vma_m, address_m);
81660+ inc_mm_counter_fast(mm, MM_ANONPAGES);
81661+ set_pte_at(mm, address_m, pte_m, entry_m);
81662+ update_mmu_cache(vma_m, address_m, pte_m);
81663+out:
81664+ if (ptl != ptl_m)
81665+ spin_unlock(ptl_m);
81666+ pte_unmap(pte_m);
81667+ unlock_page(page_m);
81668+}
81669+
81670+void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
81671+{
81672+ struct mm_struct *mm = vma->vm_mm;
81673+ unsigned long address_m;
81674+ spinlock_t *ptl_m;
81675+ struct vm_area_struct *vma_m;
81676+ pmd_t *pmd_m;
81677+ pte_t *pte_m, entry_m;
81678+
81679+ BUG_ON(!page_m || PageAnon(page_m));
81680+
81681+ vma_m = pax_find_mirror_vma(vma);
81682+ if (!vma_m)
81683+ return;
81684+
81685+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81686+ address_m = address + SEGMEXEC_TASK_SIZE;
81687+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81688+ pte_m = pte_offset_map(pmd_m, address_m);
81689+ ptl_m = pte_lockptr(mm, pmd_m);
81690+ if (ptl != ptl_m) {
81691+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81692+ if (!pte_none(*pte_m))
81693+ goto out;
81694+ }
81695+
81696+ entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
81697+ page_cache_get(page_m);
81698+ page_add_file_rmap(page_m);
81699+ inc_mm_counter_fast(mm, MM_FILEPAGES);
81700+ set_pte_at(mm, address_m, pte_m, entry_m);
81701+ update_mmu_cache(vma_m, address_m, pte_m);
81702+out:
81703+ if (ptl != ptl_m)
81704+ spin_unlock(ptl_m);
81705+ pte_unmap(pte_m);
81706+}
81707+
81708+static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
81709+{
81710+ struct mm_struct *mm = vma->vm_mm;
81711+ unsigned long address_m;
81712+ spinlock_t *ptl_m;
81713+ struct vm_area_struct *vma_m;
81714+ pmd_t *pmd_m;
81715+ pte_t *pte_m, entry_m;
81716+
81717+ vma_m = pax_find_mirror_vma(vma);
81718+ if (!vma_m)
81719+ return;
81720+
81721+ BUG_ON(address >= SEGMEXEC_TASK_SIZE);
81722+ address_m = address + SEGMEXEC_TASK_SIZE;
81723+ pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
81724+ pte_m = pte_offset_map(pmd_m, address_m);
81725+ ptl_m = pte_lockptr(mm, pmd_m);
81726+ if (ptl != ptl_m) {
81727+ spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
81728+ if (!pte_none(*pte_m))
81729+ goto out;
81730+ }
81731+
81732+ entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
81733+ set_pte_at(mm, address_m, pte_m, entry_m);
81734+out:
81735+ if (ptl != ptl_m)
81736+ spin_unlock(ptl_m);
81737+ pte_unmap(pte_m);
81738+}
81739+
81740+static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
81741+{
81742+ struct page *page_m;
81743+ pte_t entry;
81744+
81745+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
81746+ goto out;
81747+
81748+ entry = *pte;
81749+ page_m = vm_normal_page(vma, address, entry);
81750+ if (!page_m)
81751+ pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
81752+ else if (PageAnon(page_m)) {
81753+ if (pax_find_mirror_vma(vma)) {
81754+ pte_unmap_unlock(pte, ptl);
81755+ lock_page(page_m);
81756+ pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
81757+ if (pte_same(entry, *pte))
81758+ pax_mirror_anon_pte(vma, address, page_m, ptl);
81759+ else
81760+ unlock_page(page_m);
81761+ }
81762+ } else
81763+ pax_mirror_file_pte(vma, address, page_m, ptl);
81764+
81765+out:
81766+ pte_unmap_unlock(pte, ptl);
81767+}
81768+#endif
81769+
81770 /*
81771 * This routine handles present pages, when users try to write
81772 * to a shared page. It is done by copying the page to a new address
81773@@ -2808,6 +3004,12 @@ gotten:
81774 */
81775 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81776 if (likely(pte_same(*page_table, orig_pte))) {
81777+
81778+#ifdef CONFIG_PAX_SEGMEXEC
81779+ if (pax_find_mirror_vma(vma))
81780+ BUG_ON(!trylock_page(new_page));
81781+#endif
81782+
81783 if (old_page) {
81784 if (!PageAnon(old_page)) {
81785 dec_mm_counter_fast(mm, MM_FILEPAGES);
81786@@ -2859,6 +3061,10 @@ gotten:
81787 page_remove_rmap(old_page);
81788 }
81789
81790+#ifdef CONFIG_PAX_SEGMEXEC
81791+ pax_mirror_anon_pte(vma, address, new_page, ptl);
81792+#endif
81793+
81794 /* Free the old page.. */
81795 new_page = old_page;
81796 ret |= VM_FAULT_WRITE;
81797@@ -3134,6 +3340,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81798 swap_free(entry);
81799 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
81800 try_to_free_swap(page);
81801+
81802+#ifdef CONFIG_PAX_SEGMEXEC
81803+ if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
81804+#endif
81805+
81806 unlock_page(page);
81807 if (page != swapcache) {
81808 /*
81809@@ -3157,6 +3368,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
81810
81811 /* No need to invalidate - it was non-present before */
81812 update_mmu_cache(vma, address, page_table);
81813+
81814+#ifdef CONFIG_PAX_SEGMEXEC
81815+ pax_mirror_anon_pte(vma, address, page, ptl);
81816+#endif
81817+
81818 unlock:
81819 pte_unmap_unlock(page_table, ptl);
81820 out:
81821@@ -3176,40 +3392,6 @@ out_release:
81822 }
81823
81824 /*
81825- * This is like a special single-page "expand_{down|up}wards()",
81826- * except we must first make sure that 'address{-|+}PAGE_SIZE'
81827- * doesn't hit another vma.
81828- */
81829-static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
81830-{
81831- address &= PAGE_MASK;
81832- if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
81833- struct vm_area_struct *prev = vma->vm_prev;
81834-
81835- /*
81836- * Is there a mapping abutting this one below?
81837- *
81838- * That's only ok if it's the same stack mapping
81839- * that has gotten split..
81840- */
81841- if (prev && prev->vm_end == address)
81842- return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
81843-
81844- expand_downwards(vma, address - PAGE_SIZE);
81845- }
81846- if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
81847- struct vm_area_struct *next = vma->vm_next;
81848-
81849- /* As VM_GROWSDOWN but s/below/above/ */
81850- if (next && next->vm_start == address + PAGE_SIZE)
81851- return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
81852-
81853- expand_upwards(vma, address + PAGE_SIZE);
81854- }
81855- return 0;
81856-}
81857-
81858-/*
81859 * We enter with non-exclusive mmap_sem (to exclude vma changes,
81860 * but allow concurrent faults), and pte mapped but not yet locked.
81861 * We return with mmap_sem still held, but pte unmapped and unlocked.
81862@@ -3218,27 +3400,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81863 unsigned long address, pte_t *page_table, pmd_t *pmd,
81864 unsigned int flags)
81865 {
81866- struct page *page;
81867+ struct page *page = NULL;
81868 spinlock_t *ptl;
81869 pte_t entry;
81870
81871- pte_unmap(page_table);
81872-
81873- /* Check if we need to add a guard page to the stack */
81874- if (check_stack_guard_page(vma, address) < 0)
81875- return VM_FAULT_SIGBUS;
81876-
81877- /* Use the zero-page for reads */
81878 if (!(flags & FAULT_FLAG_WRITE)) {
81879 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
81880 vma->vm_page_prot));
81881- page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
81882+ ptl = pte_lockptr(mm, pmd);
81883+ spin_lock(ptl);
81884 if (!pte_none(*page_table))
81885 goto unlock;
81886 goto setpte;
81887 }
81888
81889 /* Allocate our own private page. */
81890+ pte_unmap(page_table);
81891+
81892 if (unlikely(anon_vma_prepare(vma)))
81893 goto oom;
81894 page = alloc_zeroed_user_highpage_movable(vma, address);
81895@@ -3257,6 +3435,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
81896 if (!pte_none(*page_table))
81897 goto release;
81898
81899+#ifdef CONFIG_PAX_SEGMEXEC
81900+ if (pax_find_mirror_vma(vma))
81901+ BUG_ON(!trylock_page(page));
81902+#endif
81903+
81904 inc_mm_counter_fast(mm, MM_ANONPAGES);
81905 page_add_new_anon_rmap(page, vma, address);
81906 setpte:
81907@@ -3264,6 +3447,12 @@ setpte:
81908
81909 /* No need to invalidate - it was non-present before */
81910 update_mmu_cache(vma, address, page_table);
81911+
81912+#ifdef CONFIG_PAX_SEGMEXEC
81913+ if (page)
81914+ pax_mirror_anon_pte(vma, address, page, ptl);
81915+#endif
81916+
81917 unlock:
81918 pte_unmap_unlock(page_table, ptl);
81919 return 0;
81920@@ -3407,6 +3596,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81921 */
81922 /* Only go through if we didn't race with anybody else... */
81923 if (likely(pte_same(*page_table, orig_pte))) {
81924+
81925+#ifdef CONFIG_PAX_SEGMEXEC
81926+ if (anon && pax_find_mirror_vma(vma))
81927+ BUG_ON(!trylock_page(page));
81928+#endif
81929+
81930 flush_icache_page(vma, page);
81931 entry = mk_pte(page, vma->vm_page_prot);
81932 if (flags & FAULT_FLAG_WRITE)
81933@@ -3426,6 +3621,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81934
81935 /* no need to invalidate: a not-present page won't be cached */
81936 update_mmu_cache(vma, address, page_table);
81937+
81938+#ifdef CONFIG_PAX_SEGMEXEC
81939+ if (anon)
81940+ pax_mirror_anon_pte(vma, address, page, ptl);
81941+ else
81942+ pax_mirror_file_pte(vma, address, page, ptl);
81943+#endif
81944+
81945 } else {
81946 if (cow_page)
81947 mem_cgroup_uncharge_page(cow_page);
81948@@ -3747,6 +3950,12 @@ int handle_pte_fault(struct mm_struct *mm,
81949 if (flags & FAULT_FLAG_WRITE)
81950 flush_tlb_fix_spurious_fault(vma, address);
81951 }
81952+
81953+#ifdef CONFIG_PAX_SEGMEXEC
81954+ pax_mirror_pte(vma, address, pte, pmd, ptl);
81955+ return 0;
81956+#endif
81957+
81958 unlock:
81959 pte_unmap_unlock(pte, ptl);
81960 return 0;
81961@@ -3763,6 +3972,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81962 pmd_t *pmd;
81963 pte_t *pte;
81964
81965+#ifdef CONFIG_PAX_SEGMEXEC
81966+ struct vm_area_struct *vma_m;
81967+#endif
81968+
81969 __set_current_state(TASK_RUNNING);
81970
81971 count_vm_event(PGFAULT);
81972@@ -3774,6 +3987,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
81973 if (unlikely(is_vm_hugetlb_page(vma)))
81974 return hugetlb_fault(mm, vma, address, flags);
81975
81976+#ifdef CONFIG_PAX_SEGMEXEC
81977+ vma_m = pax_find_mirror_vma(vma);
81978+ if (vma_m) {
81979+ unsigned long address_m;
81980+ pgd_t *pgd_m;
81981+ pud_t *pud_m;
81982+ pmd_t *pmd_m;
81983+
81984+ if (vma->vm_start > vma_m->vm_start) {
81985+ address_m = address;
81986+ address -= SEGMEXEC_TASK_SIZE;
81987+ vma = vma_m;
81988+ } else
81989+ address_m = address + SEGMEXEC_TASK_SIZE;
81990+
81991+ pgd_m = pgd_offset(mm, address_m);
81992+ pud_m = pud_alloc(mm, pgd_m, address_m);
81993+ if (!pud_m)
81994+ return VM_FAULT_OOM;
81995+ pmd_m = pmd_alloc(mm, pud_m, address_m);
81996+ if (!pmd_m)
81997+ return VM_FAULT_OOM;
81998+ if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
81999+ return VM_FAULT_OOM;
82000+ pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
82001+ }
82002+#endif
82003+
82004 retry:
82005 pgd = pgd_offset(mm, address);
82006 pud = pud_alloc(mm, pgd, address);
82007@@ -3872,6 +4113,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82008 spin_unlock(&mm->page_table_lock);
82009 return 0;
82010 }
82011+
82012+int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
82013+{
82014+ pud_t *new = pud_alloc_one(mm, address);
82015+ if (!new)
82016+ return -ENOMEM;
82017+
82018+ smp_wmb(); /* See comment in __pte_alloc */
82019+
82020+ spin_lock(&mm->page_table_lock);
82021+ if (pgd_present(*pgd)) /* Another has populated it */
82022+ pud_free(mm, new);
82023+ else
82024+ pgd_populate_kernel(mm, pgd, new);
82025+ spin_unlock(&mm->page_table_lock);
82026+ return 0;
82027+}
82028 #endif /* __PAGETABLE_PUD_FOLDED */
82029
82030 #ifndef __PAGETABLE_PMD_FOLDED
82031@@ -3902,6 +4160,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
82032 spin_unlock(&mm->page_table_lock);
82033 return 0;
82034 }
82035+
82036+int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
82037+{
82038+ pmd_t *new = pmd_alloc_one(mm, address);
82039+ if (!new)
82040+ return -ENOMEM;
82041+
82042+ smp_wmb(); /* See comment in __pte_alloc */
82043+
82044+ spin_lock(&mm->page_table_lock);
82045+#ifndef __ARCH_HAS_4LEVEL_HACK
82046+ if (pud_present(*pud)) /* Another has populated it */
82047+ pmd_free(mm, new);
82048+ else
82049+ pud_populate_kernel(mm, pud, new);
82050+#else
82051+ if (pgd_present(*pud)) /* Another has populated it */
82052+ pmd_free(mm, new);
82053+ else
82054+ pgd_populate_kernel(mm, pud, new);
82055+#endif /* __ARCH_HAS_4LEVEL_HACK */
82056+ spin_unlock(&mm->page_table_lock);
82057+ return 0;
82058+}
82059 #endif /* __PAGETABLE_PMD_FOLDED */
82060
82061 #if !defined(__HAVE_ARCH_GATE_AREA)
82062@@ -3915,7 +4197,7 @@ static int __init gate_vma_init(void)
82063 gate_vma.vm_start = FIXADDR_USER_START;
82064 gate_vma.vm_end = FIXADDR_USER_END;
82065 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
82066- gate_vma.vm_page_prot = __P101;
82067+ gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
82068
82069 return 0;
82070 }
82071@@ -4049,8 +4331,8 @@ out:
82072 return ret;
82073 }
82074
82075-int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82076- void *buf, int len, int write)
82077+ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82078+ void *buf, size_t len, int write)
82079 {
82080 resource_size_t phys_addr;
82081 unsigned long prot = 0;
82082@@ -4075,8 +4357,8 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
82083 * Access another process' address space as given in mm. If non-NULL, use the
82084 * given task for page fault accounting.
82085 */
82086-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82087- unsigned long addr, void *buf, int len, int write)
82088+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82089+ unsigned long addr, void *buf, size_t len, int write)
82090 {
82091 struct vm_area_struct *vma;
82092 void *old_buf = buf;
82093@@ -4084,7 +4366,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82094 down_read(&mm->mmap_sem);
82095 /* ignore errors, just check how much was successfully transferred */
82096 while (len) {
82097- int bytes, ret, offset;
82098+ ssize_t bytes, ret, offset;
82099 void *maddr;
82100 struct page *page = NULL;
82101
82102@@ -4143,8 +4425,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
82103 *
82104 * The caller must hold a reference on @mm.
82105 */
82106-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82107- void *buf, int len, int write)
82108+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
82109+ void *buf, size_t len, int write)
82110 {
82111 return __access_remote_vm(NULL, mm, addr, buf, len, write);
82112 }
82113@@ -4154,11 +4436,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
82114 * Source/target buffer must be kernel space,
82115 * Do not walk the page table directly, use get_user_pages
82116 */
82117-int access_process_vm(struct task_struct *tsk, unsigned long addr,
82118- void *buf, int len, int write)
82119+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
82120+ void *buf, size_t len, int write)
82121 {
82122 struct mm_struct *mm;
82123- int ret;
82124+ ssize_t ret;
82125
82126 mm = get_task_mm(tsk);
82127 if (!mm)
82128diff --git a/mm/mempolicy.c b/mm/mempolicy.c
82129index 7431001..0f8344e 100644
82130--- a/mm/mempolicy.c
82131+++ b/mm/mempolicy.c
82132@@ -708,6 +708,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82133 unsigned long vmstart;
82134 unsigned long vmend;
82135
82136+#ifdef CONFIG_PAX_SEGMEXEC
82137+ struct vm_area_struct *vma_m;
82138+#endif
82139+
82140 vma = find_vma(mm, start);
82141 if (!vma || vma->vm_start > start)
82142 return -EFAULT;
82143@@ -744,9 +748,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
82144 if (err)
82145 goto out;
82146 }
82147+
82148 err = vma_replace_policy(vma, new_pol);
82149 if (err)
82150 goto out;
82151+
82152+#ifdef CONFIG_PAX_SEGMEXEC
82153+ vma_m = pax_find_mirror_vma(vma);
82154+ if (vma_m) {
82155+ err = vma_replace_policy(vma_m, new_pol);
82156+ if (err)
82157+ goto out;
82158+ }
82159+#endif
82160+
82161 }
82162
82163 out:
82164@@ -1202,6 +1217,17 @@ static long do_mbind(unsigned long start, unsigned long len,
82165
82166 if (end < start)
82167 return -EINVAL;
82168+
82169+#ifdef CONFIG_PAX_SEGMEXEC
82170+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
82171+ if (end > SEGMEXEC_TASK_SIZE)
82172+ return -EINVAL;
82173+ } else
82174+#endif
82175+
82176+ if (end > TASK_SIZE)
82177+ return -EINVAL;
82178+
82179 if (end == start)
82180 return 0;
82181
82182@@ -1430,8 +1456,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82183 */
82184 tcred = __task_cred(task);
82185 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82186- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82187- !capable(CAP_SYS_NICE)) {
82188+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82189 rcu_read_unlock();
82190 err = -EPERM;
82191 goto out_put;
82192@@ -1462,6 +1487,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
82193 goto out;
82194 }
82195
82196+#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82197+ if (mm != current->mm &&
82198+ (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
82199+ mmput(mm);
82200+ err = -EPERM;
82201+ goto out;
82202+ }
82203+#endif
82204+
82205 err = do_migrate_pages(mm, old, new,
82206 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
82207
82208diff --git a/mm/migrate.c b/mm/migrate.c
82209index c04d9af..0b41805 100644
82210--- a/mm/migrate.c
82211+++ b/mm/migrate.c
82212@@ -1395,8 +1395,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
82213 */
82214 tcred = __task_cred(task);
82215 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
82216- !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
82217- !capable(CAP_SYS_NICE)) {
82218+ !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
82219 rcu_read_unlock();
82220 err = -EPERM;
82221 goto out;
82222diff --git a/mm/mlock.c b/mm/mlock.c
82223index 79b7cf7..9944291 100644
82224--- a/mm/mlock.c
82225+++ b/mm/mlock.c
82226@@ -13,6 +13,7 @@
82227 #include <linux/pagemap.h>
82228 #include <linux/mempolicy.h>
82229 #include <linux/syscalls.h>
82230+#include <linux/security.h>
82231 #include <linux/sched.h>
82232 #include <linux/export.h>
82233 #include <linux/rmap.h>
82234@@ -334,7 +335,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
82235 {
82236 unsigned long nstart, end, tmp;
82237 struct vm_area_struct * vma, * prev;
82238- int error;
82239+ int error = 0;
82240
82241 VM_BUG_ON(start & ~PAGE_MASK);
82242 VM_BUG_ON(len != PAGE_ALIGN(len));
82243@@ -343,6 +344,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
82244 return -EINVAL;
82245 if (end == start)
82246 return 0;
82247+ if (end > TASK_SIZE)
82248+ return -EINVAL;
82249+
82250 vma = find_vma(current->mm, start);
82251 if (!vma || vma->vm_start > start)
82252 return -ENOMEM;
82253@@ -354,6 +358,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
82254 for (nstart = start ; ; ) {
82255 vm_flags_t newflags;
82256
82257+#ifdef CONFIG_PAX_SEGMEXEC
82258+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82259+ break;
82260+#endif
82261+
82262 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
82263
82264 newflags = vma->vm_flags & ~VM_LOCKED;
82265@@ -466,6 +475,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
82266 lock_limit >>= PAGE_SHIFT;
82267
82268 /* check against resource limits */
82269+ gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
82270 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
82271 error = do_mlock(start, len, 1);
82272 up_write(&current->mm->mmap_sem);
82273@@ -500,6 +510,11 @@ static int do_mlockall(int flags)
82274 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
82275 vm_flags_t newflags;
82276
82277+#ifdef CONFIG_PAX_SEGMEXEC
82278+ if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
82279+ break;
82280+#endif
82281+
82282 newflags = vma->vm_flags & ~VM_LOCKED;
82283 if (flags & MCL_CURRENT)
82284 newflags |= VM_LOCKED;
82285@@ -532,6 +547,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
82286 lock_limit >>= PAGE_SHIFT;
82287
82288 ret = -ENOMEM;
82289+ gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
82290 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
82291 capable(CAP_IPC_LOCK))
82292 ret = do_mlockall(flags);
82293diff --git a/mm/mmap.c b/mm/mmap.c
82294index 0dceed8..bfcaf45 100644
82295--- a/mm/mmap.c
82296+++ b/mm/mmap.c
82297@@ -33,6 +33,7 @@
82298 #include <linux/uprobes.h>
82299 #include <linux/rbtree_augmented.h>
82300 #include <linux/sched/sysctl.h>
82301+#include <linux/random.h>
82302
82303 #include <asm/uaccess.h>
82304 #include <asm/cacheflush.h>
82305@@ -49,6 +50,16 @@
82306 #define arch_rebalance_pgtables(addr, len) (addr)
82307 #endif
82308
82309+static inline void verify_mm_writelocked(struct mm_struct *mm)
82310+{
82311+#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
82312+ if (unlikely(down_read_trylock(&mm->mmap_sem))) {
82313+ up_read(&mm->mmap_sem);
82314+ BUG();
82315+ }
82316+#endif
82317+}
82318+
82319 static void unmap_region(struct mm_struct *mm,
82320 struct vm_area_struct *vma, struct vm_area_struct *prev,
82321 unsigned long start, unsigned long end);
82322@@ -68,22 +79,32 @@ static void unmap_region(struct mm_struct *mm,
82323 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
82324 *
82325 */
82326-pgprot_t protection_map[16] = {
82327+pgprot_t protection_map[16] __read_only = {
82328 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
82329 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
82330 };
82331
82332-pgprot_t vm_get_page_prot(unsigned long vm_flags)
82333+pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
82334 {
82335- return __pgprot(pgprot_val(protection_map[vm_flags &
82336+ pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
82337 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
82338 pgprot_val(arch_vm_get_page_prot(vm_flags)));
82339+
82340+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82341+ if (!(__supported_pte_mask & _PAGE_NX) &&
82342+ (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
82343+ (vm_flags & (VM_READ | VM_WRITE)))
82344+ prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
82345+#endif
82346+
82347+ return prot;
82348 }
82349 EXPORT_SYMBOL(vm_get_page_prot);
82350
82351 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
82352 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
82353 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
82354+unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
82355 /*
82356 * Make sure vm_committed_as in one cacheline and not cacheline shared with
82357 * other variables. It can be updated by several CPUs frequently.
82358@@ -239,6 +260,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
82359 struct vm_area_struct *next = vma->vm_next;
82360
82361 might_sleep();
82362+ BUG_ON(vma->vm_mirror);
82363 if (vma->vm_ops && vma->vm_ops->close)
82364 vma->vm_ops->close(vma);
82365 if (vma->vm_file)
82366@@ -283,6 +305,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
82367 * not page aligned -Ram Gupta
82368 */
82369 rlim = rlimit(RLIMIT_DATA);
82370+ gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
82371 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
82372 (mm->end_data - mm->start_data) > rlim)
82373 goto out;
82374@@ -897,6 +920,12 @@ static int
82375 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
82376 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82377 {
82378+
82379+#ifdef CONFIG_PAX_SEGMEXEC
82380+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
82381+ return 0;
82382+#endif
82383+
82384 if (is_mergeable_vma(vma, file, vm_flags) &&
82385 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82386 if (vma->vm_pgoff == vm_pgoff)
82387@@ -916,6 +945,12 @@ static int
82388 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82389 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
82390 {
82391+
82392+#ifdef CONFIG_PAX_SEGMEXEC
82393+ if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
82394+ return 0;
82395+#endif
82396+
82397 if (is_mergeable_vma(vma, file, vm_flags) &&
82398 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
82399 pgoff_t vm_pglen;
82400@@ -958,13 +993,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
82401 struct vm_area_struct *vma_merge(struct mm_struct *mm,
82402 struct vm_area_struct *prev, unsigned long addr,
82403 unsigned long end, unsigned long vm_flags,
82404- struct anon_vma *anon_vma, struct file *file,
82405+ struct anon_vma *anon_vma, struct file *file,
82406 pgoff_t pgoff, struct mempolicy *policy)
82407 {
82408 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
82409 struct vm_area_struct *area, *next;
82410 int err;
82411
82412+#ifdef CONFIG_PAX_SEGMEXEC
82413+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
82414+ struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
82415+
82416+ BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
82417+#endif
82418+
82419 /*
82420 * We later require that vma->vm_flags == vm_flags,
82421 * so this tests vma->vm_flags & VM_SPECIAL, too.
82422@@ -980,6 +1022,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82423 if (next && next->vm_end == end) /* cases 6, 7, 8 */
82424 next = next->vm_next;
82425
82426+#ifdef CONFIG_PAX_SEGMEXEC
82427+ if (prev)
82428+ prev_m = pax_find_mirror_vma(prev);
82429+ if (area)
82430+ area_m = pax_find_mirror_vma(area);
82431+ if (next)
82432+ next_m = pax_find_mirror_vma(next);
82433+#endif
82434+
82435 /*
82436 * Can it merge with the predecessor?
82437 */
82438@@ -999,9 +1050,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82439 /* cases 1, 6 */
82440 err = vma_adjust(prev, prev->vm_start,
82441 next->vm_end, prev->vm_pgoff, NULL);
82442- } else /* cases 2, 5, 7 */
82443+
82444+#ifdef CONFIG_PAX_SEGMEXEC
82445+ if (!err && prev_m)
82446+ err = vma_adjust(prev_m, prev_m->vm_start,
82447+ next_m->vm_end, prev_m->vm_pgoff, NULL);
82448+#endif
82449+
82450+ } else { /* cases 2, 5, 7 */
82451 err = vma_adjust(prev, prev->vm_start,
82452 end, prev->vm_pgoff, NULL);
82453+
82454+#ifdef CONFIG_PAX_SEGMEXEC
82455+ if (!err && prev_m)
82456+ err = vma_adjust(prev_m, prev_m->vm_start,
82457+ end_m, prev_m->vm_pgoff, NULL);
82458+#endif
82459+
82460+ }
82461 if (err)
82462 return NULL;
82463 khugepaged_enter_vma_merge(prev);
82464@@ -1015,12 +1081,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
82465 mpol_equal(policy, vma_policy(next)) &&
82466 can_vma_merge_before(next, vm_flags,
82467 anon_vma, file, pgoff+pglen)) {
82468- if (prev && addr < prev->vm_end) /* case 4 */
82469+ if (prev && addr < prev->vm_end) { /* case 4 */
82470 err = vma_adjust(prev, prev->vm_start,
82471 addr, prev->vm_pgoff, NULL);
82472- else /* cases 3, 8 */
82473+
82474+#ifdef CONFIG_PAX_SEGMEXEC
82475+ if (!err && prev_m)
82476+ err = vma_adjust(prev_m, prev_m->vm_start,
82477+ addr_m, prev_m->vm_pgoff, NULL);
82478+#endif
82479+
82480+ } else { /* cases 3, 8 */
82481 err = vma_adjust(area, addr, next->vm_end,
82482 next->vm_pgoff - pglen, NULL);
82483+
82484+#ifdef CONFIG_PAX_SEGMEXEC
82485+ if (!err && area_m)
82486+ err = vma_adjust(area_m, addr_m, next_m->vm_end,
82487+ next_m->vm_pgoff - pglen, NULL);
82488+#endif
82489+
82490+ }
82491 if (err)
82492 return NULL;
82493 khugepaged_enter_vma_merge(area);
82494@@ -1129,8 +1210,10 @@ none:
82495 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82496 struct file *file, long pages)
82497 {
82498- const unsigned long stack_flags
82499- = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
82500+
82501+#ifdef CONFIG_PAX_RANDMMAP
82502+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82503+#endif
82504
82505 mm->total_vm += pages;
82506
82507@@ -1138,7 +1221,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
82508 mm->shared_vm += pages;
82509 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
82510 mm->exec_vm += pages;
82511- } else if (flags & stack_flags)
82512+ } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
82513 mm->stack_vm += pages;
82514 }
82515 #endif /* CONFIG_PROC_FS */
82516@@ -1177,7 +1260,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82517 * (the exception is when the underlying filesystem is noexec
82518 * mounted, in which case we dont add PROT_EXEC.)
82519 */
82520- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
82521+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
82522 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
82523 prot |= PROT_EXEC;
82524
82525@@ -1203,7 +1286,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82526 /* Obtain the address to map to. we verify (or select) it and ensure
82527 * that it represents a valid section of the address space.
82528 */
82529- addr = get_unmapped_area(file, addr, len, pgoff, flags);
82530+ addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
82531 if (addr & ~PAGE_MASK)
82532 return addr;
82533
82534@@ -1214,6 +1297,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82535 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
82536 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
82537
82538+#ifdef CONFIG_PAX_MPROTECT
82539+ if (mm->pax_flags & MF_PAX_MPROTECT) {
82540+#ifndef CONFIG_PAX_MPROTECT_COMPAT
82541+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
82542+ gr_log_rwxmmap(file);
82543+
82544+#ifdef CONFIG_PAX_EMUPLT
82545+ vm_flags &= ~VM_EXEC;
82546+#else
82547+ return -EPERM;
82548+#endif
82549+
82550+ }
82551+
82552+ if (!(vm_flags & VM_EXEC))
82553+ vm_flags &= ~VM_MAYEXEC;
82554+#else
82555+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
82556+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
82557+#endif
82558+ else
82559+ vm_flags &= ~VM_MAYWRITE;
82560+ }
82561+#endif
82562+
82563+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82564+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
82565+ vm_flags &= ~VM_PAGEEXEC;
82566+#endif
82567+
82568 if (flags & MAP_LOCKED)
82569 if (!can_do_mlock())
82570 return -EPERM;
82571@@ -1225,6 +1338,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82572 locked += mm->locked_vm;
82573 lock_limit = rlimit(RLIMIT_MEMLOCK);
82574 lock_limit >>= PAGE_SHIFT;
82575+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82576 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
82577 return -EAGAIN;
82578 }
82579@@ -1305,6 +1419,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
82580 vm_flags |= VM_NORESERVE;
82581 }
82582
82583+ if (!gr_acl_handle_mmap(file, prot))
82584+ return -EACCES;
82585+
82586 addr = mmap_region(file, addr, len, vm_flags, pgoff);
82587 if (!IS_ERR_VALUE(addr) &&
82588 ((vm_flags & VM_LOCKED) ||
82589@@ -1396,7 +1513,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
82590 vm_flags_t vm_flags = vma->vm_flags;
82591
82592 /* If it was private or non-writable, the write bit is already clear */
82593- if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
82594+ if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
82595 return 0;
82596
82597 /* The backer wishes to know when pages are first written to? */
82598@@ -1444,16 +1561,30 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
82599 unsigned long charged = 0;
82600 struct inode *inode = file ? file_inode(file) : NULL;
82601
82602+#ifdef CONFIG_PAX_SEGMEXEC
82603+ struct vm_area_struct *vma_m = NULL;
82604+#endif
82605+
82606+ /*
82607+ * mm->mmap_sem is required to protect against another thread
82608+ * changing the mappings in case we sleep.
82609+ */
82610+ verify_mm_writelocked(mm);
82611+
82612 /* Clear old maps */
82613 error = -ENOMEM;
82614-munmap_back:
82615 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
82616 if (do_munmap(mm, addr, len))
82617 return -ENOMEM;
82618- goto munmap_back;
82619+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
82620 }
82621
82622 /* Check against address space limit. */
82623+
82624+#ifdef CONFIG_PAX_RANDMMAP
82625+ if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
82626+#endif
82627+
82628 if (!may_expand_vm(mm, len >> PAGE_SHIFT))
82629 return -ENOMEM;
82630
82631@@ -1485,6 +1616,16 @@ munmap_back:
82632 goto unacct_error;
82633 }
82634
82635+#ifdef CONFIG_PAX_SEGMEXEC
82636+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
82637+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
82638+ if (!vma_m) {
82639+ error = -ENOMEM;
82640+ goto free_vma;
82641+ }
82642+ }
82643+#endif
82644+
82645 vma->vm_mm = mm;
82646 vma->vm_start = addr;
82647 vma->vm_end = addr + len;
82648@@ -1509,6 +1650,13 @@ munmap_back:
82649 if (error)
82650 goto unmap_and_free_vma;
82651
82652+#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
82653+ if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
82654+ vma->vm_flags |= VM_PAGEEXEC;
82655+ vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
82656+ }
82657+#endif
82658+
82659 /* Can addr have changed??
82660 *
82661 * Answer: Yes, several device drivers can do it in their
82662@@ -1547,6 +1695,11 @@ munmap_back:
82663 vma_link(mm, vma, prev, rb_link, rb_parent);
82664 file = vma->vm_file;
82665
82666+#ifdef CONFIG_PAX_SEGMEXEC
82667+ if (vma_m)
82668+ BUG_ON(pax_mirror_vma(vma_m, vma));
82669+#endif
82670+
82671 /* Once vma denies write, undo our temporary denial count */
82672 if (correct_wcount)
82673 atomic_inc(&inode->i_writecount);
82674@@ -1554,6 +1707,7 @@ out:
82675 perf_event_mmap(vma);
82676
82677 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
82678+ track_exec_limit(mm, addr, addr + len, vm_flags);
82679 if (vm_flags & VM_LOCKED) {
82680 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
82681 vma == get_gate_vma(current->mm)))
82682@@ -1577,6 +1731,12 @@ unmap_and_free_vma:
82683 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
82684 charged = 0;
82685 free_vma:
82686+
82687+#ifdef CONFIG_PAX_SEGMEXEC
82688+ if (vma_m)
82689+ kmem_cache_free(vm_area_cachep, vma_m);
82690+#endif
82691+
82692 kmem_cache_free(vm_area_cachep, vma);
82693 unacct_error:
82694 if (charged)
82695@@ -1584,7 +1744,63 @@ unacct_error:
82696 return error;
82697 }
82698
82699-unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82700+#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
82701+unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
82702+{
82703+ if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
82704+ return (random32() & 0xFF) << PAGE_SHIFT;
82705+
82706+ return 0;
82707+}
82708+#endif
82709+
82710+bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
82711+{
82712+ if (!vma) {
82713+#ifdef CONFIG_STACK_GROWSUP
82714+ if (addr > sysctl_heap_stack_gap)
82715+ vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
82716+ else
82717+ vma = find_vma(current->mm, 0);
82718+ if (vma && (vma->vm_flags & VM_GROWSUP))
82719+ return false;
82720+#endif
82721+ return true;
82722+ }
82723+
82724+ if (addr + len > vma->vm_start)
82725+ return false;
82726+
82727+ if (vma->vm_flags & VM_GROWSDOWN)
82728+ return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
82729+#ifdef CONFIG_STACK_GROWSUP
82730+ else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
82731+ return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
82732+#endif
82733+ else if (offset)
82734+ return offset <= vma->vm_start - addr - len;
82735+
82736+ return true;
82737+}
82738+
82739+unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
82740+{
82741+ if (vma->vm_start < len)
82742+ return -ENOMEM;
82743+
82744+ if (!(vma->vm_flags & VM_GROWSDOWN)) {
82745+ if (offset <= vma->vm_start - len)
82746+ return vma->vm_start - len - offset;
82747+ else
82748+ return -ENOMEM;
82749+ }
82750+
82751+ if (sysctl_heap_stack_gap <= vma->vm_start - len)
82752+ return vma->vm_start - len - sysctl_heap_stack_gap;
82753+ return -ENOMEM;
82754+}
82755+
82756+unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
82757 {
82758 /*
82759 * We implement the search by looking for an rbtree node that
82760@@ -1632,11 +1848,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
82761 }
82762 }
82763
82764- gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
82765+ gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
82766 check_current:
82767 /* Check if current node has a suitable gap */
82768 if (gap_start > high_limit)
82769 return -ENOMEM;
82770+
82771+ if (gap_end - gap_start > info->threadstack_offset)
82772+ gap_start += info->threadstack_offset;
82773+ else
82774+ gap_start = gap_end;
82775+
82776+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
82777+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82778+ gap_start += sysctl_heap_stack_gap;
82779+ else
82780+ gap_start = gap_end;
82781+ }
82782+ if (vma->vm_flags & VM_GROWSDOWN) {
82783+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82784+ gap_end -= sysctl_heap_stack_gap;
82785+ else
82786+ gap_end = gap_start;
82787+ }
82788 if (gap_end >= low_limit && gap_end - gap_start >= length)
82789 goto found;
82790
82791@@ -1686,7 +1920,7 @@ found:
82792 return gap_start;
82793 }
82794
82795-unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
82796+unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
82797 {
82798 struct mm_struct *mm = current->mm;
82799 struct vm_area_struct *vma;
82800@@ -1740,6 +1974,24 @@ check_current:
82801 gap_end = vma->vm_start;
82802 if (gap_end < low_limit)
82803 return -ENOMEM;
82804+
82805+ if (gap_end - gap_start > info->threadstack_offset)
82806+ gap_end -= info->threadstack_offset;
82807+ else
82808+ gap_end = gap_start;
82809+
82810+ if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
82811+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82812+ gap_start += sysctl_heap_stack_gap;
82813+ else
82814+ gap_start = gap_end;
82815+ }
82816+ if (vma->vm_flags & VM_GROWSDOWN) {
82817+ if (gap_end - gap_start > sysctl_heap_stack_gap)
82818+ gap_end -= sysctl_heap_stack_gap;
82819+ else
82820+ gap_end = gap_start;
82821+ }
82822 if (gap_start <= high_limit && gap_end - gap_start >= length)
82823 goto found;
82824
82825@@ -1803,6 +2055,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82826 struct mm_struct *mm = current->mm;
82827 struct vm_area_struct *vma;
82828 struct vm_unmapped_area_info info;
82829+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82830
82831 if (len > TASK_SIZE)
82832 return -ENOMEM;
82833@@ -1810,29 +2063,45 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
82834 if (flags & MAP_FIXED)
82835 return addr;
82836
82837+#ifdef CONFIG_PAX_RANDMMAP
82838+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82839+#endif
82840+
82841 if (addr) {
82842 addr = PAGE_ALIGN(addr);
82843 vma = find_vma(mm, addr);
82844- if (TASK_SIZE - len >= addr &&
82845- (!vma || addr + len <= vma->vm_start))
82846+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82847 return addr;
82848 }
82849
82850 info.flags = 0;
82851 info.length = len;
82852 info.low_limit = TASK_UNMAPPED_BASE;
82853+
82854+#ifdef CONFIG_PAX_RANDMMAP
82855+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82856+ info.low_limit += mm->delta_mmap;
82857+#endif
82858+
82859 info.high_limit = TASK_SIZE;
82860 info.align_mask = 0;
82861+ info.threadstack_offset = offset;
82862 return vm_unmapped_area(&info);
82863 }
82864 #endif
82865
82866 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
82867 {
82868+
82869+#ifdef CONFIG_PAX_SEGMEXEC
82870+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82871+ return;
82872+#endif
82873+
82874 /*
82875 * Is this a new hole at the lowest possible address?
82876 */
82877- if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
82878+ if (addr >= mm->mmap_base && addr < mm->free_area_cache)
82879 mm->free_area_cache = addr;
82880 }
82881
82882@@ -1850,6 +2119,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82883 struct mm_struct *mm = current->mm;
82884 unsigned long addr = addr0;
82885 struct vm_unmapped_area_info info;
82886+ unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
82887
82888 /* requested length too big for entire address space */
82889 if (len > TASK_SIZE)
82890@@ -1858,12 +2128,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82891 if (flags & MAP_FIXED)
82892 return addr;
82893
82894+#ifdef CONFIG_PAX_RANDMMAP
82895+ if (!(mm->pax_flags & MF_PAX_RANDMMAP))
82896+#endif
82897+
82898 /* requesting a specific address */
82899 if (addr) {
82900 addr = PAGE_ALIGN(addr);
82901 vma = find_vma(mm, addr);
82902- if (TASK_SIZE - len >= addr &&
82903- (!vma || addr + len <= vma->vm_start))
82904+ if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
82905 return addr;
82906 }
82907
82908@@ -1872,6 +2145,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82909 info.low_limit = PAGE_SIZE;
82910 info.high_limit = mm->mmap_base;
82911 info.align_mask = 0;
82912+ info.threadstack_offset = offset;
82913 addr = vm_unmapped_area(&info);
82914
82915 /*
82916@@ -1884,6 +2158,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82917 VM_BUG_ON(addr != -ENOMEM);
82918 info.flags = 0;
82919 info.low_limit = TASK_UNMAPPED_BASE;
82920+
82921+#ifdef CONFIG_PAX_RANDMMAP
82922+ if (mm->pax_flags & MF_PAX_RANDMMAP)
82923+ info.low_limit += mm->delta_mmap;
82924+#endif
82925+
82926 info.high_limit = TASK_SIZE;
82927 addr = vm_unmapped_area(&info);
82928 }
82929@@ -1894,6 +2174,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
82930
82931 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82932 {
82933+
82934+#ifdef CONFIG_PAX_SEGMEXEC
82935+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
82936+ return;
82937+#endif
82938+
82939 /*
82940 * Is this a new hole at the highest possible address?
82941 */
82942@@ -1901,8 +2187,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
82943 mm->free_area_cache = addr;
82944
82945 /* dont allow allocations above current base */
82946- if (mm->free_area_cache > mm->mmap_base)
82947+ if (mm->free_area_cache > mm->mmap_base) {
82948 mm->free_area_cache = mm->mmap_base;
82949+ mm->cached_hole_size = ~0UL;
82950+ }
82951 }
82952
82953 unsigned long
82954@@ -2001,6 +2289,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
82955 return vma;
82956 }
82957
82958+#ifdef CONFIG_PAX_SEGMEXEC
82959+struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
82960+{
82961+ struct vm_area_struct *vma_m;
82962+
82963+ BUG_ON(!vma || vma->vm_start >= vma->vm_end);
82964+ if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
82965+ BUG_ON(vma->vm_mirror);
82966+ return NULL;
82967+ }
82968+ BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
82969+ vma_m = vma->vm_mirror;
82970+ BUG_ON(!vma_m || vma_m->vm_mirror != vma);
82971+ BUG_ON(vma->vm_file != vma_m->vm_file);
82972+ BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
82973+ BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
82974+ BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
82975+ BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
82976+ return vma_m;
82977+}
82978+#endif
82979+
82980 /*
82981 * Verify that the stack growth is acceptable and
82982 * update accounting. This is shared with both the
82983@@ -2017,6 +2327,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82984 return -ENOMEM;
82985
82986 /* Stack limit test */
82987+ gr_learn_resource(current, RLIMIT_STACK, size, 1);
82988 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
82989 return -ENOMEM;
82990
82991@@ -2027,6 +2338,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
82992 locked = mm->locked_vm + grow;
82993 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
82994 limit >>= PAGE_SHIFT;
82995+ gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
82996 if (locked > limit && !capable(CAP_IPC_LOCK))
82997 return -ENOMEM;
82998 }
82999@@ -2056,37 +2368,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
83000 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
83001 * vma is the last one with address > vma->vm_end. Have to extend vma.
83002 */
83003+#ifndef CONFIG_IA64
83004+static
83005+#endif
83006 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83007 {
83008 int error;
83009+ bool locknext;
83010
83011 if (!(vma->vm_flags & VM_GROWSUP))
83012 return -EFAULT;
83013
83014+ /* Also guard against wrapping around to address 0. */
83015+ if (address < PAGE_ALIGN(address+1))
83016+ address = PAGE_ALIGN(address+1);
83017+ else
83018+ return -ENOMEM;
83019+
83020 /*
83021 * We must make sure the anon_vma is allocated
83022 * so that the anon_vma locking is not a noop.
83023 */
83024 if (unlikely(anon_vma_prepare(vma)))
83025 return -ENOMEM;
83026+ locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
83027+ if (locknext && anon_vma_prepare(vma->vm_next))
83028+ return -ENOMEM;
83029 vma_lock_anon_vma(vma);
83030+ if (locknext)
83031+ vma_lock_anon_vma(vma->vm_next);
83032
83033 /*
83034 * vma->vm_start/vm_end cannot change under us because the caller
83035 * is required to hold the mmap_sem in read mode. We need the
83036- * anon_vma lock to serialize against concurrent expand_stacks.
83037- * Also guard against wrapping around to address 0.
83038+ * anon_vma locks to serialize against concurrent expand_stacks
83039+ * and expand_upwards.
83040 */
83041- if (address < PAGE_ALIGN(address+4))
83042- address = PAGE_ALIGN(address+4);
83043- else {
83044- vma_unlock_anon_vma(vma);
83045- return -ENOMEM;
83046- }
83047 error = 0;
83048
83049 /* Somebody else might have raced and expanded it already */
83050- if (address > vma->vm_end) {
83051+ 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)
83052+ error = -ENOMEM;
83053+ else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
83054 unsigned long size, grow;
83055
83056 size = address - vma->vm_start;
83057@@ -2121,6 +2444,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
83058 }
83059 }
83060 }
83061+ if (locknext)
83062+ vma_unlock_anon_vma(vma->vm_next);
83063 vma_unlock_anon_vma(vma);
83064 khugepaged_enter_vma_merge(vma);
83065 validate_mm(vma->vm_mm);
83066@@ -2135,6 +2460,8 @@ int expand_downwards(struct vm_area_struct *vma,
83067 unsigned long address)
83068 {
83069 int error;
83070+ bool lockprev = false;
83071+ struct vm_area_struct *prev;
83072
83073 /*
83074 * We must make sure the anon_vma is allocated
83075@@ -2148,6 +2475,15 @@ int expand_downwards(struct vm_area_struct *vma,
83076 if (error)
83077 return error;
83078
83079+ prev = vma->vm_prev;
83080+#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
83081+ lockprev = prev && (prev->vm_flags & VM_GROWSUP);
83082+#endif
83083+ if (lockprev && anon_vma_prepare(prev))
83084+ return -ENOMEM;
83085+ if (lockprev)
83086+ vma_lock_anon_vma(prev);
83087+
83088 vma_lock_anon_vma(vma);
83089
83090 /*
83091@@ -2157,9 +2493,17 @@ int expand_downwards(struct vm_area_struct *vma,
83092 */
83093
83094 /* Somebody else might have raced and expanded it already */
83095- if (address < vma->vm_start) {
83096+ if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
83097+ error = -ENOMEM;
83098+ else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
83099 unsigned long size, grow;
83100
83101+#ifdef CONFIG_PAX_SEGMEXEC
83102+ struct vm_area_struct *vma_m;
83103+
83104+ vma_m = pax_find_mirror_vma(vma);
83105+#endif
83106+
83107 size = vma->vm_end - address;
83108 grow = (vma->vm_start - address) >> PAGE_SHIFT;
83109
83110@@ -2184,13 +2528,27 @@ int expand_downwards(struct vm_area_struct *vma,
83111 vma->vm_pgoff -= grow;
83112 anon_vma_interval_tree_post_update_vma(vma);
83113 vma_gap_update(vma);
83114+
83115+#ifdef CONFIG_PAX_SEGMEXEC
83116+ if (vma_m) {
83117+ anon_vma_interval_tree_pre_update_vma(vma_m);
83118+ vma_m->vm_start -= grow << PAGE_SHIFT;
83119+ vma_m->vm_pgoff -= grow;
83120+ anon_vma_interval_tree_post_update_vma(vma_m);
83121+ vma_gap_update(vma_m);
83122+ }
83123+#endif
83124+
83125 spin_unlock(&vma->vm_mm->page_table_lock);
83126
83127+ track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
83128 perf_event_mmap(vma);
83129 }
83130 }
83131 }
83132 vma_unlock_anon_vma(vma);
83133+ if (lockprev)
83134+ vma_unlock_anon_vma(prev);
83135 khugepaged_enter_vma_merge(vma);
83136 validate_mm(vma->vm_mm);
83137 return error;
83138@@ -2288,6 +2646,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
83139 do {
83140 long nrpages = vma_pages(vma);
83141
83142+#ifdef CONFIG_PAX_SEGMEXEC
83143+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
83144+ vma = remove_vma(vma);
83145+ continue;
83146+ }
83147+#endif
83148+
83149 if (vma->vm_flags & VM_ACCOUNT)
83150 nr_accounted += nrpages;
83151 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
83152@@ -2333,6 +2698,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
83153 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
83154 vma->vm_prev = NULL;
83155 do {
83156+
83157+#ifdef CONFIG_PAX_SEGMEXEC
83158+ if (vma->vm_mirror) {
83159+ BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
83160+ vma->vm_mirror->vm_mirror = NULL;
83161+ vma->vm_mirror->vm_flags &= ~VM_EXEC;
83162+ vma->vm_mirror = NULL;
83163+ }
83164+#endif
83165+
83166 vma_rb_erase(vma, &mm->mm_rb);
83167 mm->map_count--;
83168 tail_vma = vma;
83169@@ -2364,14 +2739,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83170 struct vm_area_struct *new;
83171 int err = -ENOMEM;
83172
83173+#ifdef CONFIG_PAX_SEGMEXEC
83174+ struct vm_area_struct *vma_m, *new_m = NULL;
83175+ unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
83176+#endif
83177+
83178 if (is_vm_hugetlb_page(vma) && (addr &
83179 ~(huge_page_mask(hstate_vma(vma)))))
83180 return -EINVAL;
83181
83182+#ifdef CONFIG_PAX_SEGMEXEC
83183+ vma_m = pax_find_mirror_vma(vma);
83184+#endif
83185+
83186 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83187 if (!new)
83188 goto out_err;
83189
83190+#ifdef CONFIG_PAX_SEGMEXEC
83191+ if (vma_m) {
83192+ new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
83193+ if (!new_m) {
83194+ kmem_cache_free(vm_area_cachep, new);
83195+ goto out_err;
83196+ }
83197+ }
83198+#endif
83199+
83200 /* most fields are the same, copy all, and then fixup */
83201 *new = *vma;
83202
83203@@ -2384,6 +2778,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83204 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
83205 }
83206
83207+#ifdef CONFIG_PAX_SEGMEXEC
83208+ if (vma_m) {
83209+ *new_m = *vma_m;
83210+ INIT_LIST_HEAD(&new_m->anon_vma_chain);
83211+ new_m->vm_mirror = new;
83212+ new->vm_mirror = new_m;
83213+
83214+ if (new_below)
83215+ new_m->vm_end = addr_m;
83216+ else {
83217+ new_m->vm_start = addr_m;
83218+ new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
83219+ }
83220+ }
83221+#endif
83222+
83223 pol = mpol_dup(vma_policy(vma));
83224 if (IS_ERR(pol)) {
83225 err = PTR_ERR(pol);
83226@@ -2406,6 +2816,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83227 else
83228 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
83229
83230+#ifdef CONFIG_PAX_SEGMEXEC
83231+ if (!err && vma_m) {
83232+ if (anon_vma_clone(new_m, vma_m))
83233+ goto out_free_mpol;
83234+
83235+ mpol_get(pol);
83236+ vma_set_policy(new_m, pol);
83237+
83238+ if (new_m->vm_file)
83239+ get_file(new_m->vm_file);
83240+
83241+ if (new_m->vm_ops && new_m->vm_ops->open)
83242+ new_m->vm_ops->open(new_m);
83243+
83244+ if (new_below)
83245+ err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
83246+ ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
83247+ else
83248+ err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
83249+
83250+ if (err) {
83251+ if (new_m->vm_ops && new_m->vm_ops->close)
83252+ new_m->vm_ops->close(new_m);
83253+ if (new_m->vm_file)
83254+ fput(new_m->vm_file);
83255+ mpol_put(pol);
83256+ }
83257+ }
83258+#endif
83259+
83260 /* Success. */
83261 if (!err)
83262 return 0;
83263@@ -2415,10 +2855,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83264 new->vm_ops->close(new);
83265 if (new->vm_file)
83266 fput(new->vm_file);
83267- unlink_anon_vmas(new);
83268 out_free_mpol:
83269 mpol_put(pol);
83270 out_free_vma:
83271+
83272+#ifdef CONFIG_PAX_SEGMEXEC
83273+ if (new_m) {
83274+ unlink_anon_vmas(new_m);
83275+ kmem_cache_free(vm_area_cachep, new_m);
83276+ }
83277+#endif
83278+
83279+ unlink_anon_vmas(new);
83280 kmem_cache_free(vm_area_cachep, new);
83281 out_err:
83282 return err;
83283@@ -2431,6 +2879,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
83284 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83285 unsigned long addr, int new_below)
83286 {
83287+
83288+#ifdef CONFIG_PAX_SEGMEXEC
83289+ if (mm->pax_flags & MF_PAX_SEGMEXEC) {
83290+ BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
83291+ if (mm->map_count >= sysctl_max_map_count-1)
83292+ return -ENOMEM;
83293+ } else
83294+#endif
83295+
83296 if (mm->map_count >= sysctl_max_map_count)
83297 return -ENOMEM;
83298
83299@@ -2442,11 +2899,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83300 * work. This now handles partial unmappings.
83301 * Jeremy Fitzhardinge <jeremy@goop.org>
83302 */
83303+#ifdef CONFIG_PAX_SEGMEXEC
83304 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83305 {
83306+ int ret = __do_munmap(mm, start, len);
83307+ if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
83308+ return ret;
83309+
83310+ return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
83311+}
83312+
83313+int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83314+#else
83315+int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83316+#endif
83317+{
83318 unsigned long end;
83319 struct vm_area_struct *vma, *prev, *last;
83320
83321+ /*
83322+ * mm->mmap_sem is required to protect against another thread
83323+ * changing the mappings in case we sleep.
83324+ */
83325+ verify_mm_writelocked(mm);
83326+
83327 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
83328 return -EINVAL;
83329
83330@@ -2521,6 +2997,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
83331 /* Fix up all other VM information */
83332 remove_vma_list(mm, vma);
83333
83334+ track_exec_limit(mm, start, end, 0UL);
83335+
83336 return 0;
83337 }
83338
83339@@ -2529,6 +3007,13 @@ int vm_munmap(unsigned long start, size_t len)
83340 int ret;
83341 struct mm_struct *mm = current->mm;
83342
83343+
83344+#ifdef CONFIG_PAX_SEGMEXEC
83345+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
83346+ (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
83347+ return -EINVAL;
83348+#endif
83349+
83350 down_write(&mm->mmap_sem);
83351 ret = do_munmap(mm, start, len);
83352 up_write(&mm->mmap_sem);
83353@@ -2542,16 +3027,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
83354 return vm_munmap(addr, len);
83355 }
83356
83357-static inline void verify_mm_writelocked(struct mm_struct *mm)
83358-{
83359-#ifdef CONFIG_DEBUG_VM
83360- if (unlikely(down_read_trylock(&mm->mmap_sem))) {
83361- WARN_ON(1);
83362- up_read(&mm->mmap_sem);
83363- }
83364-#endif
83365-}
83366-
83367 /*
83368 * this is really a simplified "do_mmap". it only handles
83369 * anonymous maps. eventually we may be able to do some
83370@@ -2565,6 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83371 struct rb_node ** rb_link, * rb_parent;
83372 pgoff_t pgoff = addr >> PAGE_SHIFT;
83373 int error;
83374+ unsigned long charged;
83375
83376 len = PAGE_ALIGN(len);
83377 if (!len)
83378@@ -2572,16 +3048,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83379
83380 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
83381
83382+#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
83383+ if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
83384+ flags &= ~VM_EXEC;
83385+
83386+#ifdef CONFIG_PAX_MPROTECT
83387+ if (mm->pax_flags & MF_PAX_MPROTECT)
83388+ flags &= ~VM_MAYEXEC;
83389+#endif
83390+
83391+ }
83392+#endif
83393+
83394 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
83395 if (error & ~PAGE_MASK)
83396 return error;
83397
83398+ charged = len >> PAGE_SHIFT;
83399+
83400 /*
83401 * mlock MCL_FUTURE?
83402 */
83403 if (mm->def_flags & VM_LOCKED) {
83404 unsigned long locked, lock_limit;
83405- locked = len >> PAGE_SHIFT;
83406+ locked = charged;
83407 locked += mm->locked_vm;
83408 lock_limit = rlimit(RLIMIT_MEMLOCK);
83409 lock_limit >>= PAGE_SHIFT;
83410@@ -2598,21 +3088,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83411 /*
83412 * Clear old maps. this also does some error checking for us
83413 */
83414- munmap_back:
83415 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
83416 if (do_munmap(mm, addr, len))
83417 return -ENOMEM;
83418- goto munmap_back;
83419+ BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
83420 }
83421
83422 /* Check against address space limits *after* clearing old maps... */
83423- if (!may_expand_vm(mm, len >> PAGE_SHIFT))
83424+ if (!may_expand_vm(mm, charged))
83425 return -ENOMEM;
83426
83427 if (mm->map_count > sysctl_max_map_count)
83428 return -ENOMEM;
83429
83430- if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
83431+ if (security_vm_enough_memory_mm(mm, charged))
83432 return -ENOMEM;
83433
83434 /* Can we just expand an old private anonymous mapping? */
83435@@ -2626,7 +3115,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83436 */
83437 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83438 if (!vma) {
83439- vm_unacct_memory(len >> PAGE_SHIFT);
83440+ vm_unacct_memory(charged);
83441 return -ENOMEM;
83442 }
83443
83444@@ -2640,9 +3129,10 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
83445 vma_link(mm, vma, prev, rb_link, rb_parent);
83446 out:
83447 perf_event_mmap(vma);
83448- mm->total_vm += len >> PAGE_SHIFT;
83449+ mm->total_vm += charged;
83450 if (flags & VM_LOCKED)
83451- mm->locked_vm += (len >> PAGE_SHIFT);
83452+ mm->locked_vm += charged;
83453+ track_exec_limit(mm, addr, addr + len, flags);
83454 return addr;
83455 }
83456
83457@@ -2704,6 +3194,7 @@ void exit_mmap(struct mm_struct *mm)
83458 while (vma) {
83459 if (vma->vm_flags & VM_ACCOUNT)
83460 nr_accounted += vma_pages(vma);
83461+ vma->vm_mirror = NULL;
83462 vma = remove_vma(vma);
83463 }
83464 vm_unacct_memory(nr_accounted);
83465@@ -2720,6 +3211,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83466 struct vm_area_struct *prev;
83467 struct rb_node **rb_link, *rb_parent;
83468
83469+#ifdef CONFIG_PAX_SEGMEXEC
83470+ struct vm_area_struct *vma_m = NULL;
83471+#endif
83472+
83473+ if (security_mmap_addr(vma->vm_start))
83474+ return -EPERM;
83475+
83476 /*
83477 * The vm_pgoff of a purely anonymous vma should be irrelevant
83478 * until its first write fault, when page's anon_vma and index
83479@@ -2743,7 +3241,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
83480 security_vm_enough_memory_mm(mm, vma_pages(vma)))
83481 return -ENOMEM;
83482
83483+#ifdef CONFIG_PAX_SEGMEXEC
83484+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
83485+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83486+ if (!vma_m)
83487+ return -ENOMEM;
83488+ }
83489+#endif
83490+
83491 vma_link(mm, vma, prev, rb_link, rb_parent);
83492+
83493+#ifdef CONFIG_PAX_SEGMEXEC
83494+ if (vma_m)
83495+ BUG_ON(pax_mirror_vma(vma_m, vma));
83496+#endif
83497+
83498 return 0;
83499 }
83500
83501@@ -2763,6 +3275,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83502 struct mempolicy *pol;
83503 bool faulted_in_anon_vma = true;
83504
83505+ BUG_ON(vma->vm_mirror);
83506+
83507 /*
83508 * If anonymous vma has not yet been faulted, update new pgoff
83509 * to match new location, to increase its chance of merging.
83510@@ -2829,6 +3343,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
83511 return NULL;
83512 }
83513
83514+#ifdef CONFIG_PAX_SEGMEXEC
83515+long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
83516+{
83517+ struct vm_area_struct *prev_m;
83518+ struct rb_node **rb_link_m, *rb_parent_m;
83519+ struct mempolicy *pol_m;
83520+
83521+ BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
83522+ BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
83523+ BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
83524+ *vma_m = *vma;
83525+ INIT_LIST_HEAD(&vma_m->anon_vma_chain);
83526+ if (anon_vma_clone(vma_m, vma))
83527+ return -ENOMEM;
83528+ pol_m = vma_policy(vma_m);
83529+ mpol_get(pol_m);
83530+ vma_set_policy(vma_m, pol_m);
83531+ vma_m->vm_start += SEGMEXEC_TASK_SIZE;
83532+ vma_m->vm_end += SEGMEXEC_TASK_SIZE;
83533+ vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
83534+ vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
83535+ if (vma_m->vm_file)
83536+ get_file(vma_m->vm_file);
83537+ if (vma_m->vm_ops && vma_m->vm_ops->open)
83538+ vma_m->vm_ops->open(vma_m);
83539+ BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
83540+ vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
83541+ vma_m->vm_mirror = vma;
83542+ vma->vm_mirror = vma_m;
83543+ return 0;
83544+}
83545+#endif
83546+
83547 /*
83548 * Return true if the calling process may expand its vm space by the passed
83549 * number of pages
83550@@ -2840,6 +3387,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
83551
83552 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
83553
83554+ gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
83555 if (cur + npages > lim)
83556 return 0;
83557 return 1;
83558@@ -2910,6 +3458,22 @@ int install_special_mapping(struct mm_struct *mm,
83559 vma->vm_start = addr;
83560 vma->vm_end = addr + len;
83561
83562+#ifdef CONFIG_PAX_MPROTECT
83563+ if (mm->pax_flags & MF_PAX_MPROTECT) {
83564+#ifndef CONFIG_PAX_MPROTECT_COMPAT
83565+ if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
83566+ return -EPERM;
83567+ if (!(vm_flags & VM_EXEC))
83568+ vm_flags &= ~VM_MAYEXEC;
83569+#else
83570+ if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
83571+ vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
83572+#endif
83573+ else
83574+ vm_flags &= ~VM_MAYWRITE;
83575+ }
83576+#endif
83577+
83578 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
83579 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
83580
83581diff --git a/mm/mprotect.c b/mm/mprotect.c
83582index 94722a4..07d9926 100644
83583--- a/mm/mprotect.c
83584+++ b/mm/mprotect.c
83585@@ -23,10 +23,18 @@
83586 #include <linux/mmu_notifier.h>
83587 #include <linux/migrate.h>
83588 #include <linux/perf_event.h>
83589+#include <linux/sched/sysctl.h>
83590+
83591+#ifdef CONFIG_PAX_MPROTECT
83592+#include <linux/elf.h>
83593+#include <linux/binfmts.h>
83594+#endif
83595+
83596 #include <asm/uaccess.h>
83597 #include <asm/pgtable.h>
83598 #include <asm/cacheflush.h>
83599 #include <asm/tlbflush.h>
83600+#include <asm/mmu_context.h>
83601
83602 #ifndef pgprot_modify
83603 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
83604@@ -233,6 +241,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
83605 return pages;
83606 }
83607
83608+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83609+/* called while holding the mmap semaphor for writing except stack expansion */
83610+void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
83611+{
83612+ unsigned long oldlimit, newlimit = 0UL;
83613+
83614+ if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
83615+ return;
83616+
83617+ spin_lock(&mm->page_table_lock);
83618+ oldlimit = mm->context.user_cs_limit;
83619+ if ((prot & VM_EXEC) && oldlimit < end)
83620+ /* USER_CS limit moved up */
83621+ newlimit = end;
83622+ else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
83623+ /* USER_CS limit moved down */
83624+ newlimit = start;
83625+
83626+ if (newlimit) {
83627+ mm->context.user_cs_limit = newlimit;
83628+
83629+#ifdef CONFIG_SMP
83630+ wmb();
83631+ cpus_clear(mm->context.cpu_user_cs_mask);
83632+ cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
83633+#endif
83634+
83635+ set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
83636+ }
83637+ spin_unlock(&mm->page_table_lock);
83638+ if (newlimit == end) {
83639+ struct vm_area_struct *vma = find_vma(mm, oldlimit);
83640+
83641+ for (; vma && vma->vm_start < end; vma = vma->vm_next)
83642+ if (is_vm_hugetlb_page(vma))
83643+ hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
83644+ else
83645+ change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
83646+ }
83647+}
83648+#endif
83649+
83650 int
83651 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83652 unsigned long start, unsigned long end, unsigned long newflags)
83653@@ -245,11 +295,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83654 int error;
83655 int dirty_accountable = 0;
83656
83657+#ifdef CONFIG_PAX_SEGMEXEC
83658+ struct vm_area_struct *vma_m = NULL;
83659+ unsigned long start_m, end_m;
83660+
83661+ start_m = start + SEGMEXEC_TASK_SIZE;
83662+ end_m = end + SEGMEXEC_TASK_SIZE;
83663+#endif
83664+
83665 if (newflags == oldflags) {
83666 *pprev = vma;
83667 return 0;
83668 }
83669
83670+ if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
83671+ struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
83672+
83673+ if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
83674+ return -ENOMEM;
83675+
83676+ if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
83677+ return -ENOMEM;
83678+ }
83679+
83680 /*
83681 * If we make a private mapping writable we increase our commit;
83682 * but (without finer accounting) cannot reduce our commit if we
83683@@ -266,6 +334,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
83684 }
83685 }
83686
83687+#ifdef CONFIG_PAX_SEGMEXEC
83688+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
83689+ if (start != vma->vm_start) {
83690+ error = split_vma(mm, vma, start, 1);
83691+ if (error)
83692+ goto fail;
83693+ BUG_ON(!*pprev || (*pprev)->vm_next == vma);
83694+ *pprev = (*pprev)->vm_next;
83695+ }
83696+
83697+ if (end != vma->vm_end) {
83698+ error = split_vma(mm, vma, end, 0);
83699+ if (error)
83700+ goto fail;
83701+ }
83702+
83703+ if (pax_find_mirror_vma(vma)) {
83704+ error = __do_munmap(mm, start_m, end_m - start_m);
83705+ if (error)
83706+ goto fail;
83707+ } else {
83708+ vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
83709+ if (!vma_m) {
83710+ error = -ENOMEM;
83711+ goto fail;
83712+ }
83713+ vma->vm_flags = newflags;
83714+ error = pax_mirror_vma(vma_m, vma);
83715+ if (error) {
83716+ vma->vm_flags = oldflags;
83717+ goto fail;
83718+ }
83719+ }
83720+ }
83721+#endif
83722+
83723 /*
83724 * First try to merge with previous and/or next vma.
83725 */
83726@@ -296,9 +400,21 @@ success:
83727 * vm_flags and vm_page_prot are protected by the mmap_sem
83728 * held in write mode.
83729 */
83730+
83731+#ifdef CONFIG_PAX_SEGMEXEC
83732+ if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
83733+ pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
83734+#endif
83735+
83736 vma->vm_flags = newflags;
83737+
83738+#ifdef CONFIG_PAX_MPROTECT
83739+ if (mm->binfmt && mm->binfmt->handle_mprotect)
83740+ mm->binfmt->handle_mprotect(vma, newflags);
83741+#endif
83742+
83743 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
83744- vm_get_page_prot(newflags));
83745+ vm_get_page_prot(vma->vm_flags));
83746
83747 if (vma_wants_writenotify(vma)) {
83748 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
83749@@ -337,6 +453,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83750 end = start + len;
83751 if (end <= start)
83752 return -ENOMEM;
83753+
83754+#ifdef CONFIG_PAX_SEGMEXEC
83755+ if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
83756+ if (end > SEGMEXEC_TASK_SIZE)
83757+ return -EINVAL;
83758+ } else
83759+#endif
83760+
83761+ if (end > TASK_SIZE)
83762+ return -EINVAL;
83763+
83764 if (!arch_validate_prot(prot))
83765 return -EINVAL;
83766
83767@@ -344,7 +471,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83768 /*
83769 * Does the application expect PROT_READ to imply PROT_EXEC:
83770 */
83771- if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
83772+ if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
83773 prot |= PROT_EXEC;
83774
83775 vm_flags = calc_vm_prot_bits(prot);
83776@@ -376,6 +503,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83777 if (start > vma->vm_start)
83778 prev = vma;
83779
83780+#ifdef CONFIG_PAX_MPROTECT
83781+ if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
83782+ current->mm->binfmt->handle_mprotect(vma, vm_flags);
83783+#endif
83784+
83785 for (nstart = start ; ; ) {
83786 unsigned long newflags;
83787
83788@@ -386,6 +518,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83789
83790 /* newflags >> 4 shift VM_MAY% in place of VM_% */
83791 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
83792+ if (prot & (PROT_WRITE | PROT_EXEC))
83793+ gr_log_rwxmprotect(vma->vm_file);
83794+
83795+ error = -EACCES;
83796+ goto out;
83797+ }
83798+
83799+ if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
83800 error = -EACCES;
83801 goto out;
83802 }
83803@@ -400,6 +540,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
83804 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
83805 if (error)
83806 goto out;
83807+
83808+ track_exec_limit(current->mm, nstart, tmp, vm_flags);
83809+
83810 nstart = tmp;
83811
83812 if (nstart < prev->vm_end)
83813diff --git a/mm/mremap.c b/mm/mremap.c
83814index 463a257..c0c7a92 100644
83815--- a/mm/mremap.c
83816+++ b/mm/mremap.c
83817@@ -126,6 +126,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
83818 continue;
83819 pte = ptep_get_and_clear(mm, old_addr, old_pte);
83820 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
83821+
83822+#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
83823+ if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
83824+ pte = pte_exprotect(pte);
83825+#endif
83826+
83827 set_pte_at(mm, new_addr, new_pte, pte);
83828 }
83829
83830@@ -318,6 +324,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
83831 if (is_vm_hugetlb_page(vma))
83832 goto Einval;
83833
83834+#ifdef CONFIG_PAX_SEGMEXEC
83835+ if (pax_find_mirror_vma(vma))
83836+ goto Einval;
83837+#endif
83838+
83839 /* We can't remap across vm area boundaries */
83840 if (old_len > vma->vm_end - addr)
83841 goto Efault;
83842@@ -373,20 +384,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
83843 unsigned long ret = -EINVAL;
83844 unsigned long charged = 0;
83845 unsigned long map_flags;
83846+ unsigned long pax_task_size = TASK_SIZE;
83847
83848 if (new_addr & ~PAGE_MASK)
83849 goto out;
83850
83851- if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
83852+#ifdef CONFIG_PAX_SEGMEXEC
83853+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83854+ pax_task_size = SEGMEXEC_TASK_SIZE;
83855+#endif
83856+
83857+ pax_task_size -= PAGE_SIZE;
83858+
83859+ if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
83860 goto out;
83861
83862 /* Check if the location we're moving into overlaps the
83863 * old location at all, and fail if it does.
83864 */
83865- if ((new_addr <= addr) && (new_addr+new_len) > addr)
83866- goto out;
83867-
83868- if ((addr <= new_addr) && (addr+old_len) > new_addr)
83869+ if (addr + old_len > new_addr && new_addr + new_len > addr)
83870 goto out;
83871
83872 ret = do_munmap(mm, new_addr, new_len);
83873@@ -455,6 +471,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83874 unsigned long ret = -EINVAL;
83875 unsigned long charged = 0;
83876 bool locked = false;
83877+ unsigned long pax_task_size = TASK_SIZE;
83878
83879 down_write(&current->mm->mmap_sem);
83880
83881@@ -475,6 +492,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83882 if (!new_len)
83883 goto out;
83884
83885+#ifdef CONFIG_PAX_SEGMEXEC
83886+ if (mm->pax_flags & MF_PAX_SEGMEXEC)
83887+ pax_task_size = SEGMEXEC_TASK_SIZE;
83888+#endif
83889+
83890+ pax_task_size -= PAGE_SIZE;
83891+
83892+ if (new_len > pax_task_size || addr > pax_task_size-new_len ||
83893+ old_len > pax_task_size || addr > pax_task_size-old_len)
83894+ goto out;
83895+
83896 if (flags & MREMAP_FIXED) {
83897 if (flags & MREMAP_MAYMOVE)
83898 ret = mremap_to(addr, old_len, new_addr, new_len,
83899@@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83900 new_addr = addr;
83901 }
83902 ret = addr;
83903+ track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
83904 goto out;
83905 }
83906 }
83907@@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
83908 goto out;
83909 }
83910
83911+ map_flags = vma->vm_flags;
83912 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
83913+ if (!(ret & ~PAGE_MASK)) {
83914+ track_exec_limit(current->mm, addr, addr + old_len, 0UL);
83915+ track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
83916+ }
83917 }
83918 out:
83919 if (ret & ~PAGE_MASK)
83920diff --git a/mm/nommu.c b/mm/nommu.c
83921index e001768..9b52b30 100644
83922--- a/mm/nommu.c
83923+++ b/mm/nommu.c
83924@@ -63,7 +63,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
83925 int sysctl_overcommit_ratio = 50; /* default is 50% */
83926 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
83927 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
83928-int heap_stack_gap = 0;
83929
83930 atomic_long_t mmap_pages_allocated;
83931
83932@@ -841,15 +840,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
83933 EXPORT_SYMBOL(find_vma);
83934
83935 /*
83936- * find a VMA
83937- * - we don't extend stack VMAs under NOMMU conditions
83938- */
83939-struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
83940-{
83941- return find_vma(mm, addr);
83942-}
83943-
83944-/*
83945 * expand a stack to a given address
83946 * - not supported under NOMMU conditions
83947 */
83948@@ -1560,6 +1550,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
83949
83950 /* most fields are the same, copy all, and then fixup */
83951 *new = *vma;
83952+ INIT_LIST_HEAD(&new->anon_vma_chain);
83953 *region = *vma->vm_region;
83954 new->vm_region = region;
83955
83956@@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
83957 }
83958 EXPORT_SYMBOL(generic_file_remap_pages);
83959
83960-static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83961- unsigned long addr, void *buf, int len, int write)
83962+static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83963+ unsigned long addr, void *buf, size_t len, int write)
83964 {
83965 struct vm_area_struct *vma;
83966
83967@@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
83968 *
83969 * The caller must hold a reference on @mm.
83970 */
83971-int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83972- void *buf, int len, int write)
83973+ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
83974+ void *buf, size_t len, int write)
83975 {
83976 return __access_remote_vm(NULL, mm, addr, buf, len, write);
83977 }
83978@@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
83979 * Access another process' address space.
83980 * - source/target buffer must be kernel space
83981 */
83982-int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
83983+ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
83984 {
83985 struct mm_struct *mm;
83986
83987diff --git a/mm/page-writeback.c b/mm/page-writeback.c
83988index efe6814..64b4701 100644
83989--- a/mm/page-writeback.c
83990+++ b/mm/page-writeback.c
83991@@ -659,7 +659,7 @@ unsigned long bdi_dirty_limit(struct backing_dev_info *bdi, unsigned long dirty)
83992 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
83993 * - the bdi dirty thresh drops quickly due to change of JBOD workload
83994 */
83995-static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
83996+static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
83997 unsigned long thresh,
83998 unsigned long bg_thresh,
83999 unsigned long dirty,
84000@@ -1634,7 +1634,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
84001 }
84002 }
84003
84004-static struct notifier_block __cpuinitdata ratelimit_nb = {
84005+static struct notifier_block ratelimit_nb = {
84006 .notifier_call = ratelimit_handler,
84007 .next = NULL,
84008 };
84009diff --git a/mm/page_alloc.c b/mm/page_alloc.c
84010index 0d4fef2..8870335 100644
84011--- a/mm/page_alloc.c
84012+++ b/mm/page_alloc.c
84013@@ -59,6 +59,7 @@
84014 #include <linux/migrate.h>
84015 #include <linux/page-debug-flags.h>
84016 #include <linux/sched/rt.h>
84017+#include <linux/random.h>
84018
84019 #include <asm/tlbflush.h>
84020 #include <asm/div64.h>
84021@@ -344,7 +345,7 @@ out:
84022 * This usage means that zero-order pages may not be compound.
84023 */
84024
84025-static void free_compound_page(struct page *page)
84026+void free_compound_page(struct page *page)
84027 {
84028 __free_pages_ok(page, compound_order(page));
84029 }
84030@@ -701,6 +702,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84031 int i;
84032 int bad = 0;
84033
84034+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84035+ unsigned long index = 1UL << order;
84036+#endif
84037+
84038 trace_mm_page_free(page, order);
84039 kmemcheck_free_shadow(page, order);
84040
84041@@ -716,6 +721,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
84042 debug_check_no_obj_freed(page_address(page),
84043 PAGE_SIZE << order);
84044 }
84045+
84046+#ifdef CONFIG_PAX_MEMORY_SANITIZE
84047+ for (; index; --index)
84048+ sanitize_highpage(page + index - 1);
84049+#endif
84050+
84051 arch_free_page(page, order);
84052 kernel_map_pages(page, 1 << order, 0);
84053
84054@@ -738,6 +749,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
84055 local_irq_restore(flags);
84056 }
84057
84058+#ifdef CONFIG_PAX_LATENT_ENTROPY
84059+bool __meminitdata extra_latent_entropy;
84060+
84061+static int __init setup_pax_extra_latent_entropy(char *str)
84062+{
84063+ extra_latent_entropy = true;
84064+ return 0;
84065+}
84066+early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
84067+
84068+volatile u64 latent_entropy;
84069+#endif
84070+
84071 /*
84072 * Read access to zone->managed_pages is safe because it's unsigned long,
84073 * but we still need to serialize writers. Currently all callers of
84074@@ -760,6 +784,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
84075 set_page_count(p, 0);
84076 }
84077
84078+#ifdef CONFIG_PAX_LATENT_ENTROPY
84079+ if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
84080+ u64 hash = 0;
84081+ size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
84082+ const u64 *data = lowmem_page_address(page);
84083+
84084+ for (index = 0; index < end; index++)
84085+ hash ^= hash + data[index];
84086+ latent_entropy ^= hash;
84087+ add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
84088+ }
84089+#endif
84090+
84091 page_zone(page)->managed_pages += 1 << order;
84092 set_page_refcounted(page);
84093 __free_pages(page, order);
84094@@ -869,8 +906,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
84095 arch_alloc_page(page, order);
84096 kernel_map_pages(page, 1 << order, 1);
84097
84098+#ifndef CONFIG_PAX_MEMORY_SANITIZE
84099 if (gfp_flags & __GFP_ZERO)
84100 prep_zero_page(page, order, gfp_flags);
84101+#endif
84102
84103 if (order && (gfp_flags & __GFP_COMP))
84104 prep_compound_page(page, order);
84105diff --git a/mm/page_io.c b/mm/page_io.c
84106index 6182870..4bba6a2 100644
84107--- a/mm/page_io.c
84108+++ b/mm/page_io.c
84109@@ -205,7 +205,7 @@ int swap_writepage(struct page *page, struct writeback_control *wbc)
84110 struct file *swap_file = sis->swap_file;
84111 struct address_space *mapping = swap_file->f_mapping;
84112 struct iovec iov = {
84113- .iov_base = kmap(page),
84114+ .iov_base = (void __force_user *)kmap(page),
84115 .iov_len = PAGE_SIZE,
84116 };
84117
84118diff --git a/mm/percpu.c b/mm/percpu.c
84119index 8c8e08f..73a5cda 100644
84120--- a/mm/percpu.c
84121+++ b/mm/percpu.c
84122@@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
84123 static unsigned int pcpu_high_unit_cpu __read_mostly;
84124
84125 /* the address of the first chunk which starts with the kernel static area */
84126-void *pcpu_base_addr __read_mostly;
84127+void *pcpu_base_addr __read_only;
84128 EXPORT_SYMBOL_GPL(pcpu_base_addr);
84129
84130 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
84131diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
84132index fd26d04..0cea1b0 100644
84133--- a/mm/process_vm_access.c
84134+++ b/mm/process_vm_access.c
84135@@ -13,6 +13,7 @@
84136 #include <linux/uio.h>
84137 #include <linux/sched.h>
84138 #include <linux/highmem.h>
84139+#include <linux/security.h>
84140 #include <linux/ptrace.h>
84141 #include <linux/slab.h>
84142 #include <linux/syscalls.h>
84143@@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84144 size_t iov_l_curr_offset = 0;
84145 ssize_t iov_len;
84146
84147+ return -ENOSYS; // PaX: until properly audited
84148+
84149 /*
84150 * Work out how many pages of struct pages we're going to need
84151 * when eventually calling get_user_pages
84152 */
84153 for (i = 0; i < riovcnt; i++) {
84154 iov_len = rvec[i].iov_len;
84155- if (iov_len > 0) {
84156- nr_pages_iov = ((unsigned long)rvec[i].iov_base
84157- + iov_len)
84158- / PAGE_SIZE - (unsigned long)rvec[i].iov_base
84159- / PAGE_SIZE + 1;
84160- nr_pages = max(nr_pages, nr_pages_iov);
84161- }
84162+ if (iov_len <= 0)
84163+ continue;
84164+ nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
84165+ (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
84166+ nr_pages = max(nr_pages, nr_pages_iov);
84167 }
84168
84169 if (nr_pages == 0)
84170@@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
84171 goto free_proc_pages;
84172 }
84173
84174+ if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
84175+ rc = -EPERM;
84176+ goto put_task_struct;
84177+ }
84178+
84179 mm = mm_access(task, PTRACE_MODE_ATTACH);
84180 if (!mm || IS_ERR(mm)) {
84181 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
84182diff --git a/mm/rmap.c b/mm/rmap.c
84183index 807c96b..0e05279 100644
84184--- a/mm/rmap.c
84185+++ b/mm/rmap.c
84186@@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84187 struct anon_vma *anon_vma = vma->anon_vma;
84188 struct anon_vma_chain *avc;
84189
84190+#ifdef CONFIG_PAX_SEGMEXEC
84191+ struct anon_vma_chain *avc_m = NULL;
84192+#endif
84193+
84194 might_sleep();
84195 if (unlikely(!anon_vma)) {
84196 struct mm_struct *mm = vma->vm_mm;
84197@@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84198 if (!avc)
84199 goto out_enomem;
84200
84201+#ifdef CONFIG_PAX_SEGMEXEC
84202+ avc_m = anon_vma_chain_alloc(GFP_KERNEL);
84203+ if (!avc_m)
84204+ goto out_enomem_free_avc;
84205+#endif
84206+
84207 anon_vma = find_mergeable_anon_vma(vma);
84208 allocated = NULL;
84209 if (!anon_vma) {
84210@@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84211 /* page_table_lock to protect against threads */
84212 spin_lock(&mm->page_table_lock);
84213 if (likely(!vma->anon_vma)) {
84214+
84215+#ifdef CONFIG_PAX_SEGMEXEC
84216+ struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
84217+
84218+ if (vma_m) {
84219+ BUG_ON(vma_m->anon_vma);
84220+ vma_m->anon_vma = anon_vma;
84221+ anon_vma_chain_link(vma_m, avc_m, anon_vma);
84222+ avc_m = NULL;
84223+ }
84224+#endif
84225+
84226 vma->anon_vma = anon_vma;
84227 anon_vma_chain_link(vma, avc, anon_vma);
84228 allocated = NULL;
84229@@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
84230
84231 if (unlikely(allocated))
84232 put_anon_vma(allocated);
84233+
84234+#ifdef CONFIG_PAX_SEGMEXEC
84235+ if (unlikely(avc_m))
84236+ anon_vma_chain_free(avc_m);
84237+#endif
84238+
84239 if (unlikely(avc))
84240 anon_vma_chain_free(avc);
84241 }
84242 return 0;
84243
84244 out_enomem_free_avc:
84245+
84246+#ifdef CONFIG_PAX_SEGMEXEC
84247+ if (avc_m)
84248+ anon_vma_chain_free(avc_m);
84249+#endif
84250+
84251 anon_vma_chain_free(avc);
84252 out_enomem:
84253 return -ENOMEM;
84254@@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
84255 * Attach the anon_vmas from src to dst.
84256 * Returns 0 on success, -ENOMEM on failure.
84257 */
84258-int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84259+int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
84260 {
84261 struct anon_vma_chain *avc, *pavc;
84262 struct anon_vma *root = NULL;
84263@@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
84264 * the corresponding VMA in the parent process is attached to.
84265 * Returns 0 on success, non-zero on failure.
84266 */
84267-int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
84268+int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
84269 {
84270 struct anon_vma_chain *avc;
84271 struct anon_vma *anon_vma;
84272diff --git a/mm/shmem.c b/mm/shmem.c
84273index 1c44af7..cefe9a6 100644
84274--- a/mm/shmem.c
84275+++ b/mm/shmem.c
84276@@ -31,7 +31,7 @@
84277 #include <linux/export.h>
84278 #include <linux/swap.h>
84279
84280-static struct vfsmount *shm_mnt;
84281+struct vfsmount *shm_mnt;
84282
84283 #ifdef CONFIG_SHMEM
84284 /*
84285@@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
84286 #define BOGO_DIRENT_SIZE 20
84287
84288 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
84289-#define SHORT_SYMLINK_LEN 128
84290+#define SHORT_SYMLINK_LEN 64
84291
84292 /*
84293 * shmem_fallocate and shmem_writepage communicate via inode->i_private
84294@@ -2201,6 +2201,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
84295 static int shmem_xattr_validate(const char *name)
84296 {
84297 struct { const char *prefix; size_t len; } arr[] = {
84298+
84299+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84300+ { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
84301+#endif
84302+
84303 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
84304 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
84305 };
84306@@ -2256,6 +2261,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
84307 if (err)
84308 return err;
84309
84310+#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
84311+ if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
84312+ if (strcmp(name, XATTR_NAME_PAX_FLAGS))
84313+ return -EOPNOTSUPP;
84314+ if (size > 8)
84315+ return -EINVAL;
84316+ }
84317+#endif
84318+
84319 return simple_xattr_set(&info->xattrs, name, value, size, flags);
84320 }
84321
84322@@ -2568,8 +2582,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
84323 int err = -ENOMEM;
84324
84325 /* Round up to L1_CACHE_BYTES to resist false sharing */
84326- sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
84327- L1_CACHE_BYTES), GFP_KERNEL);
84328+ sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
84329 if (!sbinfo)
84330 return -ENOMEM;
84331
84332diff --git a/mm/slab.c b/mm/slab.c
84333index 856e4a1..fafb820 100644
84334--- a/mm/slab.c
84335+++ b/mm/slab.c
84336@@ -306,7 +306,7 @@ struct kmem_list3 {
84337 * Need this for bootstrapping a per node allocator.
84338 */
84339 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
84340-static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
84341+static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
84342 #define CACHE_CACHE 0
84343 #define SIZE_AC MAX_NUMNODES
84344 #define SIZE_L3 (2 * MAX_NUMNODES)
84345@@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
84346 if ((x)->max_freeable < i) \
84347 (x)->max_freeable = i; \
84348 } while (0)
84349-#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
84350-#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
84351-#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
84352-#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
84353+#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
84354+#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
84355+#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
84356+#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
84357 #else
84358 #define STATS_INC_ACTIVE(x) do { } while (0)
84359 #define STATS_DEC_ACTIVE(x) do { } while (0)
84360@@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
84361 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
84362 */
84363 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
84364- const struct slab *slab, void *obj)
84365+ const struct slab *slab, const void *obj)
84366 {
84367 u32 offset = (obj - slab->s_mem);
84368 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
84369@@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
84370 struct cache_names {
84371 char *name;
84372 char *name_dma;
84373+ char *name_usercopy;
84374 };
84375
84376 static struct cache_names __initdata cache_names[] = {
84377-#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
84378+#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
84379 #include <linux/kmalloc_sizes.h>
84380- {NULL,}
84381+ {NULL}
84382 #undef CACHE
84383 };
84384
84385@@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
84386 if (unlikely(gfpflags & GFP_DMA))
84387 return csizep->cs_dmacachep;
84388 #endif
84389+
84390+#ifdef CONFIG_PAX_USERCOPY_SLABS
84391+ if (unlikely(gfpflags & GFP_USERCOPY))
84392+ return csizep->cs_usercopycachep;
84393+#endif
84394+
84395 return csizep->cs_cachep;
84396 }
84397
84398@@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
84399 return notifier_from_errno(err);
84400 }
84401
84402-static struct notifier_block __cpuinitdata cpucache_notifier = {
84403+static struct notifier_block cpucache_notifier = {
84404 &cpuup_callback, NULL, 0
84405 };
84406
84407@@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
84408 */
84409
84410 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
84411- sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
84412+ sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84413
84414 if (INDEX_AC != INDEX_L3)
84415 sizes[INDEX_L3].cs_cachep =
84416 create_kmalloc_cache(names[INDEX_L3].name,
84417- sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
84418+ sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84419
84420 slab_early_init = 0;
84421
84422@@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
84423 */
84424 if (!sizes->cs_cachep)
84425 sizes->cs_cachep = create_kmalloc_cache(names->name,
84426- sizes->cs_size, ARCH_KMALLOC_FLAGS);
84427+ sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84428
84429 #ifdef CONFIG_ZONE_DMA
84430 sizes->cs_dmacachep = create_kmalloc_cache(
84431 names->name_dma, sizes->cs_size,
84432 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
84433 #endif
84434+
84435+#ifdef CONFIG_PAX_USERCOPY_SLABS
84436+ sizes->cs_usercopycachep = create_kmalloc_cache(
84437+ names->name_usercopy, sizes->cs_size,
84438+ ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
84439+#endif
84440+
84441 sizes++;
84442 names++;
84443 }
84444@@ -3924,6 +3938,7 @@ void kfree(const void *objp)
84445
84446 if (unlikely(ZERO_OR_NULL_PTR(objp)))
84447 return;
84448+ VM_BUG_ON(!virt_addr_valid(objp));
84449 local_irq_save(flags);
84450 kfree_debugcheck(objp);
84451 c = virt_to_cache(objp);
84452@@ -4365,10 +4380,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
84453 }
84454 /* cpu stats */
84455 {
84456- unsigned long allochit = atomic_read(&cachep->allochit);
84457- unsigned long allocmiss = atomic_read(&cachep->allocmiss);
84458- unsigned long freehit = atomic_read(&cachep->freehit);
84459- unsigned long freemiss = atomic_read(&cachep->freemiss);
84460+ unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
84461+ unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
84462+ unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
84463+ unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
84464
84465 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
84466 allochit, allocmiss, freehit, freemiss);
84467@@ -4600,13 +4615,71 @@ static const struct file_operations proc_slabstats_operations = {
84468 static int __init slab_proc_init(void)
84469 {
84470 #ifdef CONFIG_DEBUG_SLAB_LEAK
84471- proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
84472+ proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
84473 #endif
84474 return 0;
84475 }
84476 module_init(slab_proc_init);
84477 #endif
84478
84479+bool is_usercopy_object(const void *ptr)
84480+{
84481+ struct page *page;
84482+ struct kmem_cache *cachep;
84483+
84484+ if (ZERO_OR_NULL_PTR(ptr))
84485+ return false;
84486+
84487+ if (!slab_is_available())
84488+ return false;
84489+
84490+ if (!virt_addr_valid(ptr))
84491+ return false;
84492+
84493+ page = virt_to_head_page(ptr);
84494+
84495+ if (!PageSlab(page))
84496+ return false;
84497+
84498+ cachep = page->slab_cache;
84499+ return cachep->flags & SLAB_USERCOPY;
84500+}
84501+
84502+#ifdef CONFIG_PAX_USERCOPY
84503+const char *check_heap_object(const void *ptr, unsigned long n)
84504+{
84505+ struct page *page;
84506+ struct kmem_cache *cachep;
84507+ struct slab *slabp;
84508+ unsigned int objnr;
84509+ unsigned long offset;
84510+
84511+ if (ZERO_OR_NULL_PTR(ptr))
84512+ return "<null>";
84513+
84514+ if (!virt_addr_valid(ptr))
84515+ return NULL;
84516+
84517+ page = virt_to_head_page(ptr);
84518+
84519+ if (!PageSlab(page))
84520+ return NULL;
84521+
84522+ cachep = page->slab_cache;
84523+ if (!(cachep->flags & SLAB_USERCOPY))
84524+ return cachep->name;
84525+
84526+ slabp = page->slab_page;
84527+ objnr = obj_to_index(cachep, slabp, ptr);
84528+ BUG_ON(objnr >= cachep->num);
84529+ offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
84530+ if (offset <= cachep->object_size && n <= cachep->object_size - offset)
84531+ return NULL;
84532+
84533+ return cachep->name;
84534+}
84535+#endif
84536+
84537 /**
84538 * ksize - get the actual amount of memory allocated for a given object
84539 * @objp: Pointer to the object
84540diff --git a/mm/slab.h b/mm/slab.h
84541index 34a98d6..73633d1 100644
84542--- a/mm/slab.h
84543+++ b/mm/slab.h
84544@@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
84545
84546 /* Legal flag mask for kmem_cache_create(), for various configurations */
84547 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
84548- SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
84549+ SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
84550
84551 #if defined(CONFIG_DEBUG_SLAB)
84552 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
84553@@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
84554 return s;
84555
84556 page = virt_to_head_page(x);
84557+
84558+ BUG_ON(!PageSlab(page));
84559+
84560 cachep = page->slab_cache;
84561 if (slab_equal_or_root(cachep, s))
84562 return cachep;
84563diff --git a/mm/slab_common.c b/mm/slab_common.c
84564index 3f3cd97..93b0236 100644
84565--- a/mm/slab_common.c
84566+++ b/mm/slab_common.c
84567@@ -22,7 +22,7 @@
84568
84569 #include "slab.h"
84570
84571-enum slab_state slab_state;
84572+enum slab_state slab_state __read_only;
84573 LIST_HEAD(slab_caches);
84574 DEFINE_MUTEX(slab_mutex);
84575 struct kmem_cache *kmem_cache;
84576@@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
84577
84578 err = __kmem_cache_create(s, flags);
84579 if (!err) {
84580- s->refcount = 1;
84581+ atomic_set(&s->refcount, 1);
84582 list_add(&s->list, &slab_caches);
84583 memcg_cache_list_add(memcg, s);
84584 } else {
84585@@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
84586
84587 get_online_cpus();
84588 mutex_lock(&slab_mutex);
84589- s->refcount--;
84590- if (!s->refcount) {
84591+ if (atomic_dec_and_test(&s->refcount)) {
84592 list_del(&s->list);
84593
84594 if (!__kmem_cache_shutdown(s)) {
84595@@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
84596 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
84597 name, size, err);
84598
84599- s->refcount = -1; /* Exempt from merging for now */
84600+ atomic_set(&s->refcount, -1); /* Exempt from merging for now */
84601 }
84602
84603 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84604@@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
84605
84606 create_boot_cache(s, name, size, flags);
84607 list_add(&s->list, &slab_caches);
84608- s->refcount = 1;
84609+ atomic_set(&s->refcount, 1);
84610 return s;
84611 }
84612
84613diff --git a/mm/slob.c b/mm/slob.c
84614index eeed4a0..6ee34ec 100644
84615--- a/mm/slob.c
84616+++ b/mm/slob.c
84617@@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
84618 /*
84619 * Return the size of a slob block.
84620 */
84621-static slobidx_t slob_units(slob_t *s)
84622+static slobidx_t slob_units(const slob_t *s)
84623 {
84624 if (s->units > 0)
84625 return s->units;
84626@@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
84627 /*
84628 * Return the next free slob block pointer after this one.
84629 */
84630-static slob_t *slob_next(slob_t *s)
84631+static slob_t *slob_next(const slob_t *s)
84632 {
84633 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
84634 slobidx_t next;
84635@@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
84636 /*
84637 * Returns true if s is the last free block in its page.
84638 */
84639-static int slob_last(slob_t *s)
84640+static int slob_last(const slob_t *s)
84641 {
84642 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
84643 }
84644
84645-static void *slob_new_pages(gfp_t gfp, int order, int node)
84646+static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
84647 {
84648- void *page;
84649+ struct page *page;
84650
84651 #ifdef CONFIG_NUMA
84652 if (node != NUMA_NO_NODE)
84653@@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
84654 if (!page)
84655 return NULL;
84656
84657- return page_address(page);
84658+ __SetPageSlab(page);
84659+ return page;
84660 }
84661
84662-static void slob_free_pages(void *b, int order)
84663+static void slob_free_pages(struct page *sp, int order)
84664 {
84665 if (current->reclaim_state)
84666 current->reclaim_state->reclaimed_slab += 1 << order;
84667- free_pages((unsigned long)b, order);
84668+ __ClearPageSlab(sp);
84669+ reset_page_mapcount(sp);
84670+ sp->private = 0;
84671+ __free_pages(sp, order);
84672 }
84673
84674 /*
84675@@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
84676
84677 /* Not enough space: must allocate a new page */
84678 if (!b) {
84679- b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84680- if (!b)
84681+ sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
84682+ if (!sp)
84683 return NULL;
84684- sp = virt_to_page(b);
84685- __SetPageSlab(sp);
84686+ b = page_address(sp);
84687
84688 spin_lock_irqsave(&slob_lock, flags);
84689 sp->units = SLOB_UNITS(PAGE_SIZE);
84690 sp->freelist = b;
84691+ sp->private = 0;
84692 INIT_LIST_HEAD(&sp->list);
84693 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
84694 set_slob_page_free(sp, slob_list);
84695@@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
84696 if (slob_page_free(sp))
84697 clear_slob_page_free(sp);
84698 spin_unlock_irqrestore(&slob_lock, flags);
84699- __ClearPageSlab(sp);
84700- page_mapcount_reset(sp);
84701- slob_free_pages(b, 0);
84702+ slob_free_pages(sp, 0);
84703 return;
84704 }
84705
84706@@ -424,11 +426,10 @@ out:
84707 */
84708
84709 static __always_inline void *
84710-__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84711+__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
84712 {
84713- unsigned int *m;
84714- int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84715- void *ret;
84716+ slob_t *m;
84717+ void *ret = NULL;
84718
84719 gfp &= gfp_allowed_mask;
84720
84721@@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84722
84723 if (!m)
84724 return NULL;
84725- *m = size;
84726+ BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
84727+ BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
84728+ m[0].units = size;
84729+ m[1].units = align;
84730 ret = (void *)m + align;
84731
84732 trace_kmalloc_node(caller, ret,
84733 size, size + align, gfp, node);
84734 } else {
84735 unsigned int order = get_order(size);
84736+ struct page *page;
84737
84738 if (likely(order))
84739 gfp |= __GFP_COMP;
84740- ret = slob_new_pages(gfp, order, node);
84741+ page = slob_new_pages(gfp, order, node);
84742+ if (page) {
84743+ ret = page_address(page);
84744+ page->private = size;
84745+ }
84746
84747 trace_kmalloc_node(caller, ret,
84748 size, PAGE_SIZE << order, gfp, node);
84749 }
84750
84751- kmemleak_alloc(ret, size, 1, gfp);
84752+ return ret;
84753+}
84754+
84755+static __always_inline void *
84756+__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
84757+{
84758+ int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84759+ void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
84760+
84761+ if (!ZERO_OR_NULL_PTR(ret))
84762+ kmemleak_alloc(ret, size, 1, gfp);
84763 return ret;
84764 }
84765
84766@@ -493,34 +512,112 @@ void kfree(const void *block)
84767 return;
84768 kmemleak_free(block);
84769
84770+ VM_BUG_ON(!virt_addr_valid(block));
84771 sp = virt_to_page(block);
84772- if (PageSlab(sp)) {
84773+ VM_BUG_ON(!PageSlab(sp));
84774+ if (!sp->private) {
84775 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84776- unsigned int *m = (unsigned int *)(block - align);
84777- slob_free(m, *m + align);
84778- } else
84779+ slob_t *m = (slob_t *)(block - align);
84780+ slob_free(m, m[0].units + align);
84781+ } else {
84782+ __ClearPageSlab(sp);
84783+ reset_page_mapcount(sp);
84784+ sp->private = 0;
84785 __free_pages(sp, compound_order(sp));
84786+ }
84787 }
84788 EXPORT_SYMBOL(kfree);
84789
84790+bool is_usercopy_object(const void *ptr)
84791+{
84792+ if (!slab_is_available())
84793+ return false;
84794+
84795+ // PAX: TODO
84796+
84797+ return false;
84798+}
84799+
84800+#ifdef CONFIG_PAX_USERCOPY
84801+const char *check_heap_object(const void *ptr, unsigned long n)
84802+{
84803+ struct page *page;
84804+ const slob_t *free;
84805+ const void *base;
84806+ unsigned long flags;
84807+
84808+ if (ZERO_OR_NULL_PTR(ptr))
84809+ return "<null>";
84810+
84811+ if (!virt_addr_valid(ptr))
84812+ return NULL;
84813+
84814+ page = virt_to_head_page(ptr);
84815+ if (!PageSlab(page))
84816+ return NULL;
84817+
84818+ if (page->private) {
84819+ base = page;
84820+ if (base <= ptr && n <= page->private - (ptr - base))
84821+ return NULL;
84822+ return "<slob>";
84823+ }
84824+
84825+ /* some tricky double walking to find the chunk */
84826+ spin_lock_irqsave(&slob_lock, flags);
84827+ base = (void *)((unsigned long)ptr & PAGE_MASK);
84828+ free = page->freelist;
84829+
84830+ while (!slob_last(free) && (void *)free <= ptr) {
84831+ base = free + slob_units(free);
84832+ free = slob_next(free);
84833+ }
84834+
84835+ while (base < (void *)free) {
84836+ slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
84837+ int size = SLOB_UNIT * SLOB_UNITS(m + align);
84838+ int offset;
84839+
84840+ if (ptr < base + align)
84841+ break;
84842+
84843+ offset = ptr - base - align;
84844+ if (offset >= m) {
84845+ base += size;
84846+ continue;
84847+ }
84848+
84849+ if (n > m - offset)
84850+ break;
84851+
84852+ spin_unlock_irqrestore(&slob_lock, flags);
84853+ return NULL;
84854+ }
84855+
84856+ spin_unlock_irqrestore(&slob_lock, flags);
84857+ return "<slob>";
84858+}
84859+#endif
84860+
84861 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
84862 size_t ksize(const void *block)
84863 {
84864 struct page *sp;
84865 int align;
84866- unsigned int *m;
84867+ slob_t *m;
84868
84869 BUG_ON(!block);
84870 if (unlikely(block == ZERO_SIZE_PTR))
84871 return 0;
84872
84873 sp = virt_to_page(block);
84874- if (unlikely(!PageSlab(sp)))
84875- return PAGE_SIZE << compound_order(sp);
84876+ VM_BUG_ON(!PageSlab(sp));
84877+ if (sp->private)
84878+ return sp->private;
84879
84880 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
84881- m = (unsigned int *)(block - align);
84882- return SLOB_UNITS(*m) * SLOB_UNIT;
84883+ m = (slob_t *)(block - align);
84884+ return SLOB_UNITS(m[0].units) * SLOB_UNIT;
84885 }
84886 EXPORT_SYMBOL(ksize);
84887
84888@@ -536,23 +633,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
84889
84890 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
84891 {
84892- void *b;
84893+ void *b = NULL;
84894
84895 flags &= gfp_allowed_mask;
84896
84897 lockdep_trace_alloc(flags);
84898
84899+#ifdef CONFIG_PAX_USERCOPY_SLABS
84900+ b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
84901+#else
84902 if (c->size < PAGE_SIZE) {
84903 b = slob_alloc(c->size, flags, c->align, node);
84904 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84905 SLOB_UNITS(c->size) * SLOB_UNIT,
84906 flags, node);
84907 } else {
84908- b = slob_new_pages(flags, get_order(c->size), node);
84909+ struct page *sp;
84910+
84911+ sp = slob_new_pages(flags, get_order(c->size), node);
84912+ if (sp) {
84913+ b = page_address(sp);
84914+ sp->private = c->size;
84915+ }
84916 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
84917 PAGE_SIZE << get_order(c->size),
84918 flags, node);
84919 }
84920+#endif
84921
84922 if (c->ctor)
84923 c->ctor(b);
84924@@ -564,10 +671,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
84925
84926 static void __kmem_cache_free(void *b, int size)
84927 {
84928- if (size < PAGE_SIZE)
84929+ struct page *sp;
84930+
84931+ sp = virt_to_page(b);
84932+ BUG_ON(!PageSlab(sp));
84933+ if (!sp->private)
84934 slob_free(b, size);
84935 else
84936- slob_free_pages(b, get_order(size));
84937+ slob_free_pages(sp, get_order(size));
84938 }
84939
84940 static void kmem_rcu_free(struct rcu_head *head)
84941@@ -580,17 +691,31 @@ static void kmem_rcu_free(struct rcu_head *head)
84942
84943 void kmem_cache_free(struct kmem_cache *c, void *b)
84944 {
84945+ int size = c->size;
84946+
84947+#ifdef CONFIG_PAX_USERCOPY_SLABS
84948+ if (size + c->align < PAGE_SIZE) {
84949+ size += c->align;
84950+ b -= c->align;
84951+ }
84952+#endif
84953+
84954 kmemleak_free_recursive(b, c->flags);
84955 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
84956 struct slob_rcu *slob_rcu;
84957- slob_rcu = b + (c->size - sizeof(struct slob_rcu));
84958- slob_rcu->size = c->size;
84959+ slob_rcu = b + (size - sizeof(struct slob_rcu));
84960+ slob_rcu->size = size;
84961 call_rcu(&slob_rcu->head, kmem_rcu_free);
84962 } else {
84963- __kmem_cache_free(b, c->size);
84964+ __kmem_cache_free(b, size);
84965 }
84966
84967+#ifdef CONFIG_PAX_USERCOPY_SLABS
84968+ trace_kfree(_RET_IP_, b);
84969+#else
84970 trace_kmem_cache_free(_RET_IP_, b);
84971+#endif
84972+
84973 }
84974 EXPORT_SYMBOL(kmem_cache_free);
84975
84976diff --git a/mm/slub.c b/mm/slub.c
84977index 4aec537..8043df1 100644
84978--- a/mm/slub.c
84979+++ b/mm/slub.c
84980@@ -197,7 +197,7 @@ struct track {
84981
84982 enum track_item { TRACK_ALLOC, TRACK_FREE };
84983
84984-#ifdef CONFIG_SYSFS
84985+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
84986 static int sysfs_slab_add(struct kmem_cache *);
84987 static int sysfs_slab_alias(struct kmem_cache *, const char *);
84988 static void sysfs_slab_remove(struct kmem_cache *);
84989@@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
84990 if (!t->addr)
84991 return;
84992
84993- printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
84994+ printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
84995 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
84996 #ifdef CONFIG_STACKTRACE
84997 {
84998@@ -2653,7 +2653,7 @@ static int slub_min_objects;
84999 * Merge control. If this is set then no merging of slab caches will occur.
85000 * (Could be removed. This was introduced to pacify the merge skeptics.)
85001 */
85002-static int slub_nomerge;
85003+static int slub_nomerge = 1;
85004
85005 /*
85006 * Calculate the order of allocation given an slab object size.
85007@@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
85008 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
85009 #endif
85010
85011+#ifdef CONFIG_PAX_USERCOPY_SLABS
85012+static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
85013+#endif
85014+
85015 static int __init setup_slub_min_order(char *str)
85016 {
85017 get_option(&str, &slub_min_order);
85018@@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
85019 return kmalloc_dma_caches[index];
85020
85021 #endif
85022+
85023+#ifdef CONFIG_PAX_USERCOPY_SLABS
85024+ if (flags & SLAB_USERCOPY)
85025+ return kmalloc_usercopy_caches[index];
85026+
85027+#endif
85028+
85029 return kmalloc_caches[index];
85030 }
85031
85032@@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
85033 EXPORT_SYMBOL(__kmalloc_node);
85034 #endif
85035
85036+bool is_usercopy_object(const void *ptr)
85037+{
85038+ struct page *page;
85039+ struct kmem_cache *s;
85040+
85041+ if (ZERO_OR_NULL_PTR(ptr))
85042+ return false;
85043+
85044+ if (!slab_is_available())
85045+ return false;
85046+
85047+ if (!virt_addr_valid(ptr))
85048+ return false;
85049+
85050+ page = virt_to_head_page(ptr);
85051+
85052+ if (!PageSlab(page))
85053+ return false;
85054+
85055+ s = page->slab_cache;
85056+ return s->flags & SLAB_USERCOPY;
85057+}
85058+
85059+#ifdef CONFIG_PAX_USERCOPY
85060+const char *check_heap_object(const void *ptr, unsigned long n)
85061+{
85062+ struct page *page;
85063+ struct kmem_cache *s;
85064+ unsigned long offset;
85065+
85066+ if (ZERO_OR_NULL_PTR(ptr))
85067+ return "<null>";
85068+
85069+ if (!virt_addr_valid(ptr))
85070+ return NULL;
85071+
85072+ page = virt_to_head_page(ptr);
85073+
85074+ if (!PageSlab(page))
85075+ return NULL;
85076+
85077+ s = page->slab_cache;
85078+ if (!(s->flags & SLAB_USERCOPY))
85079+ return s->name;
85080+
85081+ offset = (ptr - page_address(page)) % s->size;
85082+ if (offset <= s->object_size && n <= s->object_size - offset)
85083+ return NULL;
85084+
85085+ return s->name;
85086+}
85087+#endif
85088+
85089 size_t ksize(const void *object)
85090 {
85091 struct page *page;
85092@@ -3404,6 +3468,7 @@ void kfree(const void *x)
85093 if (unlikely(ZERO_OR_NULL_PTR(x)))
85094 return;
85095
85096+ VM_BUG_ON(!virt_addr_valid(x));
85097 page = virt_to_head_page(x);
85098 if (unlikely(!PageSlab(page))) {
85099 BUG_ON(!PageCompound(page));
85100@@ -3712,17 +3777,17 @@ void __init kmem_cache_init(void)
85101
85102 /* Caches that are not of the two-to-the-power-of size */
85103 if (KMALLOC_MIN_SIZE <= 32) {
85104- kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
85105+ kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
85106 caches++;
85107 }
85108
85109 if (KMALLOC_MIN_SIZE <= 64) {
85110- kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
85111+ kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
85112 caches++;
85113 }
85114
85115 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
85116- kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
85117+ kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
85118 caches++;
85119 }
85120
85121@@ -3764,6 +3829,22 @@ void __init kmem_cache_init(void)
85122 }
85123 }
85124 #endif
85125+
85126+#ifdef CONFIG_PAX_USERCOPY_SLABS
85127+ for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
85128+ struct kmem_cache *s = kmalloc_caches[i];
85129+
85130+ if (s && s->size) {
85131+ char *name = kasprintf(GFP_NOWAIT,
85132+ "usercopy-kmalloc-%d", s->object_size);
85133+
85134+ BUG_ON(!name);
85135+ kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
85136+ s->object_size, SLAB_USERCOPY);
85137+ }
85138+ }
85139+#endif
85140+
85141 printk(KERN_INFO
85142 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
85143 " CPUs=%d, Nodes=%d\n",
85144@@ -3790,7 +3871,7 @@ static int slab_unmergeable(struct kmem_cache *s)
85145 /*
85146 * We may have set a slab to be unmergeable during bootstrap.
85147 */
85148- if (s->refcount < 0)
85149+ if (atomic_read(&s->refcount) < 0)
85150 return 1;
85151
85152 return 0;
85153@@ -3848,7 +3929,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85154
85155 s = find_mergeable(memcg, size, align, flags, name, ctor);
85156 if (s) {
85157- s->refcount++;
85158+ atomic_inc(&s->refcount);
85159 /*
85160 * Adjust the object sizes so that we clear
85161 * the complete object on kzalloc.
85162@@ -3857,7 +3938,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
85163 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
85164
85165 if (sysfs_slab_alias(s, name)) {
85166- s->refcount--;
85167+ atomic_dec(&s->refcount);
85168 s = NULL;
85169 }
85170 }
85171@@ -3919,7 +4000,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
85172 return NOTIFY_OK;
85173 }
85174
85175-static struct notifier_block __cpuinitdata slab_notifier = {
85176+static struct notifier_block slab_notifier = {
85177 .notifier_call = slab_cpuup_callback
85178 };
85179
85180@@ -3977,7 +4058,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
85181 }
85182 #endif
85183
85184-#ifdef CONFIG_SYSFS
85185+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85186 static int count_inuse(struct page *page)
85187 {
85188 return page->inuse;
85189@@ -4364,12 +4445,12 @@ static void resiliency_test(void)
85190 validate_slab_cache(kmalloc_caches[9]);
85191 }
85192 #else
85193-#ifdef CONFIG_SYSFS
85194+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85195 static void resiliency_test(void) {};
85196 #endif
85197 #endif
85198
85199-#ifdef CONFIG_SYSFS
85200+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85201 enum slab_stat_type {
85202 SL_ALL, /* All slabs */
85203 SL_PARTIAL, /* Only partially allocated slabs */
85204@@ -4613,7 +4694,7 @@ SLAB_ATTR_RO(ctor);
85205
85206 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
85207 {
85208- return sprintf(buf, "%d\n", s->refcount - 1);
85209+ return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
85210 }
85211 SLAB_ATTR_RO(aliases);
85212
85213@@ -5266,6 +5347,7 @@ static char *create_unique_id(struct kmem_cache *s)
85214 return name;
85215 }
85216
85217+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85218 static int sysfs_slab_add(struct kmem_cache *s)
85219 {
85220 int err;
85221@@ -5289,7 +5371,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
85222 }
85223
85224 s->kobj.kset = slab_kset;
85225- err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
85226+ err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
85227 if (err) {
85228 kobject_put(&s->kobj);
85229 return err;
85230@@ -5323,6 +5405,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
85231 kobject_del(&s->kobj);
85232 kobject_put(&s->kobj);
85233 }
85234+#endif
85235
85236 /*
85237 * Need to buffer aliases during bootup until sysfs becomes
85238@@ -5336,6 +5419,7 @@ struct saved_alias {
85239
85240 static struct saved_alias *alias_list;
85241
85242+#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
85243 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85244 {
85245 struct saved_alias *al;
85246@@ -5358,6 +5442,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
85247 alias_list = al;
85248 return 0;
85249 }
85250+#endif
85251
85252 static int __init slab_sysfs_init(void)
85253 {
85254diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
85255index 1b7e22a..3fcd4f3 100644
85256--- a/mm/sparse-vmemmap.c
85257+++ b/mm/sparse-vmemmap.c
85258@@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
85259 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85260 if (!p)
85261 return NULL;
85262- pud_populate(&init_mm, pud, p);
85263+ pud_populate_kernel(&init_mm, pud, p);
85264 }
85265 return pud;
85266 }
85267@@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
85268 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
85269 if (!p)
85270 return NULL;
85271- pgd_populate(&init_mm, pgd, p);
85272+ pgd_populate_kernel(&init_mm, pgd, p);
85273 }
85274 return pgd;
85275 }
85276diff --git a/mm/sparse.c b/mm/sparse.c
85277index 7ca6dc8..6472aa1 100644
85278--- a/mm/sparse.c
85279+++ b/mm/sparse.c
85280@@ -783,7 +783,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
85281
85282 for (i = 0; i < PAGES_PER_SECTION; i++) {
85283 if (PageHWPoison(&memmap[i])) {
85284- atomic_long_sub(1, &num_poisoned_pages);
85285+ atomic_long_sub_unchecked(1, &num_poisoned_pages);
85286 ClearPageHWPoison(&memmap[i]);
85287 }
85288 }
85289diff --git a/mm/swap.c b/mm/swap.c
85290index 8a529a0..154ef26 100644
85291--- a/mm/swap.c
85292+++ b/mm/swap.c
85293@@ -30,6 +30,7 @@
85294 #include <linux/backing-dev.h>
85295 #include <linux/memcontrol.h>
85296 #include <linux/gfp.h>
85297+#include <linux/hugetlb.h>
85298
85299 #include "internal.h"
85300
85301@@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
85302
85303 __page_cache_release(page);
85304 dtor = get_compound_page_dtor(page);
85305+ if (!PageHuge(page))
85306+ BUG_ON(dtor != free_compound_page);
85307 (*dtor)(page);
85308 }
85309
85310diff --git a/mm/swapfile.c b/mm/swapfile.c
85311index a1f7772..9e982ac 100644
85312--- a/mm/swapfile.c
85313+++ b/mm/swapfile.c
85314@@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
85315
85316 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
85317 /* Activity counter to indicate that a swapon or swapoff has occurred */
85318-static atomic_t proc_poll_event = ATOMIC_INIT(0);
85319+static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
85320
85321 static inline unsigned char swap_count(unsigned char ent)
85322 {
85323@@ -1683,7 +1683,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
85324 }
85325 filp_close(swap_file, NULL);
85326 err = 0;
85327- atomic_inc(&proc_poll_event);
85328+ atomic_inc_unchecked(&proc_poll_event);
85329 wake_up_interruptible(&proc_poll_wait);
85330
85331 out_dput:
85332@@ -1700,8 +1700,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
85333
85334 poll_wait(file, &proc_poll_wait, wait);
85335
85336- if (seq->poll_event != atomic_read(&proc_poll_event)) {
85337- seq->poll_event = atomic_read(&proc_poll_event);
85338+ if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
85339+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85340 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
85341 }
85342
85343@@ -1799,7 +1799,7 @@ static int swaps_open(struct inode *inode, struct file *file)
85344 return ret;
85345
85346 seq = file->private_data;
85347- seq->poll_event = atomic_read(&proc_poll_event);
85348+ seq->poll_event = atomic_read_unchecked(&proc_poll_event);
85349 return 0;
85350 }
85351
85352@@ -2142,7 +2142,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
85353 (frontswap_map) ? "FS" : "");
85354
85355 mutex_unlock(&swapon_mutex);
85356- atomic_inc(&proc_poll_event);
85357+ atomic_inc_unchecked(&proc_poll_event);
85358 wake_up_interruptible(&proc_poll_wait);
85359
85360 if (S_ISREG(inode->i_mode))
85361diff --git a/mm/util.c b/mm/util.c
85362index ab1424d..7c5bd5a 100644
85363--- a/mm/util.c
85364+++ b/mm/util.c
85365@@ -294,6 +294,12 @@ done:
85366 void arch_pick_mmap_layout(struct mm_struct *mm)
85367 {
85368 mm->mmap_base = TASK_UNMAPPED_BASE;
85369+
85370+#ifdef CONFIG_PAX_RANDMMAP
85371+ if (mm->pax_flags & MF_PAX_RANDMMAP)
85372+ mm->mmap_base += mm->delta_mmap;
85373+#endif
85374+
85375 mm->get_unmapped_area = arch_get_unmapped_area;
85376 mm->unmap_area = arch_unmap_area;
85377 }
85378diff --git a/mm/vmalloc.c b/mm/vmalloc.c
85379index 0f751f2..2bc3bd1 100644
85380--- a/mm/vmalloc.c
85381+++ b/mm/vmalloc.c
85382@@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
85383
85384 pte = pte_offset_kernel(pmd, addr);
85385 do {
85386- pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85387- WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85388+
85389+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85390+ if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
85391+ BUG_ON(!pte_exec(*pte));
85392+ set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
85393+ continue;
85394+ }
85395+#endif
85396+
85397+ {
85398+ pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
85399+ WARN_ON(!pte_none(ptent) && !pte_present(ptent));
85400+ }
85401 } while (pte++, addr += PAGE_SIZE, addr != end);
85402 }
85403
85404@@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
85405 pte = pte_alloc_kernel(pmd, addr);
85406 if (!pte)
85407 return -ENOMEM;
85408+
85409+ pax_open_kernel();
85410 do {
85411 struct page *page = pages[*nr];
85412
85413- if (WARN_ON(!pte_none(*pte)))
85414+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85415+ if (pgprot_val(prot) & _PAGE_NX)
85416+#endif
85417+
85418+ if (!pte_none(*pte)) {
85419+ pax_close_kernel();
85420+ WARN_ON(1);
85421 return -EBUSY;
85422- if (WARN_ON(!page))
85423+ }
85424+ if (!page) {
85425+ pax_close_kernel();
85426+ WARN_ON(1);
85427 return -ENOMEM;
85428+ }
85429 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
85430 (*nr)++;
85431 } while (pte++, addr += PAGE_SIZE, addr != end);
85432+ pax_close_kernel();
85433 return 0;
85434 }
85435
85436@@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
85437 pmd_t *pmd;
85438 unsigned long next;
85439
85440- pmd = pmd_alloc(&init_mm, pud, addr);
85441+ pmd = pmd_alloc_kernel(&init_mm, pud, addr);
85442 if (!pmd)
85443 return -ENOMEM;
85444 do {
85445@@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
85446 pud_t *pud;
85447 unsigned long next;
85448
85449- pud = pud_alloc(&init_mm, pgd, addr);
85450+ pud = pud_alloc_kernel(&init_mm, pgd, addr);
85451 if (!pud)
85452 return -ENOMEM;
85453 do {
85454@@ -196,6 +220,12 @@ int is_vmalloc_or_module_addr(const void *x)
85455 if (addr >= MODULES_VADDR && addr < MODULES_END)
85456 return 1;
85457 #endif
85458+
85459+#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85460+ if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
85461+ return 1;
85462+#endif
85463+
85464 return is_vmalloc_addr(x);
85465 }
85466
85467@@ -216,8 +246,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
85468
85469 if (!pgd_none(*pgd)) {
85470 pud_t *pud = pud_offset(pgd, addr);
85471+#ifdef CONFIG_X86
85472+ if (!pud_large(*pud))
85473+#endif
85474 if (!pud_none(*pud)) {
85475 pmd_t *pmd = pmd_offset(pud, addr);
85476+#ifdef CONFIG_X86
85477+ if (!pmd_large(*pmd))
85478+#endif
85479 if (!pmd_none(*pmd)) {
85480 pte_t *ptep, pte;
85481
85482@@ -329,7 +365,7 @@ static void purge_vmap_area_lazy(void);
85483 * Allocate a region of KVA of the specified size and alignment, within the
85484 * vstart and vend.
85485 */
85486-static struct vmap_area *alloc_vmap_area(unsigned long size,
85487+static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
85488 unsigned long align,
85489 unsigned long vstart, unsigned long vend,
85490 int node, gfp_t gfp_mask)
85491@@ -1328,6 +1364,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
85492 struct vm_struct *area;
85493
85494 BUG_ON(in_interrupt());
85495+
85496+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85497+ if (flags & VM_KERNEXEC) {
85498+ if (start != VMALLOC_START || end != VMALLOC_END)
85499+ return NULL;
85500+ start = (unsigned long)MODULES_EXEC_VADDR;
85501+ end = (unsigned long)MODULES_EXEC_END;
85502+ }
85503+#endif
85504+
85505 if (flags & VM_IOREMAP) {
85506 int bit = fls(size);
85507
85508@@ -1569,6 +1615,11 @@ void *vmap(struct page **pages, unsigned int count,
85509 if (count > totalram_pages)
85510 return NULL;
85511
85512+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85513+ if (!(pgprot_val(prot) & _PAGE_NX))
85514+ flags |= VM_KERNEXEC;
85515+#endif
85516+
85517 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
85518 __builtin_return_address(0));
85519 if (!area)
85520@@ -1670,6 +1721,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
85521 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
85522 goto fail;
85523
85524+#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
85525+ if (!(pgprot_val(prot) & _PAGE_NX))
85526+ area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
85527+ VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
85528+ else
85529+#endif
85530+
85531 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
85532 start, end, node, gfp_mask, caller);
85533 if (!area)
85534@@ -1845,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
85535 * For tight control over page level allocator and protection flags
85536 * use __vmalloc() instead.
85537 */
85538-
85539 void *vmalloc_exec(unsigned long size)
85540 {
85541- return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
85542+ return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
85543 NUMA_NO_NODE, __builtin_return_address(0));
85544 }
85545
85546@@ -2139,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
85547 unsigned long uaddr = vma->vm_start;
85548 unsigned long usize = vma->vm_end - vma->vm_start;
85549
85550+ BUG_ON(vma->vm_mirror);
85551+
85552 if ((PAGE_SIZE-1) & (unsigned long)addr)
85553 return -EINVAL;
85554
85555@@ -2578,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
85556 v->addr, v->addr + v->size, v->size);
85557
85558 if (v->caller)
85559+#ifdef CONFIG_GRKERNSEC_HIDESYM
85560+ seq_printf(m, " %pK", v->caller);
85561+#else
85562 seq_printf(m, " %pS", v->caller);
85563+#endif
85564
85565 if (v->nr_pages)
85566 seq_printf(m, " pages=%d", v->nr_pages);
85567diff --git a/mm/vmstat.c b/mm/vmstat.c
85568index e1d8ed1..253fa3c 100644
85569--- a/mm/vmstat.c
85570+++ b/mm/vmstat.c
85571@@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
85572 *
85573 * vm_stat contains the global counters
85574 */
85575-atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85576+atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
85577 EXPORT_SYMBOL(vm_stat);
85578
85579 #ifdef CONFIG_SMP
85580@@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
85581 v = p->vm_stat_diff[i];
85582 p->vm_stat_diff[i] = 0;
85583 local_irq_restore(flags);
85584- atomic_long_add(v, &zone->vm_stat[i]);
85585+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85586 global_diff[i] += v;
85587 #ifdef CONFIG_NUMA
85588 /* 3 seconds idle till flush */
85589@@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
85590
85591 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
85592 if (global_diff[i])
85593- atomic_long_add(global_diff[i], &vm_stat[i]);
85594+ atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
85595 }
85596
85597 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85598@@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
85599 if (pset->vm_stat_diff[i]) {
85600 int v = pset->vm_stat_diff[i];
85601 pset->vm_stat_diff[i] = 0;
85602- atomic_long_add(v, &zone->vm_stat[i]);
85603- atomic_long_add(v, &vm_stat[i]);
85604+ atomic_long_add_unchecked(v, &zone->vm_stat[i]);
85605+ atomic_long_add_unchecked(v, &vm_stat[i]);
85606 }
85607 }
85608 #endif
85609@@ -1224,7 +1224,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
85610 return NOTIFY_OK;
85611 }
85612
85613-static struct notifier_block __cpuinitdata vmstat_notifier =
85614+static struct notifier_block vmstat_notifier =
85615 { &vmstat_cpuup_callback, NULL, 0 };
85616 #endif
85617
85618@@ -1239,10 +1239,20 @@ static int __init setup_vmstat(void)
85619 start_cpu_timer(cpu);
85620 #endif
85621 #ifdef CONFIG_PROC_FS
85622- proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
85623- proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
85624- proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
85625- proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
85626+ {
85627+ mode_t gr_mode = S_IRUGO;
85628+#ifdef CONFIG_GRKERNSEC_PROC_ADD
85629+ gr_mode = S_IRUSR;
85630+#endif
85631+ proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
85632+ proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
85633+#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85634+ proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
85635+#else
85636+ proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
85637+#endif
85638+ proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
85639+ }
85640 #endif
85641 return 0;
85642 }
85643diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
85644index 85addcd..c429a13 100644
85645--- a/net/8021q/vlan.c
85646+++ b/net/8021q/vlan.c
85647@@ -114,6 +114,13 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
85648 if (vlan_id)
85649 vlan_vid_del(real_dev, vlan_id);
85650
85651+ /* Take it out of our own structures, but be sure to interlock with
85652+ * HW accelerating devices or SW vlan input packet processing if
85653+ * VLAN is not 0 (leave it there for 802.1p).
85654+ */
85655+ if (vlan_id)
85656+ vlan_vid_del(real_dev, vlan_id);
85657+
85658 /* Get rid of the vlan's reference to real_dev */
85659 dev_put(real_dev);
85660 }
85661@@ -496,7 +503,7 @@ out:
85662 return NOTIFY_DONE;
85663 }
85664
85665-static struct notifier_block vlan_notifier_block __read_mostly = {
85666+static struct notifier_block vlan_notifier_block = {
85667 .notifier_call = vlan_device_event,
85668 };
85669
85670@@ -571,8 +578,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
85671 err = -EPERM;
85672 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
85673 break;
85674- if ((args.u.name_type >= 0) &&
85675- (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
85676+ if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
85677 struct vlan_net *vn;
85678
85679 vn = net_generic(net, vlan_net_id);
85680diff --git a/net/9p/mod.c b/net/9p/mod.c
85681index 6ab36ae..6f1841b 100644
85682--- a/net/9p/mod.c
85683+++ b/net/9p/mod.c
85684@@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
85685 void v9fs_register_trans(struct p9_trans_module *m)
85686 {
85687 spin_lock(&v9fs_trans_lock);
85688- list_add_tail(&m->list, &v9fs_trans_list);
85689+ pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
85690 spin_unlock(&v9fs_trans_lock);
85691 }
85692 EXPORT_SYMBOL(v9fs_register_trans);
85693@@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
85694 void v9fs_unregister_trans(struct p9_trans_module *m)
85695 {
85696 spin_lock(&v9fs_trans_lock);
85697- list_del_init(&m->list);
85698+ pax_list_del_init((struct list_head *)&m->list);
85699 spin_unlock(&v9fs_trans_lock);
85700 }
85701 EXPORT_SYMBOL(v9fs_unregister_trans);
85702diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
85703index 02efb25..41541a9 100644
85704--- a/net/9p/trans_fd.c
85705+++ b/net/9p/trans_fd.c
85706@@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
85707 oldfs = get_fs();
85708 set_fs(get_ds());
85709 /* The cast to a user pointer is valid due to the set_fs() */
85710- ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
85711+ ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
85712 set_fs(oldfs);
85713
85714 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
85715diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
85716index 876fbe8..8bbea9f 100644
85717--- a/net/atm/atm_misc.c
85718+++ b/net/atm/atm_misc.c
85719@@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
85720 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
85721 return 1;
85722 atm_return(vcc, truesize);
85723- atomic_inc(&vcc->stats->rx_drop);
85724+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85725 return 0;
85726 }
85727 EXPORT_SYMBOL(atm_charge);
85728@@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
85729 }
85730 }
85731 atm_return(vcc, guess);
85732- atomic_inc(&vcc->stats->rx_drop);
85733+ atomic_inc_unchecked(&vcc->stats->rx_drop);
85734 return NULL;
85735 }
85736 EXPORT_SYMBOL(atm_alloc_charge);
85737@@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
85738
85739 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85740 {
85741-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85742+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85743 __SONET_ITEMS
85744 #undef __HANDLE_ITEM
85745 }
85746@@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
85747
85748 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
85749 {
85750-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85751+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
85752 __SONET_ITEMS
85753 #undef __HANDLE_ITEM
85754 }
85755diff --git a/net/atm/lec.h b/net/atm/lec.h
85756index a86aff9..3a0d6f6 100644
85757--- a/net/atm/lec.h
85758+++ b/net/atm/lec.h
85759@@ -48,7 +48,7 @@ struct lane2_ops {
85760 const u8 *tlvs, u32 sizeoftlvs);
85761 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
85762 const u8 *tlvs, u32 sizeoftlvs);
85763-};
85764+} __no_const;
85765
85766 /*
85767 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
85768diff --git a/net/atm/proc.c b/net/atm/proc.c
85769index 6ac35ff..ac0e136 100644
85770--- a/net/atm/proc.c
85771+++ b/net/atm/proc.c
85772@@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
85773 const struct k_atm_aal_stats *stats)
85774 {
85775 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
85776- atomic_read(&stats->tx), atomic_read(&stats->tx_err),
85777- atomic_read(&stats->rx), atomic_read(&stats->rx_err),
85778- atomic_read(&stats->rx_drop));
85779+ atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
85780+ atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
85781+ atomic_read_unchecked(&stats->rx_drop));
85782 }
85783
85784 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
85785diff --git a/net/atm/resources.c b/net/atm/resources.c
85786index 0447d5d..3cf4728 100644
85787--- a/net/atm/resources.c
85788+++ b/net/atm/resources.c
85789@@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
85790 static void copy_aal_stats(struct k_atm_aal_stats *from,
85791 struct atm_aal_stats *to)
85792 {
85793-#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
85794+#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
85795 __AAL_STAT_ITEMS
85796 #undef __HANDLE_ITEM
85797 }
85798@@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
85799 static void subtract_aal_stats(struct k_atm_aal_stats *from,
85800 struct atm_aal_stats *to)
85801 {
85802-#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
85803+#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
85804 __AAL_STAT_ITEMS
85805 #undef __HANDLE_ITEM
85806 }
85807diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
85808index d5744b7..506bae3 100644
85809--- a/net/ax25/sysctl_net_ax25.c
85810+++ b/net/ax25/sysctl_net_ax25.c
85811@@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
85812 {
85813 char path[sizeof("net/ax25/") + IFNAMSIZ];
85814 int k;
85815- struct ctl_table *table;
85816+ ctl_table_no_const *table;
85817
85818 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
85819 if (!table)
85820diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
85821index a5bb0a7..e1d8b97 100644
85822--- a/net/batman-adv/bat_iv_ogm.c
85823+++ b/net/batman-adv/bat_iv_ogm.c
85824@@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
85825
85826 /* randomize initial seqno to avoid collision */
85827 get_random_bytes(&random_seqno, sizeof(random_seqno));
85828- atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85829+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
85830
85831 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
85832 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
85833@@ -611,9 +611,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
85834 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
85835
85836 /* change sequence number to network order */
85837- seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
85838+ seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
85839 batadv_ogm_packet->seqno = htonl(seqno);
85840- atomic_inc(&hard_iface->bat_iv.ogm_seqno);
85841+ atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
85842
85843 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
85844 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
85845@@ -1013,7 +1013,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
85846 return;
85847
85848 /* could be changed by schedule_own_packet() */
85849- if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
85850+ if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
85851
85852 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
85853 has_directlink_flag = 1;
85854diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
85855index 368219e..53f56f9 100644
85856--- a/net/batman-adv/hard-interface.c
85857+++ b/net/batman-adv/hard-interface.c
85858@@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
85859 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
85860 dev_add_pack(&hard_iface->batman_adv_ptype);
85861
85862- atomic_set(&hard_iface->frag_seqno, 1);
85863+ atomic_set_unchecked(&hard_iface->frag_seqno, 1);
85864 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
85865 hard_iface->net_dev->name);
85866
85867@@ -514,7 +514,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
85868 /* This can't be called via a bat_priv callback because
85869 * we have no bat_priv yet.
85870 */
85871- atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
85872+ atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
85873 hard_iface->bat_iv.ogm_buff = NULL;
85874
85875 return hard_iface;
85876diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
85877index 2711e87..4ca48fa 100644
85878--- a/net/batman-adv/soft-interface.c
85879+++ b/net/batman-adv/soft-interface.c
85880@@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
85881 primary_if->net_dev->dev_addr, ETH_ALEN);
85882
85883 /* set broadcast sequence number */
85884- seqno = atomic_inc_return(&bat_priv->bcast_seqno);
85885+ seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
85886 bcast_packet->seqno = htonl(seqno);
85887
85888 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
85889@@ -527,7 +527,7 @@ struct net_device *batadv_softif_create(const char *name)
85890 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
85891
85892 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
85893- atomic_set(&bat_priv->bcast_seqno, 1);
85894+ atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
85895 atomic_set(&bat_priv->tt.vn, 0);
85896 atomic_set(&bat_priv->tt.local_changes, 0);
85897 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
85898diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
85899index 4cd87a0..348e705 100644
85900--- a/net/batman-adv/types.h
85901+++ b/net/batman-adv/types.h
85902@@ -51,7 +51,7 @@
85903 struct batadv_hard_iface_bat_iv {
85904 unsigned char *ogm_buff;
85905 int ogm_buff_len;
85906- atomic_t ogm_seqno;
85907+ atomic_unchecked_t ogm_seqno;
85908 };
85909
85910 /**
85911@@ -75,7 +75,7 @@ struct batadv_hard_iface {
85912 int16_t if_num;
85913 char if_status;
85914 struct net_device *net_dev;
85915- atomic_t frag_seqno;
85916+ atomic_unchecked_t frag_seqno;
85917 struct kobject *hardif_obj;
85918 atomic_t refcount;
85919 struct packet_type batman_adv_ptype;
85920@@ -495,7 +495,7 @@ struct batadv_priv {
85921 #ifdef CONFIG_BATMAN_ADV_DEBUG
85922 atomic_t log_level;
85923 #endif
85924- atomic_t bcast_seqno;
85925+ atomic_unchecked_t bcast_seqno;
85926 atomic_t bcast_queue_left;
85927 atomic_t batman_queue_left;
85928 char num_ifaces;
85929diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
85930index 50e079f..49ce2d2 100644
85931--- a/net/batman-adv/unicast.c
85932+++ b/net/batman-adv/unicast.c
85933@@ -270,7 +270,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
85934 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
85935 frag2->flags = large_tail;
85936
85937- seqno = atomic_add_return(2, &hard_iface->frag_seqno);
85938+ seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
85939 frag1->seqno = htons(seqno - 1);
85940 frag2->seqno = htons(seqno);
85941
85942diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
85943index b88605f..958e3e2 100644
85944--- a/net/bluetooth/hci_core.c
85945+++ b/net/bluetooth/hci_core.c
85946@@ -1793,16 +1793,16 @@ int hci_register_dev(struct hci_dev *hdev)
85947 list_add(&hdev->list, &hci_dev_list);
85948 write_unlock(&hci_dev_list_lock);
85949
85950- hdev->workqueue = alloc_workqueue(hdev->name, WQ_HIGHPRI | WQ_UNBOUND |
85951- WQ_MEM_RECLAIM, 1);
85952+ hdev->workqueue = alloc_workqueue("%s", WQ_HIGHPRI | WQ_UNBOUND |
85953+ WQ_MEM_RECLAIM, 1, hdev->name);
85954 if (!hdev->workqueue) {
85955 error = -ENOMEM;
85956 goto err;
85957 }
85958
85959- hdev->req_workqueue = alloc_workqueue(hdev->name,
85960+ hdev->req_workqueue = alloc_workqueue("%s",
85961 WQ_HIGHPRI | WQ_UNBOUND |
85962- WQ_MEM_RECLAIM, 1);
85963+ WQ_MEM_RECLAIM, 1, hdev->name);
85964 if (!hdev->req_workqueue) {
85965 destroy_workqueue(hdev->workqueue);
85966 error = -ENOMEM;
85967diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
85968index 6a93614..1415549 100644
85969--- a/net/bluetooth/hci_sock.c
85970+++ b/net/bluetooth/hci_sock.c
85971@@ -929,7 +929,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
85972 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
85973 }
85974
85975- len = min_t(unsigned int, len, sizeof(uf));
85976+ len = min((size_t)len, sizeof(uf));
85977 if (copy_from_user(&uf, optval, len)) {
85978 err = -EFAULT;
85979 break;
85980diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
85981index c5f9cd6..dfc8ec1 100644
85982--- a/net/bluetooth/l2cap_core.c
85983+++ b/net/bluetooth/l2cap_core.c
85984@@ -2743,6 +2743,9 @@ static struct sk_buff *l2cap_build_cmd(struct l2cap_conn *conn, u8 code,
85985 BT_DBG("conn %p, code 0x%2.2x, ident 0x%2.2x, len %u",
85986 conn, code, ident, dlen);
85987
85988+ if (conn->mtu < L2CAP_HDR_SIZE + L2CAP_CMD_HDR_SIZE)
85989+ return NULL;
85990+
85991 len = L2CAP_HDR_SIZE + L2CAP_CMD_HDR_SIZE + dlen;
85992 count = min_t(unsigned int, conn->mtu, len);
85993
85994@@ -3395,8 +3398,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
85995 break;
85996
85997 case L2CAP_CONF_RFC:
85998- if (olen == sizeof(rfc))
85999- memcpy(&rfc, (void *)val, olen);
86000+ if (olen != sizeof(rfc))
86001+ break;
86002+
86003+ memcpy(&rfc, (void *)val, olen);
86004
86005 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
86006 rfc.mode != chan->mode)
86007@@ -4221,7 +4226,7 @@ static inline int l2cap_information_rsp(struct l2cap_conn *conn,
86008 struct l2cap_info_rsp *rsp = (struct l2cap_info_rsp *) data;
86009 u16 type, result;
86010
86011- if (cmd_len != sizeof(*rsp))
86012+ if (cmd_len < sizeof(*rsp))
86013 return -EPROTO;
86014
86015 type = __le16_to_cpu(rsp->type);
86016diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
86017index 1bcfb84..dad9f98 100644
86018--- a/net/bluetooth/l2cap_sock.c
86019+++ b/net/bluetooth/l2cap_sock.c
86020@@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86021 struct sock *sk = sock->sk;
86022 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
86023 struct l2cap_options opts;
86024- int len, err = 0;
86025+ int err = 0;
86026+ size_t len = optlen;
86027 u32 opt;
86028
86029 BT_DBG("sk %p", sk);
86030@@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
86031 opts.max_tx = chan->max_tx;
86032 opts.txwin_size = chan->tx_win;
86033
86034- len = min_t(unsigned int, sizeof(opts), optlen);
86035+ len = min(sizeof(opts), len);
86036 if (copy_from_user((char *) &opts, optval, len)) {
86037 err = -EFAULT;
86038 break;
86039@@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86040 struct bt_security sec;
86041 struct bt_power pwr;
86042 struct l2cap_conn *conn;
86043- int len, err = 0;
86044+ int err = 0;
86045+ size_t len = optlen;
86046 u32 opt;
86047
86048 BT_DBG("sk %p", sk);
86049@@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86050
86051 sec.level = BT_SECURITY_LOW;
86052
86053- len = min_t(unsigned int, sizeof(sec), optlen);
86054+ len = min(sizeof(sec), len);
86055 if (copy_from_user((char *) &sec, optval, len)) {
86056 err = -EFAULT;
86057 break;
86058@@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
86059
86060 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
86061
86062- len = min_t(unsigned int, sizeof(pwr), optlen);
86063+ len = min(sizeof(pwr), len);
86064 if (copy_from_user((char *) &pwr, optval, len)) {
86065 err = -EFAULT;
86066 break;
86067diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
86068index 7c9224b..381009e 100644
86069--- a/net/bluetooth/rfcomm/sock.c
86070+++ b/net/bluetooth/rfcomm/sock.c
86071@@ -666,7 +666,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86072 struct sock *sk = sock->sk;
86073 struct bt_security sec;
86074 int err = 0;
86075- size_t len;
86076+ size_t len = optlen;
86077 u32 opt;
86078
86079 BT_DBG("sk %p", sk);
86080@@ -688,7 +688,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
86081
86082 sec.level = BT_SECURITY_LOW;
86083
86084- len = min_t(unsigned int, sizeof(sec), optlen);
86085+ len = min(sizeof(sec), len);
86086 if (copy_from_user((char *) &sec, optval, len)) {
86087 err = -EFAULT;
86088 break;
86089diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
86090index b6e44ad..5b0d514 100644
86091--- a/net/bluetooth/rfcomm/tty.c
86092+++ b/net/bluetooth/rfcomm/tty.c
86093@@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
86094 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
86095
86096 spin_lock_irqsave(&dev->port.lock, flags);
86097- if (dev->port.count > 0) {
86098+ if (atomic_read(&dev->port.count) > 0) {
86099 spin_unlock_irqrestore(&dev->port.lock, flags);
86100 return;
86101 }
86102@@ -659,10 +659,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
86103 return -ENODEV;
86104
86105 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
86106- dev->channel, dev->port.count);
86107+ dev->channel, atomic_read(&dev->port.count));
86108
86109 spin_lock_irqsave(&dev->port.lock, flags);
86110- if (++dev->port.count > 1) {
86111+ if (atomic_inc_return(&dev->port.count) > 1) {
86112 spin_unlock_irqrestore(&dev->port.lock, flags);
86113 return 0;
86114 }
86115@@ -727,10 +727,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
86116 return;
86117
86118 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
86119- dev->port.count);
86120+ atomic_read(&dev->port.count));
86121
86122 spin_lock_irqsave(&dev->port.lock, flags);
86123- if (!--dev->port.count) {
86124+ if (!atomic_dec_return(&dev->port.count)) {
86125 spin_unlock_irqrestore(&dev->port.lock, flags);
86126 if (dev->tty_dev->parent)
86127 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
86128diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
86129index 8d493c9..3849e49 100644
86130--- a/net/bridge/netfilter/ebtables.c
86131+++ b/net/bridge/netfilter/ebtables.c
86132@@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86133 tmp.valid_hooks = t->table->valid_hooks;
86134 }
86135 mutex_unlock(&ebt_mutex);
86136- if (copy_to_user(user, &tmp, *len) != 0){
86137+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
86138 BUGPRINT("c2u Didn't work\n");
86139 ret = -EFAULT;
86140 break;
86141@@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86142 goto out;
86143 tmp.valid_hooks = t->valid_hooks;
86144
86145- if (copy_to_user(user, &tmp, *len) != 0) {
86146+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86147 ret = -EFAULT;
86148 break;
86149 }
86150@@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
86151 tmp.entries_size = t->table->entries_size;
86152 tmp.valid_hooks = t->table->valid_hooks;
86153
86154- if (copy_to_user(user, &tmp, *len) != 0) {
86155+ if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
86156 ret = -EFAULT;
86157 break;
86158 }
86159diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
86160index a376ec1..1fbd6be 100644
86161--- a/net/caif/cfctrl.c
86162+++ b/net/caif/cfctrl.c
86163@@ -10,6 +10,7 @@
86164 #include <linux/spinlock.h>
86165 #include <linux/slab.h>
86166 #include <linux/pkt_sched.h>
86167+#include <linux/sched.h>
86168 #include <net/caif/caif_layer.h>
86169 #include <net/caif/cfpkt.h>
86170 #include <net/caif/cfctrl.h>
86171@@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
86172 memset(&dev_info, 0, sizeof(dev_info));
86173 dev_info.id = 0xff;
86174 cfsrvl_init(&this->serv, 0, &dev_info, false);
86175- atomic_set(&this->req_seq_no, 1);
86176- atomic_set(&this->rsp_seq_no, 1);
86177+ atomic_set_unchecked(&this->req_seq_no, 1);
86178+ atomic_set_unchecked(&this->rsp_seq_no, 1);
86179 this->serv.layer.receive = cfctrl_recv;
86180 sprintf(this->serv.layer.name, "ctrl");
86181 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
86182@@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
86183 struct cfctrl_request_info *req)
86184 {
86185 spin_lock_bh(&ctrl->info_list_lock);
86186- atomic_inc(&ctrl->req_seq_no);
86187- req->sequence_no = atomic_read(&ctrl->req_seq_no);
86188+ atomic_inc_unchecked(&ctrl->req_seq_no);
86189+ req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
86190 list_add_tail(&req->list, &ctrl->list);
86191 spin_unlock_bh(&ctrl->info_list_lock);
86192 }
86193@@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
86194 if (p != first)
86195 pr_warn("Requests are not received in order\n");
86196
86197- atomic_set(&ctrl->rsp_seq_no,
86198+ atomic_set_unchecked(&ctrl->rsp_seq_no,
86199 p->sequence_no);
86200 list_del(&p->list);
86201 goto out;
86202diff --git a/net/can/af_can.c b/net/can/af_can.c
86203index c48e522..1223690 100644
86204--- a/net/can/af_can.c
86205+++ b/net/can/af_can.c
86206@@ -870,7 +870,7 @@ static const struct net_proto_family can_family_ops = {
86207 };
86208
86209 /* notifier block for netdevice event */
86210-static struct notifier_block can_netdev_notifier __read_mostly = {
86211+static struct notifier_block can_netdev_notifier = {
86212 .notifier_call = can_notifier,
86213 };
86214
86215diff --git a/net/can/gw.c b/net/can/gw.c
86216index 117814a..ad4fb73 100644
86217--- a/net/can/gw.c
86218+++ b/net/can/gw.c
86219@@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
86220 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
86221
86222 static HLIST_HEAD(cgw_list);
86223-static struct notifier_block notifier;
86224
86225 static struct kmem_cache *cgw_cache __read_mostly;
86226
86227@@ -928,6 +927,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
86228 return err;
86229 }
86230
86231+static struct notifier_block notifier = {
86232+ .notifier_call = cgw_notifier
86233+};
86234+
86235 static __init int cgw_module_init(void)
86236 {
86237 /* sanitize given module parameter */
86238@@ -943,7 +946,6 @@ static __init int cgw_module_init(void)
86239 return -ENOMEM;
86240
86241 /* set notifier */
86242- notifier.notifier_call = cgw_notifier;
86243 register_netdevice_notifier(&notifier);
86244
86245 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
86246diff --git a/net/compat.c b/net/compat.c
86247index f0a1ba6..0541331 100644
86248--- a/net/compat.c
86249+++ b/net/compat.c
86250@@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
86251 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
86252 __get_user(kmsg->msg_flags, &umsg->msg_flags))
86253 return -EFAULT;
86254- kmsg->msg_name = compat_ptr(tmp1);
86255- kmsg->msg_iov = compat_ptr(tmp2);
86256- kmsg->msg_control = compat_ptr(tmp3);
86257+ kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
86258+ kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
86259+ kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
86260 return 0;
86261 }
86262
86263@@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86264
86265 if (kern_msg->msg_namelen) {
86266 if (mode == VERIFY_READ) {
86267- int err = move_addr_to_kernel(kern_msg->msg_name,
86268+ int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
86269 kern_msg->msg_namelen,
86270 kern_address);
86271 if (err < 0)
86272@@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86273 kern_msg->msg_name = NULL;
86274
86275 tot_len = iov_from_user_compat_to_kern(kern_iov,
86276- (struct compat_iovec __user *)kern_msg->msg_iov,
86277+ (struct compat_iovec __force_user *)kern_msg->msg_iov,
86278 kern_msg->msg_iovlen);
86279 if (tot_len >= 0)
86280 kern_msg->msg_iov = kern_iov;
86281@@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
86282
86283 #define CMSG_COMPAT_FIRSTHDR(msg) \
86284 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
86285- (struct compat_cmsghdr __user *)((msg)->msg_control) : \
86286+ (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
86287 (struct compat_cmsghdr __user *)NULL)
86288
86289 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
86290 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
86291 (ucmlen) <= (unsigned long) \
86292 ((mhdr)->msg_controllen - \
86293- ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
86294+ ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
86295
86296 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
86297 struct compat_cmsghdr __user *cmsg, int cmsg_len)
86298 {
86299 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
86300- if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
86301+ if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
86302 msg->msg_controllen)
86303 return NULL;
86304 return (struct compat_cmsghdr __user *)ptr;
86305@@ -219,7 +219,7 @@ Efault:
86306
86307 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
86308 {
86309- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86310+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86311 struct compat_cmsghdr cmhdr;
86312 struct compat_timeval ctv;
86313 struct compat_timespec cts[3];
86314@@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
86315
86316 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
86317 {
86318- struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
86319+ struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
86320 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
86321 int fdnum = scm->fp->count;
86322 struct file **fp = scm->fp->fp;
86323@@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
86324 return -EFAULT;
86325 old_fs = get_fs();
86326 set_fs(KERNEL_DS);
86327- err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
86328+ err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
86329 set_fs(old_fs);
86330
86331 return err;
86332@@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
86333 len = sizeof(ktime);
86334 old_fs = get_fs();
86335 set_fs(KERNEL_DS);
86336- err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
86337+ err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
86338 set_fs(old_fs);
86339
86340 if (!err) {
86341@@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86342 case MCAST_JOIN_GROUP:
86343 case MCAST_LEAVE_GROUP:
86344 {
86345- struct compat_group_req __user *gr32 = (void *)optval;
86346+ struct compat_group_req __user *gr32 = (void __user *)optval;
86347 struct group_req __user *kgr =
86348 compat_alloc_user_space(sizeof(struct group_req));
86349 u32 interface;
86350@@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86351 case MCAST_BLOCK_SOURCE:
86352 case MCAST_UNBLOCK_SOURCE:
86353 {
86354- struct compat_group_source_req __user *gsr32 = (void *)optval;
86355+ struct compat_group_source_req __user *gsr32 = (void __user *)optval;
86356 struct group_source_req __user *kgsr = compat_alloc_user_space(
86357 sizeof(struct group_source_req));
86358 u32 interface;
86359@@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
86360 }
86361 case MCAST_MSFILTER:
86362 {
86363- struct compat_group_filter __user *gf32 = (void *)optval;
86364+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86365 struct group_filter __user *kgf;
86366 u32 interface, fmode, numsrc;
86367
86368@@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
86369 char __user *optval, int __user *optlen,
86370 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
86371 {
86372- struct compat_group_filter __user *gf32 = (void *)optval;
86373+ struct compat_group_filter __user *gf32 = (void __user *)optval;
86374 struct group_filter __user *kgf;
86375 int __user *koptlen;
86376 u32 interface, fmode, numsrc;
86377@@ -805,7 +805,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
86378
86379 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
86380 return -EINVAL;
86381- if (copy_from_user(a, args, nas[call]))
86382+ if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
86383 return -EFAULT;
86384 a0 = a[0];
86385 a1 = a[1];
86386diff --git a/net/core/datagram.c b/net/core/datagram.c
86387index 368f9c3..f82d4a3 100644
86388--- a/net/core/datagram.c
86389+++ b/net/core/datagram.c
86390@@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
86391 }
86392
86393 kfree_skb(skb);
86394- atomic_inc(&sk->sk_drops);
86395+ atomic_inc_unchecked(&sk->sk_drops);
86396 sk_mem_reclaim_partial(sk);
86397
86398 return err;
86399diff --git a/net/core/dev.c b/net/core/dev.c
86400index c9eb9e6..922c789 100644
86401--- a/net/core/dev.c
86402+++ b/net/core/dev.c
86403@@ -1617,7 +1617,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86404 {
86405 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
86406 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
86407- atomic_long_inc(&dev->rx_dropped);
86408+ atomic_long_inc_unchecked(&dev->rx_dropped);
86409 kfree_skb(skb);
86410 return NET_RX_DROP;
86411 }
86412@@ -1626,7 +1626,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
86413 skb_orphan(skb);
86414
86415 if (unlikely(!is_skb_forwardable(dev, skb))) {
86416- atomic_long_inc(&dev->rx_dropped);
86417+ atomic_long_inc_unchecked(&dev->rx_dropped);
86418 kfree_skb(skb);
86419 return NET_RX_DROP;
86420 }
86421@@ -2351,7 +2351,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
86422
86423 struct dev_gso_cb {
86424 void (*destructor)(struct sk_buff *skb);
86425-};
86426+} __no_const;
86427
86428 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
86429
86430@@ -3099,7 +3099,7 @@ enqueue:
86431
86432 local_irq_restore(flags);
86433
86434- atomic_long_inc(&skb->dev->rx_dropped);
86435+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86436 kfree_skb(skb);
86437 return NET_RX_DROP;
86438 }
86439@@ -3171,7 +3171,7 @@ int netif_rx_ni(struct sk_buff *skb)
86440 }
86441 EXPORT_SYMBOL(netif_rx_ni);
86442
86443-static void net_tx_action(struct softirq_action *h)
86444+static void net_tx_action(void)
86445 {
86446 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86447
86448@@ -3496,7 +3496,7 @@ ncls:
86449 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
86450 } else {
86451 drop:
86452- atomic_long_inc(&skb->dev->rx_dropped);
86453+ atomic_long_inc_unchecked(&skb->dev->rx_dropped);
86454 kfree_skb(skb);
86455 /* Jamal, now you will not able to escape explaining
86456 * me how you were going to use this. :-)
86457@@ -4101,7 +4101,7 @@ void netif_napi_del(struct napi_struct *napi)
86458 }
86459 EXPORT_SYMBOL(netif_napi_del);
86460
86461-static void net_rx_action(struct softirq_action *h)
86462+static void net_rx_action(void)
86463 {
86464 struct softnet_data *sd = &__get_cpu_var(softnet_data);
86465 unsigned long time_limit = jiffies + 2;
86466@@ -5528,7 +5528,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
86467 } else {
86468 netdev_stats_to_stats64(storage, &dev->stats);
86469 }
86470- storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
86471+ storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
86472 return storage;
86473 }
86474 EXPORT_SYMBOL(dev_get_stats);
86475diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
86476index 6cc0481..59cfb00 100644
86477--- a/net/core/dev_ioctl.c
86478+++ b/net/core/dev_ioctl.c
86479@@ -376,9 +376,13 @@ void dev_load(struct net *net, const char *name)
86480 if (no_module && capable(CAP_NET_ADMIN))
86481 no_module = request_module("netdev-%s", name);
86482 if (no_module && capable(CAP_SYS_MODULE)) {
86483+#ifdef CONFIG_GRKERNSEC_MODHARDEN
86484+ ___request_module(true, "grsec_modharden_netdev", "%s", name);
86485+#else
86486 if (!request_module("%s", name))
86487 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
86488 name);
86489+#endif
86490 }
86491 }
86492 EXPORT_SYMBOL(dev_load);
86493diff --git a/net/core/flow.c b/net/core/flow.c
86494index 2bfd081..53c6058 100644
86495--- a/net/core/flow.c
86496+++ b/net/core/flow.c
86497@@ -61,7 +61,7 @@ struct flow_cache {
86498 struct timer_list rnd_timer;
86499 };
86500
86501-atomic_t flow_cache_genid = ATOMIC_INIT(0);
86502+atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
86503 EXPORT_SYMBOL(flow_cache_genid);
86504 static struct flow_cache flow_cache_global;
86505 static struct kmem_cache *flow_cachep __read_mostly;
86506@@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
86507
86508 static int flow_entry_valid(struct flow_cache_entry *fle)
86509 {
86510- if (atomic_read(&flow_cache_genid) != fle->genid)
86511+ if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
86512 return 0;
86513 if (fle->object && !fle->object->ops->check(fle->object))
86514 return 0;
86515@@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
86516 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
86517 fcp->hash_count++;
86518 }
86519- } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
86520+ } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
86521 flo = fle->object;
86522 if (!flo)
86523 goto ret_object;
86524@@ -279,7 +279,7 @@ nocache:
86525 }
86526 flo = resolver(net, key, family, dir, flo, ctx);
86527 if (fle) {
86528- fle->genid = atomic_read(&flow_cache_genid);
86529+ fle->genid = atomic_read_unchecked(&flow_cache_genid);
86530 if (!IS_ERR(flo))
86531 fle->object = flo;
86532 else
86533diff --git a/net/core/iovec.c b/net/core/iovec.c
86534index 7e7aeb0..2a998cb 100644
86535--- a/net/core/iovec.c
86536+++ b/net/core/iovec.c
86537@@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86538 if (m->msg_namelen) {
86539 if (mode == VERIFY_READ) {
86540 void __user *namep;
86541- namep = (void __user __force *) m->msg_name;
86542+ namep = (void __force_user *) m->msg_name;
86543 err = move_addr_to_kernel(namep, m->msg_namelen,
86544 address);
86545 if (err < 0)
86546@@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
86547 }
86548
86549 size = m->msg_iovlen * sizeof(struct iovec);
86550- if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
86551+ if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
86552 return -EFAULT;
86553
86554 m->msg_iov = iov;
86555diff --git a/net/core/neighbour.c b/net/core/neighbour.c
86556index 3863b8f..85c99a6 100644
86557--- a/net/core/neighbour.c
86558+++ b/net/core/neighbour.c
86559@@ -2778,7 +2778,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
86560 size_t *lenp, loff_t *ppos)
86561 {
86562 int size, ret;
86563- ctl_table tmp = *ctl;
86564+ ctl_table_no_const tmp = *ctl;
86565
86566 tmp.extra1 = &zero;
86567 tmp.extra2 = &unres_qlen_max;
86568diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
86569index 3174f19..5810985 100644
86570--- a/net/core/net-procfs.c
86571+++ b/net/core/net-procfs.c
86572@@ -271,8 +271,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
86573 else
86574 seq_printf(seq, "%04x", ntohs(pt->type));
86575
86576+#ifdef CONFIG_GRKERNSEC_HIDESYM
86577+ seq_printf(seq, " %-8s %pF\n",
86578+ pt->dev ? pt->dev->name : "", NULL);
86579+#else
86580 seq_printf(seq, " %-8s %pF\n",
86581 pt->dev ? pt->dev->name : "", pt->func);
86582+#endif
86583 }
86584
86585 return 0;
86586diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
86587index 7427ab5..389f411 100644
86588--- a/net/core/net-sysfs.c
86589+++ b/net/core/net-sysfs.c
86590@@ -1321,7 +1321,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
86591 }
86592 EXPORT_SYMBOL(netdev_class_remove_file);
86593
86594-int netdev_kobject_init(void)
86595+int __init netdev_kobject_init(void)
86596 {
86597 kobj_ns_type_register(&net_ns_type_operations);
86598 return class_register(&net_class);
86599diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
86600index 80e271d..2980cc2 100644
86601--- a/net/core/net_namespace.c
86602+++ b/net/core/net_namespace.c
86603@@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
86604 int error;
86605 LIST_HEAD(net_exit_list);
86606
86607- list_add_tail(&ops->list, list);
86608+ pax_list_add_tail((struct list_head *)&ops->list, list);
86609 if (ops->init || (ops->id && ops->size)) {
86610 for_each_net(net) {
86611 error = ops_init(ops, net);
86612@@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
86613
86614 out_undo:
86615 /* If I have an error cleanup all namespaces I initialized */
86616- list_del(&ops->list);
86617+ pax_list_del((struct list_head *)&ops->list);
86618 ops_exit_list(ops, &net_exit_list);
86619 ops_free_list(ops, &net_exit_list);
86620 return error;
86621@@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
86622 struct net *net;
86623 LIST_HEAD(net_exit_list);
86624
86625- list_del(&ops->list);
86626+ pax_list_del((struct list_head *)&ops->list);
86627 for_each_net(net)
86628 list_add_tail(&net->exit_list, &net_exit_list);
86629 ops_exit_list(ops, &net_exit_list);
86630@@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
86631 mutex_lock(&net_mutex);
86632 error = register_pernet_operations(&pernet_list, ops);
86633 if (!error && (first_device == &pernet_list))
86634- first_device = &ops->list;
86635+ first_device = (struct list_head *)&ops->list;
86636 mutex_unlock(&net_mutex);
86637 return error;
86638 }
86639diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
86640index 23854b5..ff4fda4 100644
86641--- a/net/core/rtnetlink.c
86642+++ b/net/core/rtnetlink.c
86643@@ -58,7 +58,7 @@ struct rtnl_link {
86644 rtnl_doit_func doit;
86645 rtnl_dumpit_func dumpit;
86646 rtnl_calcit_func calcit;
86647-};
86648+} __no_const;
86649
86650 static DEFINE_MUTEX(rtnl_mutex);
86651
86652@@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
86653 if (rtnl_link_ops_get(ops->kind))
86654 return -EEXIST;
86655
86656- if (!ops->dellink)
86657- ops->dellink = unregister_netdevice_queue;
86658+ if (!ops->dellink) {
86659+ pax_open_kernel();
86660+ *(void **)&ops->dellink = unregister_netdevice_queue;
86661+ pax_close_kernel();
86662+ }
86663
86664- list_add_tail(&ops->list, &link_ops);
86665+ pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
86666 return 0;
86667 }
86668 EXPORT_SYMBOL_GPL(__rtnl_link_register);
86669@@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
86670 for_each_net(net) {
86671 __rtnl_kill_links(net, ops);
86672 }
86673- list_del(&ops->list);
86674+ pax_list_del((struct list_head *)&ops->list);
86675 }
86676 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
86677
86678diff --git a/net/core/scm.c b/net/core/scm.c
86679index 2dc6cda..2159524 100644
86680--- a/net/core/scm.c
86681+++ b/net/core/scm.c
86682@@ -226,7 +226,7 @@ EXPORT_SYMBOL(__scm_send);
86683 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86684 {
86685 struct cmsghdr __user *cm
86686- = (__force struct cmsghdr __user *)msg->msg_control;
86687+ = (struct cmsghdr __force_user *)msg->msg_control;
86688 struct cmsghdr cmhdr;
86689 int cmlen = CMSG_LEN(len);
86690 int err;
86691@@ -249,7 +249,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
86692 err = -EFAULT;
86693 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
86694 goto out;
86695- if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
86696+ if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
86697 goto out;
86698 cmlen = CMSG_SPACE(len);
86699 if (msg->msg_controllen < cmlen)
86700@@ -265,7 +265,7 @@ EXPORT_SYMBOL(put_cmsg);
86701 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86702 {
86703 struct cmsghdr __user *cm
86704- = (__force struct cmsghdr __user*)msg->msg_control;
86705+ = (struct cmsghdr __force_user *)msg->msg_control;
86706
86707 int fdmax = 0;
86708 int fdnum = scm->fp->count;
86709@@ -285,7 +285,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
86710 if (fdnum < fdmax)
86711 fdmax = fdnum;
86712
86713- for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
86714+ for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
86715 i++, cmfptr++)
86716 {
86717 struct socket *sock;
86718diff --git a/net/core/secure_seq.c b/net/core/secure_seq.c
86719index e61a8bb..6a2f13c 100644
86720--- a/net/core/secure_seq.c
86721+++ b/net/core/secure_seq.c
86722@@ -12,12 +12,10 @@
86723
86724 static u32 net_secret[MD5_MESSAGE_BYTES / 4] ____cacheline_aligned;
86725
86726-static int __init net_secret_init(void)
86727+void net_secret_init(void)
86728 {
86729 get_random_bytes(net_secret, sizeof(net_secret));
86730- return 0;
86731 }
86732-late_initcall(net_secret_init);
86733
86734 #ifdef CONFIG_INET
86735 static u32 seq_scale(u32 seq)
86736diff --git a/net/core/sock.c b/net/core/sock.c
86737index 684c37d..b541900 100644
86738--- a/net/core/sock.c
86739+++ b/net/core/sock.c
86740@@ -390,7 +390,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86741 struct sk_buff_head *list = &sk->sk_receive_queue;
86742
86743 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
86744- atomic_inc(&sk->sk_drops);
86745+ atomic_inc_unchecked(&sk->sk_drops);
86746 trace_sock_rcvqueue_full(sk, skb);
86747 return -ENOMEM;
86748 }
86749@@ -400,7 +400,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86750 return err;
86751
86752 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
86753- atomic_inc(&sk->sk_drops);
86754+ atomic_inc_unchecked(&sk->sk_drops);
86755 return -ENOBUFS;
86756 }
86757
86758@@ -420,7 +420,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86759 skb_dst_force(skb);
86760
86761 spin_lock_irqsave(&list->lock, flags);
86762- skb->dropcount = atomic_read(&sk->sk_drops);
86763+ skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
86764 __skb_queue_tail(list, skb);
86765 spin_unlock_irqrestore(&list->lock, flags);
86766
86767@@ -440,7 +440,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86768 skb->dev = NULL;
86769
86770 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
86771- atomic_inc(&sk->sk_drops);
86772+ atomic_inc_unchecked(&sk->sk_drops);
86773 goto discard_and_relse;
86774 }
86775 if (nested)
86776@@ -458,7 +458,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
86777 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
86778 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
86779 bh_unlock_sock(sk);
86780- atomic_inc(&sk->sk_drops);
86781+ atomic_inc_unchecked(&sk->sk_drops);
86782 goto discard_and_relse;
86783 }
86784
86785@@ -942,12 +942,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86786 struct timeval tm;
86787 } v;
86788
86789- int lv = sizeof(int);
86790- int len;
86791+ unsigned int lv = sizeof(int);
86792+ unsigned int len;
86793
86794 if (get_user(len, optlen))
86795 return -EFAULT;
86796- if (len < 0)
86797+ if (len > INT_MAX)
86798 return -EINVAL;
86799
86800 memset(&v, 0, sizeof(v));
86801@@ -1099,11 +1099,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86802
86803 case SO_PEERNAME:
86804 {
86805- char address[128];
86806+ char address[_K_SS_MAXSIZE];
86807
86808 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
86809 return -ENOTCONN;
86810- if (lv < len)
86811+ if (lv < len || sizeof address < len)
86812 return -EINVAL;
86813 if (copy_to_user(optval, address, len))
86814 return -EFAULT;
86815@@ -1166,7 +1166,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
86816
86817 if (len > lv)
86818 len = lv;
86819- if (copy_to_user(optval, &v, len))
86820+ if (len > sizeof(v) || copy_to_user(optval, &v, len))
86821 return -EFAULT;
86822 lenout:
86823 if (put_user(len, optlen))
86824@@ -2284,7 +2284,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
86825 */
86826 smp_wmb();
86827 atomic_set(&sk->sk_refcnt, 1);
86828- atomic_set(&sk->sk_drops, 0);
86829+ atomic_set_unchecked(&sk->sk_drops, 0);
86830 }
86831 EXPORT_SYMBOL(sock_init_data);
86832
86833diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
86834index a29e90c..922399c 100644
86835--- a/net/core/sock_diag.c
86836+++ b/net/core/sock_diag.c
86837@@ -9,26 +9,33 @@
86838 #include <linux/inet_diag.h>
86839 #include <linux/sock_diag.h>
86840
86841-static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
86842+static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
86843 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
86844 static DEFINE_MUTEX(sock_diag_table_mutex);
86845
86846 int sock_diag_check_cookie(void *sk, __u32 *cookie)
86847 {
86848+#ifndef CONFIG_GRKERNSEC_HIDESYM
86849 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
86850 cookie[1] != INET_DIAG_NOCOOKIE) &&
86851 ((u32)(unsigned long)sk != cookie[0] ||
86852 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
86853 return -ESTALE;
86854 else
86855+#endif
86856 return 0;
86857 }
86858 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
86859
86860 void sock_diag_save_cookie(void *sk, __u32 *cookie)
86861 {
86862+#ifdef CONFIG_GRKERNSEC_HIDESYM
86863+ cookie[0] = 0;
86864+ cookie[1] = 0;
86865+#else
86866 cookie[0] = (u32)(unsigned long)sk;
86867 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
86868+#endif
86869 }
86870 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
86871
86872@@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
86873 mutex_lock(&sock_diag_table_mutex);
86874 if (sock_diag_handlers[hndl->family])
86875 err = -EBUSY;
86876- else
86877+ else {
86878+ pax_open_kernel();
86879 sock_diag_handlers[hndl->family] = hndl;
86880+ pax_close_kernel();
86881+ }
86882 mutex_unlock(&sock_diag_table_mutex);
86883
86884 return err;
86885@@ -92,7 +102,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
86886
86887 mutex_lock(&sock_diag_table_mutex);
86888 BUG_ON(sock_diag_handlers[family] != hnld);
86889+ pax_open_kernel();
86890 sock_diag_handlers[family] = NULL;
86891+ pax_close_kernel();
86892 mutex_unlock(&sock_diag_table_mutex);
86893 }
86894 EXPORT_SYMBOL_GPL(sock_diag_unregister);
86895diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
86896index cfdb46a..cef55e1 100644
86897--- a/net/core/sysctl_net_core.c
86898+++ b/net/core/sysctl_net_core.c
86899@@ -28,7 +28,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
86900 {
86901 unsigned int orig_size, size;
86902 int ret, i;
86903- ctl_table tmp = {
86904+ ctl_table_no_const tmp = {
86905 .data = &size,
86906 .maxlen = sizeof(size),
86907 .mode = table->mode
86908@@ -211,13 +211,12 @@ static struct ctl_table netns_core_table[] = {
86909
86910 static __net_init int sysctl_core_net_init(struct net *net)
86911 {
86912- struct ctl_table *tbl;
86913+ ctl_table_no_const *tbl = NULL;
86914
86915 net->core.sysctl_somaxconn = SOMAXCONN;
86916
86917- tbl = netns_core_table;
86918 if (!net_eq(net, &init_net)) {
86919- tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
86920+ tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
86921 if (tbl == NULL)
86922 goto err_dup;
86923
86924@@ -227,17 +226,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
86925 if (net->user_ns != &init_user_ns) {
86926 tbl[0].procname = NULL;
86927 }
86928- }
86929-
86930- net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86931+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
86932+ } else
86933+ net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
86934 if (net->core.sysctl_hdr == NULL)
86935 goto err_reg;
86936
86937 return 0;
86938
86939 err_reg:
86940- if (tbl != netns_core_table)
86941- kfree(tbl);
86942+ kfree(tbl);
86943 err_dup:
86944 return -ENOMEM;
86945 }
86946@@ -252,7 +250,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
86947 kfree(tbl);
86948 }
86949
86950-static __net_initdata struct pernet_operations sysctl_core_ops = {
86951+static __net_initconst struct pernet_operations sysctl_core_ops = {
86952 .init = sysctl_core_net_init,
86953 .exit = sysctl_core_net_exit,
86954 };
86955diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
86956index c21f200..bc4565b 100644
86957--- a/net/decnet/af_decnet.c
86958+++ b/net/decnet/af_decnet.c
86959@@ -465,6 +465,7 @@ static struct proto dn_proto = {
86960 .sysctl_rmem = sysctl_decnet_rmem,
86961 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
86962 .obj_size = sizeof(struct dn_sock),
86963+ .slab_flags = SLAB_USERCOPY,
86964 };
86965
86966 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
86967diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
86968index a55eecc..dd8428c 100644
86969--- a/net/decnet/sysctl_net_decnet.c
86970+++ b/net/decnet/sysctl_net_decnet.c
86971@@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
86972
86973 if (len > *lenp) len = *lenp;
86974
86975- if (copy_to_user(buffer, addr, len))
86976+ if (len > sizeof addr || copy_to_user(buffer, addr, len))
86977 return -EFAULT;
86978
86979 *lenp = len;
86980@@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
86981
86982 if (len > *lenp) len = *lenp;
86983
86984- if (copy_to_user(buffer, devname, len))
86985+ if (len > sizeof devname || copy_to_user(buffer, devname, len))
86986 return -EFAULT;
86987
86988 *lenp = len;
86989diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
86990index c929d9c..df10cde 100644
86991--- a/net/ipv4/af_inet.c
86992+++ b/net/ipv4/af_inet.c
86993@@ -115,6 +115,7 @@
86994 #include <net/inet_common.h>
86995 #include <net/xfrm.h>
86996 #include <net/net_namespace.h>
86997+#include <net/secure_seq.h>
86998 #ifdef CONFIG_IP_MROUTE
86999 #include <linux/mroute.h>
87000 #endif
87001@@ -263,8 +264,10 @@ void build_ehash_secret(void)
87002 get_random_bytes(&rnd, sizeof(rnd));
87003 } while (rnd == 0);
87004
87005- if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0)
87006+ if (cmpxchg(&inet_ehash_secret, 0, rnd) == 0) {
87007 get_random_bytes(&ipv6_hash_secret, sizeof(ipv6_hash_secret));
87008+ net_secret_init();
87009+ }
87010 }
87011 EXPORT_SYMBOL(build_ehash_secret);
87012
87013@@ -1699,13 +1702,9 @@ static int __init inet_init(void)
87014
87015 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
87016
87017- sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
87018- if (!sysctl_local_reserved_ports)
87019- goto out;
87020-
87021 rc = proto_register(&tcp_prot, 1);
87022 if (rc)
87023- goto out_free_reserved_ports;
87024+ goto out;
87025
87026 rc = proto_register(&udp_prot, 1);
87027 if (rc)
87028@@ -1814,8 +1813,6 @@ out_unregister_udp_proto:
87029 proto_unregister(&udp_prot);
87030 out_unregister_tcp_proto:
87031 proto_unregister(&tcp_prot);
87032-out_free_reserved_ports:
87033- kfree(sysctl_local_reserved_ports);
87034 goto out;
87035 }
87036
87037diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
87038index 2e7f194..0fa4d6d 100644
87039--- a/net/ipv4/ah4.c
87040+++ b/net/ipv4/ah4.c
87041@@ -420,7 +420,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
87042 return;
87043
87044 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87045- atomic_inc(&flow_cache_genid);
87046+ atomic_inc_unchecked(&flow_cache_genid);
87047 rt_genid_bump(net);
87048
87049 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
87050diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
87051index c6287cd..e9bc96a 100644
87052--- a/net/ipv4/devinet.c
87053+++ b/net/ipv4/devinet.c
87054@@ -1992,7 +1992,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
87055 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
87056 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
87057
87058-static struct devinet_sysctl_table {
87059+static const struct devinet_sysctl_table {
87060 struct ctl_table_header *sysctl_header;
87061 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
87062 } devinet_sysctl = {
87063@@ -2110,7 +2110,7 @@ static __net_init int devinet_init_net(struct net *net)
87064 int err;
87065 struct ipv4_devconf *all, *dflt;
87066 #ifdef CONFIG_SYSCTL
87067- struct ctl_table *tbl = ctl_forward_entry;
87068+ ctl_table_no_const *tbl = NULL;
87069 struct ctl_table_header *forw_hdr;
87070 #endif
87071
87072@@ -2128,7 +2128,7 @@ static __net_init int devinet_init_net(struct net *net)
87073 goto err_alloc_dflt;
87074
87075 #ifdef CONFIG_SYSCTL
87076- tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
87077+ tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
87078 if (tbl == NULL)
87079 goto err_alloc_ctl;
87080
87081@@ -2148,7 +2148,10 @@ static __net_init int devinet_init_net(struct net *net)
87082 goto err_reg_dflt;
87083
87084 err = -ENOMEM;
87085- forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87086+ if (!net_eq(net, &init_net))
87087+ forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
87088+ else
87089+ forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
87090 if (forw_hdr == NULL)
87091 goto err_reg_ctl;
87092 net->ipv4.forw_hdr = forw_hdr;
87093@@ -2164,8 +2167,7 @@ err_reg_ctl:
87094 err_reg_dflt:
87095 __devinet_sysctl_unregister(all);
87096 err_reg_all:
87097- if (tbl != ctl_forward_entry)
87098- kfree(tbl);
87099+ kfree(tbl);
87100 err_alloc_ctl:
87101 #endif
87102 if (dflt != &ipv4_devconf_dflt)
87103diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
87104index 4cfe34d..a6ba66e 100644
87105--- a/net/ipv4/esp4.c
87106+++ b/net/ipv4/esp4.c
87107@@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
87108 return;
87109
87110 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87111- atomic_inc(&flow_cache_genid);
87112+ atomic_inc_unchecked(&flow_cache_genid);
87113 rt_genid_bump(net);
87114
87115 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
87116diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
87117index eb4bb12..ee4ec7d 100644
87118--- a/net/ipv4/fib_frontend.c
87119+++ b/net/ipv4/fib_frontend.c
87120@@ -1017,12 +1017,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
87121 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87122 fib_sync_up(dev);
87123 #endif
87124- atomic_inc(&net->ipv4.dev_addr_genid);
87125+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87126 rt_cache_flush(dev_net(dev));
87127 break;
87128 case NETDEV_DOWN:
87129 fib_del_ifaddr(ifa, NULL);
87130- atomic_inc(&net->ipv4.dev_addr_genid);
87131+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87132 if (ifa->ifa_dev->ifa_list == NULL) {
87133 /* Last address was deleted from this interface.
87134 * Disable IP.
87135@@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
87136 #ifdef CONFIG_IP_ROUTE_MULTIPATH
87137 fib_sync_up(dev);
87138 #endif
87139- atomic_inc(&net->ipv4.dev_addr_genid);
87140+ atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
87141 rt_cache_flush(net);
87142 break;
87143 case NETDEV_DOWN:
87144diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
87145index 8f6cb7a..34507f9 100644
87146--- a/net/ipv4/fib_semantics.c
87147+++ b/net/ipv4/fib_semantics.c
87148@@ -765,7 +765,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
87149 nh->nh_saddr = inet_select_addr(nh->nh_dev,
87150 nh->nh_gw,
87151 nh->nh_parent->fib_scope);
87152- nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
87153+ nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
87154
87155 return nh->nh_saddr;
87156 }
87157diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
87158index 786d97a..1889c0d 100644
87159--- a/net/ipv4/inet_connection_sock.c
87160+++ b/net/ipv4/inet_connection_sock.c
87161@@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
87162 .range = { 32768, 61000 },
87163 };
87164
87165-unsigned long *sysctl_local_reserved_ports;
87166+unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
87167 EXPORT_SYMBOL(sysctl_local_reserved_ports);
87168
87169 void inet_get_local_port_range(int *low, int *high)
87170diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
87171index 6af375a..c493c74 100644
87172--- a/net/ipv4/inet_hashtables.c
87173+++ b/net/ipv4/inet_hashtables.c
87174@@ -18,12 +18,15 @@
87175 #include <linux/sched.h>
87176 #include <linux/slab.h>
87177 #include <linux/wait.h>
87178+#include <linux/security.h>
87179
87180 #include <net/inet_connection_sock.h>
87181 #include <net/inet_hashtables.h>
87182 #include <net/secure_seq.h>
87183 #include <net/ip.h>
87184
87185+extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
87186+
87187 /*
87188 * Allocate and initialize a new local port bind bucket.
87189 * The bindhash mutex for snum's hash chain must be held here.
87190@@ -554,6 +557,8 @@ ok:
87191 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
87192 spin_unlock(&head->lock);
87193
87194+ gr_update_task_in_ip_table(current, inet_sk(sk));
87195+
87196 if (tw) {
87197 inet_twsk_deschedule(tw, death_row);
87198 while (twrefcnt) {
87199diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
87200index 000e3d2..5472da3 100644
87201--- a/net/ipv4/inetpeer.c
87202+++ b/net/ipv4/inetpeer.c
87203@@ -503,8 +503,8 @@ relookup:
87204 if (p) {
87205 p->daddr = *daddr;
87206 atomic_set(&p->refcnt, 1);
87207- atomic_set(&p->rid, 0);
87208- atomic_set(&p->ip_id_count,
87209+ atomic_set_unchecked(&p->rid, 0);
87210+ atomic_set_unchecked(&p->ip_id_count,
87211 (daddr->family == AF_INET) ?
87212 secure_ip_id(daddr->addr.a4) :
87213 secure_ipv6_id(daddr->addr.a6));
87214diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
87215index 52c273e..579060b 100644
87216--- a/net/ipv4/ip_fragment.c
87217+++ b/net/ipv4/ip_fragment.c
87218@@ -311,7 +311,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
87219 return 0;
87220
87221 start = qp->rid;
87222- end = atomic_inc_return(&peer->rid);
87223+ end = atomic_inc_return_unchecked(&peer->rid);
87224 qp->rid = end;
87225
87226 rc = qp->q.fragments && (end - start) > max;
87227@@ -788,12 +788,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
87228
87229 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87230 {
87231- struct ctl_table *table;
87232+ ctl_table_no_const *table = NULL;
87233 struct ctl_table_header *hdr;
87234
87235- table = ip4_frags_ns_ctl_table;
87236 if (!net_eq(net, &init_net)) {
87237- table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87238+ table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
87239 if (table == NULL)
87240 goto err_alloc;
87241
87242@@ -804,9 +803,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87243 /* Don't export sysctls to unprivileged users */
87244 if (net->user_ns != &init_user_ns)
87245 table[0].procname = NULL;
87246- }
87247+ hdr = register_net_sysctl(net, "net/ipv4", table);
87248+ } else
87249+ hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
87250
87251- hdr = register_net_sysctl(net, "net/ipv4", table);
87252 if (hdr == NULL)
87253 goto err_reg;
87254
87255@@ -814,8 +814,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
87256 return 0;
87257
87258 err_reg:
87259- if (!net_eq(net, &init_net))
87260- kfree(table);
87261+ kfree(table);
87262 err_alloc:
87263 return -ENOMEM;
87264 }
87265diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
87266index c7e8c04..56cb4c1 100644
87267--- a/net/ipv4/ip_gre.c
87268+++ b/net/ipv4/ip_gre.c
87269@@ -124,7 +124,7 @@ static bool log_ecn_error = true;
87270 module_param(log_ecn_error, bool, 0644);
87271 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
87272
87273-static struct rtnl_link_ops ipgre_link_ops __read_mostly;
87274+static struct rtnl_link_ops ipgre_link_ops;
87275 static int ipgre_tunnel_init(struct net_device *dev);
87276 static void ipgre_tunnel_setup(struct net_device *dev);
87277 static int ipgre_tunnel_bind_dev(struct net_device *dev);
87278@@ -1823,7 +1823,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
87279 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
87280 };
87281
87282-static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87283+static struct rtnl_link_ops ipgre_link_ops = {
87284 .kind = "gre",
87285 .maxtype = IFLA_GRE_MAX,
87286 .policy = ipgre_policy,
87287@@ -1836,7 +1836,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
87288 .fill_info = ipgre_fill_info,
87289 };
87290
87291-static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
87292+static struct rtnl_link_ops ipgre_tap_ops = {
87293 .kind = "gretap",
87294 .maxtype = IFLA_GRE_MAX,
87295 .policy = ipgre_policy,
87296diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
87297index d9c4f11..02b82dbc 100644
87298--- a/net/ipv4/ip_sockglue.c
87299+++ b/net/ipv4/ip_sockglue.c
87300@@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87301 len = min_t(unsigned int, len, opt->optlen);
87302 if (put_user(len, optlen))
87303 return -EFAULT;
87304- if (copy_to_user(optval, opt->__data, len))
87305+ if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
87306+ copy_to_user(optval, opt->__data, len))
87307 return -EFAULT;
87308 return 0;
87309 }
87310@@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
87311 if (sk->sk_type != SOCK_STREAM)
87312 return -ENOPROTOOPT;
87313
87314- msg.msg_control = optval;
87315+ msg.msg_control = (void __force_kernel *)optval;
87316 msg.msg_controllen = len;
87317 msg.msg_flags = flags;
87318
87319diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
87320index c3a4233..7df5626 100644
87321--- a/net/ipv4/ip_vti.c
87322+++ b/net/ipv4/ip_vti.c
87323@@ -47,7 +47,7 @@
87324 #define HASH_SIZE 16
87325 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
87326
87327-static struct rtnl_link_ops vti_link_ops __read_mostly;
87328+static struct rtnl_link_ops vti_link_ops;
87329
87330 static int vti_net_id __read_mostly;
87331 struct vti_net {
87332@@ -399,8 +399,7 @@ static netdev_tx_t vti_tunnel_xmit(struct sk_buff *skb, struct net_device *dev)
87333 tunnel->err_count = 0;
87334 }
87335
87336- IPCB(skb)->flags &= ~(IPSKB_XFRM_TUNNEL_SIZE | IPSKB_XFRM_TRANSFORMED |
87337- IPSKB_REROUTED);
87338+ memset(IPCB(skb), 0, sizeof(*IPCB(skb)));
87339 skb_dst_drop(skb);
87340 skb_dst_set(skb, &rt->dst);
87341 nf_reset(skb);
87342@@ -886,7 +885,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
87343 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
87344 };
87345
87346-static struct rtnl_link_ops vti_link_ops __read_mostly = {
87347+static struct rtnl_link_ops vti_link_ops = {
87348 .kind = "vti",
87349 .maxtype = IFLA_VTI_MAX,
87350 .policy = vti_policy,
87351diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
87352index f01d1b1..8fe03ad 100644
87353--- a/net/ipv4/ipcomp.c
87354+++ b/net/ipv4/ipcomp.c
87355@@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
87356 return;
87357
87358 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
87359- atomic_inc(&flow_cache_genid);
87360+ atomic_inc_unchecked(&flow_cache_genid);
87361 rt_genid_bump(net);
87362
87363 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
87364diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
87365index bf6c5cf..ab2e9c6 100644
87366--- a/net/ipv4/ipconfig.c
87367+++ b/net/ipv4/ipconfig.c
87368@@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
87369
87370 mm_segment_t oldfs = get_fs();
87371 set_fs(get_ds());
87372- res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87373+ res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87374 set_fs(oldfs);
87375 return res;
87376 }
87377@@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
87378
87379 mm_segment_t oldfs = get_fs();
87380 set_fs(get_ds());
87381- res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
87382+ res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
87383 set_fs(oldfs);
87384 return res;
87385 }
87386@@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
87387
87388 mm_segment_t oldfs = get_fs();
87389 set_fs(get_ds());
87390- res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
87391+ res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
87392 set_fs(oldfs);
87393 return res;
87394 }
87395diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
87396index 7533846..d2361d1 100644
87397--- a/net/ipv4/ipip.c
87398+++ b/net/ipv4/ipip.c
87399@@ -138,7 +138,7 @@ struct ipip_net {
87400 static int ipip_tunnel_init(struct net_device *dev);
87401 static void ipip_tunnel_setup(struct net_device *dev);
87402 static void ipip_dev_free(struct net_device *dev);
87403-static struct rtnl_link_ops ipip_link_ops __read_mostly;
87404+static struct rtnl_link_ops ipip_link_ops;
87405
87406 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
87407 struct rtnl_link_stats64 *tot)
87408@@ -974,7 +974,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
87409 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
87410 };
87411
87412-static struct rtnl_link_ops ipip_link_ops __read_mostly = {
87413+static struct rtnl_link_ops ipip_link_ops = {
87414 .kind = "ipip",
87415 .maxtype = IFLA_IPTUN_MAX,
87416 .policy = ipip_policy,
87417diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
87418index 7dc6a97..229c61b 100644
87419--- a/net/ipv4/netfilter/arp_tables.c
87420+++ b/net/ipv4/netfilter/arp_tables.c
87421@@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
87422 #endif
87423
87424 static int get_info(struct net *net, void __user *user,
87425- const int *len, int compat)
87426+ int len, int compat)
87427 {
87428 char name[XT_TABLE_MAXNAMELEN];
87429 struct xt_table *t;
87430 int ret;
87431
87432- if (*len != sizeof(struct arpt_getinfo)) {
87433- duprintf("length %u != %Zu\n", *len,
87434+ if (len != sizeof(struct arpt_getinfo)) {
87435+ duprintf("length %u != %Zu\n", len,
87436 sizeof(struct arpt_getinfo));
87437 return -EINVAL;
87438 }
87439@@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
87440 info.size = private->size;
87441 strcpy(info.name, name);
87442
87443- if (copy_to_user(user, &info, *len) != 0)
87444+ if (copy_to_user(user, &info, len) != 0)
87445 ret = -EFAULT;
87446 else
87447 ret = 0;
87448@@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
87449
87450 switch (cmd) {
87451 case ARPT_SO_GET_INFO:
87452- ret = get_info(sock_net(sk), user, len, 1);
87453+ ret = get_info(sock_net(sk), user, *len, 1);
87454 break;
87455 case ARPT_SO_GET_ENTRIES:
87456 ret = compat_get_entries(sock_net(sk), user, len);
87457@@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
87458
87459 switch (cmd) {
87460 case ARPT_SO_GET_INFO:
87461- ret = get_info(sock_net(sk), user, len, 0);
87462+ ret = get_info(sock_net(sk), user, *len, 0);
87463 break;
87464
87465 case ARPT_SO_GET_ENTRIES:
87466diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
87467index 3efcf87..5247916 100644
87468--- a/net/ipv4/netfilter/ip_tables.c
87469+++ b/net/ipv4/netfilter/ip_tables.c
87470@@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
87471 #endif
87472
87473 static int get_info(struct net *net, void __user *user,
87474- const int *len, int compat)
87475+ int len, int compat)
87476 {
87477 char name[XT_TABLE_MAXNAMELEN];
87478 struct xt_table *t;
87479 int ret;
87480
87481- if (*len != sizeof(struct ipt_getinfo)) {
87482- duprintf("length %u != %zu\n", *len,
87483+ if (len != sizeof(struct ipt_getinfo)) {
87484+ duprintf("length %u != %zu\n", len,
87485 sizeof(struct ipt_getinfo));
87486 return -EINVAL;
87487 }
87488@@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
87489 info.size = private->size;
87490 strcpy(info.name, name);
87491
87492- if (copy_to_user(user, &info, *len) != 0)
87493+ if (copy_to_user(user, &info, len) != 0)
87494 ret = -EFAULT;
87495 else
87496 ret = 0;
87497@@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87498
87499 switch (cmd) {
87500 case IPT_SO_GET_INFO:
87501- ret = get_info(sock_net(sk), user, len, 1);
87502+ ret = get_info(sock_net(sk), user, *len, 1);
87503 break;
87504 case IPT_SO_GET_ENTRIES:
87505 ret = compat_get_entries(sock_net(sk), user, len);
87506@@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
87507
87508 switch (cmd) {
87509 case IPT_SO_GET_INFO:
87510- ret = get_info(sock_net(sk), user, len, 0);
87511+ ret = get_info(sock_net(sk), user, *len, 0);
87512 break;
87513
87514 case IPT_SO_GET_ENTRIES:
87515diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
87516index 2e91006..f084394 100644
87517--- a/net/ipv4/ping.c
87518+++ b/net/ipv4/ping.c
87519@@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
87520 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
87521 0, sock_i_ino(sp),
87522 atomic_read(&sp->sk_refcnt), sp,
87523- atomic_read(&sp->sk_drops), len);
87524+ atomic_read_unchecked(&sp->sk_drops), len);
87525 }
87526
87527 static int ping_seq_show(struct seq_file *seq, void *v)
87528diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
87529index dd44e0a..06dcca4 100644
87530--- a/net/ipv4/raw.c
87531+++ b/net/ipv4/raw.c
87532@@ -309,7 +309,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
87533 int raw_rcv(struct sock *sk, struct sk_buff *skb)
87534 {
87535 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
87536- atomic_inc(&sk->sk_drops);
87537+ atomic_inc_unchecked(&sk->sk_drops);
87538 kfree_skb(skb);
87539 return NET_RX_DROP;
87540 }
87541@@ -745,16 +745,20 @@ static int raw_init(struct sock *sk)
87542
87543 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
87544 {
87545+ struct icmp_filter filter;
87546+
87547 if (optlen > sizeof(struct icmp_filter))
87548 optlen = sizeof(struct icmp_filter);
87549- if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
87550+ if (copy_from_user(&filter, optval, optlen))
87551 return -EFAULT;
87552+ raw_sk(sk)->filter = filter;
87553 return 0;
87554 }
87555
87556 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
87557 {
87558 int len, ret = -EFAULT;
87559+ struct icmp_filter filter;
87560
87561 if (get_user(len, optlen))
87562 goto out;
87563@@ -764,8 +768,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
87564 if (len > sizeof(struct icmp_filter))
87565 len = sizeof(struct icmp_filter);
87566 ret = -EFAULT;
87567- if (put_user(len, optlen) ||
87568- copy_to_user(optval, &raw_sk(sk)->filter, len))
87569+ filter = raw_sk(sk)->filter;
87570+ if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
87571 goto out;
87572 ret = 0;
87573 out: return ret;
87574@@ -994,7 +998,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
87575 0, 0L, 0,
87576 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
87577 0, sock_i_ino(sp),
87578- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
87579+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
87580 }
87581
87582 static int raw_seq_show(struct seq_file *seq, void *v)
87583diff --git a/net/ipv4/route.c b/net/ipv4/route.c
87584index cfede9a..22248f9 100644
87585--- a/net/ipv4/route.c
87586+++ b/net/ipv4/route.c
87587@@ -2558,34 +2558,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
87588 .maxlen = sizeof(int),
87589 .mode = 0200,
87590 .proc_handler = ipv4_sysctl_rtcache_flush,
87591+ .extra1 = &init_net,
87592 },
87593 { },
87594 };
87595
87596 static __net_init int sysctl_route_net_init(struct net *net)
87597 {
87598- struct ctl_table *tbl;
87599+ ctl_table_no_const *tbl = NULL;
87600
87601- tbl = ipv4_route_flush_table;
87602 if (!net_eq(net, &init_net)) {
87603- tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87604+ tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
87605 if (tbl == NULL)
87606 goto err_dup;
87607
87608 /* Don't export sysctls to unprivileged users */
87609 if (net->user_ns != &init_user_ns)
87610 tbl[0].procname = NULL;
87611- }
87612- tbl[0].extra1 = net;
87613+ tbl[0].extra1 = net;
87614+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87615+ } else
87616+ net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
87617
87618- net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
87619 if (net->ipv4.route_hdr == NULL)
87620 goto err_reg;
87621 return 0;
87622
87623 err_reg:
87624- if (tbl != ipv4_route_flush_table)
87625- kfree(tbl);
87626+ kfree(tbl);
87627 err_dup:
87628 return -ENOMEM;
87629 }
87630@@ -2608,7 +2608,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
87631
87632 static __net_init int rt_genid_init(struct net *net)
87633 {
87634- atomic_set(&net->rt_genid, 0);
87635+ atomic_set_unchecked(&net->rt_genid, 0);
87636 get_random_bytes(&net->ipv4.dev_addr_genid,
87637 sizeof(net->ipv4.dev_addr_genid));
87638 return 0;
87639diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
87640index 960fd29..d55bf64 100644
87641--- a/net/ipv4/sysctl_net_ipv4.c
87642+++ b/net/ipv4/sysctl_net_ipv4.c
87643@@ -55,7 +55,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
87644 {
87645 int ret;
87646 int range[2];
87647- ctl_table tmp = {
87648+ ctl_table_no_const tmp = {
87649 .data = &range,
87650 .maxlen = sizeof(range),
87651 .mode = table->mode,
87652@@ -108,7 +108,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
87653 int ret;
87654 gid_t urange[2];
87655 kgid_t low, high;
87656- ctl_table tmp = {
87657+ ctl_table_no_const tmp = {
87658 .data = &urange,
87659 .maxlen = sizeof(urange),
87660 .mode = table->mode,
87661@@ -139,7 +139,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
87662 void __user *buffer, size_t *lenp, loff_t *ppos)
87663 {
87664 char val[TCP_CA_NAME_MAX];
87665- ctl_table tbl = {
87666+ ctl_table_no_const tbl = {
87667 .data = val,
87668 .maxlen = TCP_CA_NAME_MAX,
87669 };
87670@@ -158,7 +158,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
87671 void __user *buffer, size_t *lenp,
87672 loff_t *ppos)
87673 {
87674- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
87675+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
87676 int ret;
87677
87678 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87679@@ -175,7 +175,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
87680 void __user *buffer, size_t *lenp,
87681 loff_t *ppos)
87682 {
87683- ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
87684+ ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
87685 int ret;
87686
87687 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
87688@@ -201,15 +201,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87689 struct mem_cgroup *memcg;
87690 #endif
87691
87692- ctl_table tmp = {
87693+ ctl_table_no_const tmp = {
87694 .data = &vec,
87695 .maxlen = sizeof(vec),
87696 .mode = ctl->mode,
87697 };
87698
87699 if (!write) {
87700- ctl->data = &net->ipv4.sysctl_tcp_mem;
87701- return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
87702+ ctl_table_no_const tcp_mem = *ctl;
87703+
87704+ tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
87705+ return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
87706 }
87707
87708 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
87709@@ -236,7 +238,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
87710 static int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
87711 size_t *lenp, loff_t *ppos)
87712 {
87713- ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87714+ ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
87715 struct tcp_fastopen_context *ctxt;
87716 int ret;
87717 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
87718@@ -477,7 +479,7 @@ static struct ctl_table ipv4_table[] = {
87719 },
87720 {
87721 .procname = "ip_local_reserved_ports",
87722- .data = NULL, /* initialized in sysctl_ipv4_init */
87723+ .data = sysctl_local_reserved_ports,
87724 .maxlen = 65536,
87725 .mode = 0644,
87726 .proc_handler = proc_do_large_bitmap,
87727@@ -856,11 +858,10 @@ static struct ctl_table ipv4_net_table[] = {
87728
87729 static __net_init int ipv4_sysctl_init_net(struct net *net)
87730 {
87731- struct ctl_table *table;
87732+ ctl_table_no_const *table = NULL;
87733
87734- table = ipv4_net_table;
87735 if (!net_eq(net, &init_net)) {
87736- table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
87737+ table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
87738 if (table == NULL)
87739 goto err_alloc;
87740
87741@@ -895,15 +896,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
87742
87743 tcp_init_mem(net);
87744
87745- net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87746+ if (!net_eq(net, &init_net))
87747+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
87748+ else
87749+ net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
87750 if (net->ipv4.ipv4_hdr == NULL)
87751 goto err_reg;
87752
87753 return 0;
87754
87755 err_reg:
87756- if (!net_eq(net, &init_net))
87757- kfree(table);
87758+ kfree(table);
87759 err_alloc:
87760 return -ENOMEM;
87761 }
87762@@ -925,16 +928,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
87763 static __init int sysctl_ipv4_init(void)
87764 {
87765 struct ctl_table_header *hdr;
87766- struct ctl_table *i;
87767-
87768- for (i = ipv4_table; i->procname; i++) {
87769- if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
87770- i->data = sysctl_local_reserved_ports;
87771- break;
87772- }
87773- }
87774- if (!i->procname)
87775- return -EINVAL;
87776
87777 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
87778 if (hdr == NULL)
87779diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
87780index 59163c8..8277c51 100644
87781--- a/net/ipv4/tcp_input.c
87782+++ b/net/ipv4/tcp_input.c
87783@@ -4727,7 +4727,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
87784 * simplifies code)
87785 */
87786 static void
87787-tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87788+__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
87789 struct sk_buff *head, struct sk_buff *tail,
87790 u32 start, u32 end)
87791 {
87792@@ -5841,6 +5841,7 @@ discard:
87793 tcp_paws_reject(&tp->rx_opt, 0))
87794 goto discard_and_undo;
87795
87796+#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
87797 if (th->syn) {
87798 /* We see SYN without ACK. It is attempt of
87799 * simultaneous connect with crossed SYNs.
87800@@ -5891,6 +5892,7 @@ discard:
87801 goto discard;
87802 #endif
87803 }
87804+#endif
87805 /* "fifth, if neither of the SYN or RST bits is set then
87806 * drop the segment and return."
87807 */
87808@@ -5935,7 +5937,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
87809 goto discard;
87810
87811 if (th->syn) {
87812- if (th->fin)
87813+ if (th->fin || th->urg || th->psh)
87814 goto discard;
87815 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
87816 return 1;
87817diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
87818index d09203c..fd5cc91 100644
87819--- a/net/ipv4/tcp_ipv4.c
87820+++ b/net/ipv4/tcp_ipv4.c
87821@@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
87822 EXPORT_SYMBOL(sysctl_tcp_low_latency);
87823
87824
87825+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87826+extern int grsec_enable_blackhole;
87827+#endif
87828+
87829 #ifdef CONFIG_TCP_MD5SIG
87830 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
87831 __be32 daddr, __be32 saddr, const struct tcphdr *th);
87832@@ -1897,6 +1901,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
87833 return 0;
87834
87835 reset:
87836+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87837+ if (!grsec_enable_blackhole)
87838+#endif
87839 tcp_v4_send_reset(rsk, skb);
87840 discard:
87841 kfree_skb(skb);
87842@@ -1996,12 +2003,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
87843 TCP_SKB_CB(skb)->sacked = 0;
87844
87845 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
87846- if (!sk)
87847+ if (!sk) {
87848+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87849+ ret = 1;
87850+#endif
87851 goto no_tcp_socket;
87852-
87853+ }
87854 process:
87855- if (sk->sk_state == TCP_TIME_WAIT)
87856+ if (sk->sk_state == TCP_TIME_WAIT) {
87857+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87858+ ret = 2;
87859+#endif
87860 goto do_time_wait;
87861+ }
87862
87863 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
87864 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
87865@@ -2052,6 +2066,10 @@ no_tcp_socket:
87866 bad_packet:
87867 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
87868 } else {
87869+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87870+ if (!grsec_enable_blackhole || (ret == 1 &&
87871+ (skb->dev->flags & IFF_LOOPBACK)))
87872+#endif
87873 tcp_v4_send_reset(NULL, skb);
87874 }
87875
87876diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
87877index 2f672e7..b8895e9 100644
87878--- a/net/ipv4/tcp_minisocks.c
87879+++ b/net/ipv4/tcp_minisocks.c
87880@@ -27,6 +27,10 @@
87881 #include <net/inet_common.h>
87882 #include <net/xfrm.h>
87883
87884+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87885+extern int grsec_enable_blackhole;
87886+#endif
87887+
87888 int sysctl_tcp_syncookies __read_mostly = 1;
87889 EXPORT_SYMBOL(sysctl_tcp_syncookies);
87890
87891@@ -749,7 +753,10 @@ embryonic_reset:
87892 * avoid becoming vulnerable to outside attack aiming at
87893 * resetting legit local connections.
87894 */
87895- req->rsk_ops->send_reset(sk, skb);
87896+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87897+ if (!grsec_enable_blackhole)
87898+#endif
87899+ req->rsk_ops->send_reset(sk, skb);
87900 } else if (fastopen) { /* received a valid RST pkt */
87901 reqsk_fastopen_remove(sk, req, true);
87902 tcp_reset(sk);
87903diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
87904index d4943f6..e7a74a5 100644
87905--- a/net/ipv4/tcp_probe.c
87906+++ b/net/ipv4/tcp_probe.c
87907@@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
87908 if (cnt + width >= len)
87909 break;
87910
87911- if (copy_to_user(buf + cnt, tbuf, width))
87912+ if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
87913 return -EFAULT;
87914 cnt += width;
87915 }
87916diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
87917index b78aac3..e18230b 100644
87918--- a/net/ipv4/tcp_timer.c
87919+++ b/net/ipv4/tcp_timer.c
87920@@ -22,6 +22,10 @@
87921 #include <linux/gfp.h>
87922 #include <net/tcp.h>
87923
87924+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87925+extern int grsec_lastack_retries;
87926+#endif
87927+
87928 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
87929 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
87930 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
87931@@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
87932 }
87933 }
87934
87935+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87936+ if ((sk->sk_state == TCP_LAST_ACK) &&
87937+ (grsec_lastack_retries > 0) &&
87938+ (grsec_lastack_retries < retry_until))
87939+ retry_until = grsec_lastack_retries;
87940+#endif
87941+
87942 if (retransmits_timed_out(sk, retry_until,
87943 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
87944 /* Has it gone just too far? */
87945diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
87946index 0a073a2..ddf6279 100644
87947--- a/net/ipv4/udp.c
87948+++ b/net/ipv4/udp.c
87949@@ -87,6 +87,7 @@
87950 #include <linux/types.h>
87951 #include <linux/fcntl.h>
87952 #include <linux/module.h>
87953+#include <linux/security.h>
87954 #include <linux/socket.h>
87955 #include <linux/sockios.h>
87956 #include <linux/igmp.h>
87957@@ -111,6 +112,10 @@
87958 #include <trace/events/skb.h>
87959 #include "udp_impl.h"
87960
87961+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
87962+extern int grsec_enable_blackhole;
87963+#endif
87964+
87965 struct udp_table udp_table __read_mostly;
87966 EXPORT_SYMBOL(udp_table);
87967
87968@@ -594,6 +599,9 @@ found:
87969 return s;
87970 }
87971
87972+extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
87973+extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
87974+
87975 /*
87976 * This routine is called by the ICMP module when it gets some
87977 * sort of error condition. If err < 0 then the socket should
87978@@ -889,9 +897,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
87979 dport = usin->sin_port;
87980 if (dport == 0)
87981 return -EINVAL;
87982+
87983+ err = gr_search_udp_sendmsg(sk, usin);
87984+ if (err)
87985+ return err;
87986 } else {
87987 if (sk->sk_state != TCP_ESTABLISHED)
87988 return -EDESTADDRREQ;
87989+
87990+ err = gr_search_udp_sendmsg(sk, NULL);
87991+ if (err)
87992+ return err;
87993+
87994 daddr = inet->inet_daddr;
87995 dport = inet->inet_dport;
87996 /* Open fast path for connected socket.
87997@@ -1133,7 +1150,7 @@ static unsigned int first_packet_length(struct sock *sk)
87998 udp_lib_checksum_complete(skb)) {
87999 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88000 IS_UDPLITE(sk));
88001- atomic_inc(&sk->sk_drops);
88002+ atomic_inc_unchecked(&sk->sk_drops);
88003 __skb_unlink(skb, rcvq);
88004 __skb_queue_tail(&list_kill, skb);
88005 }
88006@@ -1219,6 +1236,10 @@ try_again:
88007 if (!skb)
88008 goto out;
88009
88010+ err = gr_search_udp_recvmsg(sk, skb);
88011+ if (err)
88012+ goto out_free;
88013+
88014 ulen = skb->len - sizeof(struct udphdr);
88015 copied = len;
88016 if (copied > ulen)
88017@@ -1252,7 +1273,7 @@ try_again:
88018 if (unlikely(err)) {
88019 trace_kfree_skb(skb, udp_recvmsg);
88020 if (!peeked) {
88021- atomic_inc(&sk->sk_drops);
88022+ atomic_inc_unchecked(&sk->sk_drops);
88023 UDP_INC_STATS_USER(sock_net(sk),
88024 UDP_MIB_INERRORS, is_udplite);
88025 }
88026@@ -1535,7 +1556,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88027
88028 drop:
88029 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88030- atomic_inc(&sk->sk_drops);
88031+ atomic_inc_unchecked(&sk->sk_drops);
88032 kfree_skb(skb);
88033 return -1;
88034 }
88035@@ -1554,7 +1575,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88036 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88037
88038 if (!skb1) {
88039- atomic_inc(&sk->sk_drops);
88040+ atomic_inc_unchecked(&sk->sk_drops);
88041 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88042 IS_UDPLITE(sk));
88043 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88044@@ -1723,6 +1744,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88045 goto csum_error;
88046
88047 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88048+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88049+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88050+#endif
88051 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
88052
88053 /*
88054@@ -2152,7 +2176,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
88055 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
88056 0, sock_i_ino(sp),
88057 atomic_read(&sp->sk_refcnt), sp,
88058- atomic_read(&sp->sk_drops), len);
88059+ atomic_read_unchecked(&sp->sk_drops), len);
88060 }
88061
88062 int udp4_seq_show(struct seq_file *seq, void *v)
88063diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
88064index 9a459be..086b866 100644
88065--- a/net/ipv4/xfrm4_policy.c
88066+++ b/net/ipv4/xfrm4_policy.c
88067@@ -264,19 +264,18 @@ static struct ctl_table xfrm4_policy_table[] = {
88068
88069 static int __net_init xfrm4_net_init(struct net *net)
88070 {
88071- struct ctl_table *table;
88072+ ctl_table_no_const *table = NULL;
88073 struct ctl_table_header *hdr;
88074
88075- table = xfrm4_policy_table;
88076 if (!net_eq(net, &init_net)) {
88077- table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88078+ table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
88079 if (!table)
88080 goto err_alloc;
88081
88082 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
88083- }
88084-
88085- hdr = register_net_sysctl(net, "net/ipv4", table);
88086+ hdr = register_net_sysctl(net, "net/ipv4", table);
88087+ } else
88088+ hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
88089 if (!hdr)
88090 goto err_reg;
88091
88092@@ -284,8 +283,7 @@ static int __net_init xfrm4_net_init(struct net *net)
88093 return 0;
88094
88095 err_reg:
88096- if (!net_eq(net, &init_net))
88097- kfree(table);
88098+ kfree(table);
88099 err_alloc:
88100 return -ENOMEM;
88101 }
88102diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
88103index 50a4c7c..50a27e6 100644
88104--- a/net/ipv6/addrconf.c
88105+++ b/net/ipv6/addrconf.c
88106@@ -2274,7 +2274,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
88107 p.iph.ihl = 5;
88108 p.iph.protocol = IPPROTO_IPV6;
88109 p.iph.ttl = 64;
88110- ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
88111+ ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
88112
88113 if (ops->ndo_do_ioctl) {
88114 mm_segment_t oldfs = get_fs();
88115@@ -4412,7 +4412,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
88116 int *valp = ctl->data;
88117 int val = *valp;
88118 loff_t pos = *ppos;
88119- ctl_table lctl;
88120+ ctl_table_no_const lctl;
88121 int ret;
88122
88123 /*
88124@@ -4494,7 +4494,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
88125 int *valp = ctl->data;
88126 int val = *valp;
88127 loff_t pos = *ppos;
88128- ctl_table lctl;
88129+ ctl_table_no_const lctl;
88130 int ret;
88131
88132 /*
88133diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
88134index fff5bdd..15194fb 100644
88135--- a/net/ipv6/icmp.c
88136+++ b/net/ipv6/icmp.c
88137@@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
88138
88139 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
88140 {
88141- struct ctl_table *table;
88142+ ctl_table_no_const *table;
88143
88144 table = kmemdup(ipv6_icmp_table_template,
88145 sizeof(ipv6_icmp_table_template),
88146diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
88147index 95d13c7..791fe2f 100644
88148--- a/net/ipv6/ip6_gre.c
88149+++ b/net/ipv6/ip6_gre.c
88150@@ -73,7 +73,7 @@ struct ip6gre_net {
88151 struct net_device *fb_tunnel_dev;
88152 };
88153
88154-static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
88155+static struct rtnl_link_ops ip6gre_link_ops;
88156 static int ip6gre_tunnel_init(struct net_device *dev);
88157 static void ip6gre_tunnel_setup(struct net_device *dev);
88158 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
88159@@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
88160 }
88161
88162
88163-static struct inet6_protocol ip6gre_protocol __read_mostly = {
88164+static struct inet6_protocol ip6gre_protocol = {
88165 .handler = ip6gre_rcv,
88166 .err_handler = ip6gre_err,
88167 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
88168@@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
88169 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
88170 };
88171
88172-static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88173+static struct rtnl_link_ops ip6gre_link_ops = {
88174 .kind = "ip6gre",
88175 .maxtype = IFLA_GRE_MAX,
88176 .policy = ip6gre_policy,
88177@@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
88178 .fill_info = ip6gre_fill_info,
88179 };
88180
88181-static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
88182+static struct rtnl_link_ops ip6gre_tap_ops = {
88183 .kind = "ip6gretap",
88184 .maxtype = IFLA_GRE_MAX,
88185 .policy = ip6gre_policy,
88186diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c
88187index 851fdae..9d4d1fd 100644
88188--- a/net/ipv6/ip6_output.c
88189+++ b/net/ipv6/ip6_output.c
88190@@ -822,11 +822,17 @@ static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
88191 const struct flowi6 *fl6)
88192 {
88193 struct ipv6_pinfo *np = inet6_sk(sk);
88194- struct rt6_info *rt = (struct rt6_info *)dst;
88195+ struct rt6_info *rt;
88196
88197 if (!dst)
88198 goto out;
88199
88200+ if (dst->ops->family != AF_INET6) {
88201+ dst_release(dst);
88202+ return NULL;
88203+ }
88204+
88205+ rt = (struct rt6_info *)dst;
88206 /* Yes, checking route validity in not connected
88207 * case is not very simple. Take into account,
88208 * that we do not support routing by source, TOS,
88209diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
88210index fff83cb..82d49dd 100644
88211--- a/net/ipv6/ip6_tunnel.c
88212+++ b/net/ipv6/ip6_tunnel.c
88213@@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
88214
88215 static int ip6_tnl_dev_init(struct net_device *dev);
88216 static void ip6_tnl_dev_setup(struct net_device *dev);
88217-static struct rtnl_link_ops ip6_link_ops __read_mostly;
88218+static struct rtnl_link_ops ip6_link_ops;
88219
88220 static int ip6_tnl_net_id __read_mostly;
88221 struct ip6_tnl_net {
88222@@ -1684,7 +1684,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
88223 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
88224 };
88225
88226-static struct rtnl_link_ops ip6_link_ops __read_mostly = {
88227+static struct rtnl_link_ops ip6_link_ops = {
88228 .kind = "ip6tnl",
88229 .maxtype = IFLA_IPTUN_MAX,
88230 .policy = ip6_tnl_policy,
88231diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
88232index d1e2e8e..51c19ae 100644
88233--- a/net/ipv6/ipv6_sockglue.c
88234+++ b/net/ipv6/ipv6_sockglue.c
88235@@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
88236 if (sk->sk_type != SOCK_STREAM)
88237 return -ENOPROTOOPT;
88238
88239- msg.msg_control = optval;
88240+ msg.msg_control = (void __force_kernel *)optval;
88241 msg.msg_controllen = len;
88242 msg.msg_flags = flags;
88243
88244diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
88245index 341b54a..591e8ed 100644
88246--- a/net/ipv6/netfilter/ip6_tables.c
88247+++ b/net/ipv6/netfilter/ip6_tables.c
88248@@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
88249 #endif
88250
88251 static int get_info(struct net *net, void __user *user,
88252- const int *len, int compat)
88253+ int len, int compat)
88254 {
88255 char name[XT_TABLE_MAXNAMELEN];
88256 struct xt_table *t;
88257 int ret;
88258
88259- if (*len != sizeof(struct ip6t_getinfo)) {
88260- duprintf("length %u != %zu\n", *len,
88261+ if (len != sizeof(struct ip6t_getinfo)) {
88262+ duprintf("length %u != %zu\n", len,
88263 sizeof(struct ip6t_getinfo));
88264 return -EINVAL;
88265 }
88266@@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
88267 info.size = private->size;
88268 strcpy(info.name, name);
88269
88270- if (copy_to_user(user, &info, *len) != 0)
88271+ if (copy_to_user(user, &info, len) != 0)
88272 ret = -EFAULT;
88273 else
88274 ret = 0;
88275@@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88276
88277 switch (cmd) {
88278 case IP6T_SO_GET_INFO:
88279- ret = get_info(sock_net(sk), user, len, 1);
88280+ ret = get_info(sock_net(sk), user, *len, 1);
88281 break;
88282 case IP6T_SO_GET_ENTRIES:
88283 ret = compat_get_entries(sock_net(sk), user, len);
88284@@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
88285
88286 switch (cmd) {
88287 case IP6T_SO_GET_INFO:
88288- ret = get_info(sock_net(sk), user, len, 0);
88289+ ret = get_info(sock_net(sk), user, *len, 0);
88290 break;
88291
88292 case IP6T_SO_GET_ENTRIES:
88293diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
88294index 6700069..1e50f42 100644
88295--- a/net/ipv6/netfilter/nf_conntrack_reasm.c
88296+++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
88297@@ -89,12 +89,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
88298
88299 static int nf_ct_frag6_sysctl_register(struct net *net)
88300 {
88301- struct ctl_table *table;
88302+ ctl_table_no_const *table = NULL;
88303 struct ctl_table_header *hdr;
88304
88305- table = nf_ct_frag6_sysctl_table;
88306 if (!net_eq(net, &init_net)) {
88307- table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
88308+ table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
88309 GFP_KERNEL);
88310 if (table == NULL)
88311 goto err_alloc;
88312@@ -102,9 +101,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88313 table[0].data = &net->nf_frag.frags.timeout;
88314 table[1].data = &net->nf_frag.frags.low_thresh;
88315 table[2].data = &net->nf_frag.frags.high_thresh;
88316- }
88317-
88318- hdr = register_net_sysctl(net, "net/netfilter", table);
88319+ hdr = register_net_sysctl(net, "net/netfilter", table);
88320+ } else
88321+ hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
88322 if (hdr == NULL)
88323 goto err_reg;
88324
88325@@ -112,8 +111,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
88326 return 0;
88327
88328 err_reg:
88329- if (!net_eq(net, &init_net))
88330- kfree(table);
88331+ kfree(table);
88332 err_alloc:
88333 return -ENOMEM;
88334 }
88335diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
88336index 330b5e7..796fbf1 100644
88337--- a/net/ipv6/raw.c
88338+++ b/net/ipv6/raw.c
88339@@ -378,7 +378,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
88340 {
88341 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
88342 skb_checksum_complete(skb)) {
88343- atomic_inc(&sk->sk_drops);
88344+ atomic_inc_unchecked(&sk->sk_drops);
88345 kfree_skb(skb);
88346 return NET_RX_DROP;
88347 }
88348@@ -406,7 +406,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88349 struct raw6_sock *rp = raw6_sk(sk);
88350
88351 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
88352- atomic_inc(&sk->sk_drops);
88353+ atomic_inc_unchecked(&sk->sk_drops);
88354 kfree_skb(skb);
88355 return NET_RX_DROP;
88356 }
88357@@ -430,7 +430,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
88358
88359 if (inet->hdrincl) {
88360 if (skb_checksum_complete(skb)) {
88361- atomic_inc(&sk->sk_drops);
88362+ atomic_inc_unchecked(&sk->sk_drops);
88363 kfree_skb(skb);
88364 return NET_RX_DROP;
88365 }
88366@@ -603,7 +603,7 @@ out:
88367 return err;
88368 }
88369
88370-static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
88371+static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
88372 struct flowi6 *fl6, struct dst_entry **dstp,
88373 unsigned int flags)
88374 {
88375@@ -915,12 +915,15 @@ do_confirm:
88376 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
88377 char __user *optval, int optlen)
88378 {
88379+ struct icmp6_filter filter;
88380+
88381 switch (optname) {
88382 case ICMPV6_FILTER:
88383 if (optlen > sizeof(struct icmp6_filter))
88384 optlen = sizeof(struct icmp6_filter);
88385- if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
88386+ if (copy_from_user(&filter, optval, optlen))
88387 return -EFAULT;
88388+ raw6_sk(sk)->filter = filter;
88389 return 0;
88390 default:
88391 return -ENOPROTOOPT;
88392@@ -933,6 +936,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88393 char __user *optval, int __user *optlen)
88394 {
88395 int len;
88396+ struct icmp6_filter filter;
88397
88398 switch (optname) {
88399 case ICMPV6_FILTER:
88400@@ -944,7 +948,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
88401 len = sizeof(struct icmp6_filter);
88402 if (put_user(len, optlen))
88403 return -EFAULT;
88404- if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
88405+ filter = raw6_sk(sk)->filter;
88406+ if (len > sizeof filter || copy_to_user(optval, &filter, len))
88407 return -EFAULT;
88408 return 0;
88409 default:
88410@@ -1252,7 +1257,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
88411 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
88412 0,
88413 sock_i_ino(sp),
88414- atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
88415+ atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
88416 }
88417
88418 static int raw6_seq_show(struct seq_file *seq, void *v)
88419diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
88420index 0ba10e5..c14a4f6 100644
88421--- a/net/ipv6/reassembly.c
88422+++ b/net/ipv6/reassembly.c
88423@@ -602,12 +602,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
88424
88425 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88426 {
88427- struct ctl_table *table;
88428+ ctl_table_no_const *table = NULL;
88429 struct ctl_table_header *hdr;
88430
88431- table = ip6_frags_ns_ctl_table;
88432 if (!net_eq(net, &init_net)) {
88433- table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88434+ table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
88435 if (table == NULL)
88436 goto err_alloc;
88437
88438@@ -618,9 +617,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88439 /* Don't export sysctls to unprivileged users */
88440 if (net->user_ns != &init_user_ns)
88441 table[0].procname = NULL;
88442- }
88443+ hdr = register_net_sysctl(net, "net/ipv6", table);
88444+ } else
88445+ hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
88446
88447- hdr = register_net_sysctl(net, "net/ipv6", table);
88448 if (hdr == NULL)
88449 goto err_reg;
88450
88451@@ -628,8 +628,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
88452 return 0;
88453
88454 err_reg:
88455- if (!net_eq(net, &init_net))
88456- kfree(table);
88457+ kfree(table);
88458 err_alloc:
88459 return -ENOMEM;
88460 }
88461diff --git a/net/ipv6/route.c b/net/ipv6/route.c
88462index e5fe004..9fe3e8e 100644
88463--- a/net/ipv6/route.c
88464+++ b/net/ipv6/route.c
88465@@ -2881,7 +2881,7 @@ ctl_table ipv6_route_table_template[] = {
88466
88467 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
88468 {
88469- struct ctl_table *table;
88470+ ctl_table_no_const *table;
88471
88472 table = kmemdup(ipv6_route_table_template,
88473 sizeof(ipv6_route_table_template),
88474diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
88475index 02f96dc..4a5a6e5 100644
88476--- a/net/ipv6/sit.c
88477+++ b/net/ipv6/sit.c
88478@@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
88479 static void ipip6_dev_free(struct net_device *dev);
88480 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
88481 __be32 *v4dst);
88482-static struct rtnl_link_ops sit_link_ops __read_mostly;
88483+static struct rtnl_link_ops sit_link_ops;
88484
88485 static int sit_net_id __read_mostly;
88486 struct sit_net {
88487@@ -1486,7 +1486,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
88488 #endif
88489 };
88490
88491-static struct rtnl_link_ops sit_link_ops __read_mostly = {
88492+static struct rtnl_link_ops sit_link_ops = {
88493 .kind = "sit",
88494 .maxtype = IFLA_IPTUN_MAX,
88495 .policy = ipip6_policy,
88496diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
88497index e85c48b..b8268d3 100644
88498--- a/net/ipv6/sysctl_net_ipv6.c
88499+++ b/net/ipv6/sysctl_net_ipv6.c
88500@@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
88501
88502 static int __net_init ipv6_sysctl_net_init(struct net *net)
88503 {
88504- struct ctl_table *ipv6_table;
88505+ ctl_table_no_const *ipv6_table;
88506 struct ctl_table *ipv6_route_table;
88507 struct ctl_table *ipv6_icmp_table;
88508 int err;
88509diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
88510index 0fce928..c52a518 100644
88511--- a/net/ipv6/tcp_ipv6.c
88512+++ b/net/ipv6/tcp_ipv6.c
88513@@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
88514 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
88515 }
88516
88517+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88518+extern int grsec_enable_blackhole;
88519+#endif
88520+
88521 static void tcp_v6_hash(struct sock *sk)
88522 {
88523 if (sk->sk_state != TCP_CLOSE) {
88524@@ -1446,6 +1450,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
88525 return 0;
88526
88527 reset:
88528+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88529+ if (!grsec_enable_blackhole)
88530+#endif
88531 tcp_v6_send_reset(sk, skb);
88532 discard:
88533 if (opt_skb)
88534@@ -1527,12 +1534,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
88535 TCP_SKB_CB(skb)->sacked = 0;
88536
88537 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
88538- if (!sk)
88539+ if (!sk) {
88540+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88541+ ret = 1;
88542+#endif
88543 goto no_tcp_socket;
88544+ }
88545
88546 process:
88547- if (sk->sk_state == TCP_TIME_WAIT)
88548+ if (sk->sk_state == TCP_TIME_WAIT) {
88549+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88550+ ret = 2;
88551+#endif
88552 goto do_time_wait;
88553+ }
88554
88555 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
88556 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
88557@@ -1581,6 +1596,10 @@ no_tcp_socket:
88558 bad_packet:
88559 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
88560 } else {
88561+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88562+ if (!grsec_enable_blackhole || (ret == 1 &&
88563+ (skb->dev->flags & IFF_LOOPBACK)))
88564+#endif
88565 tcp_v6_send_reset(NULL, skb);
88566 }
88567
88568diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
88569index 27f0f8e..949e7ee 100644
88570--- a/net/ipv6/udp.c
88571+++ b/net/ipv6/udp.c
88572@@ -52,6 +52,10 @@
88573 #include <trace/events/skb.h>
88574 #include "udp_impl.h"
88575
88576+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88577+extern int grsec_enable_blackhole;
88578+#endif
88579+
88580 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
88581 {
88582 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
88583@@ -419,7 +423,7 @@ try_again:
88584 if (unlikely(err)) {
88585 trace_kfree_skb(skb, udpv6_recvmsg);
88586 if (!peeked) {
88587- atomic_inc(&sk->sk_drops);
88588+ atomic_inc_unchecked(&sk->sk_drops);
88589 if (is_udp4)
88590 UDP_INC_STATS_USER(sock_net(sk),
88591 UDP_MIB_INERRORS,
88592@@ -657,7 +661,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
88593 return rc;
88594 drop:
88595 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
88596- atomic_inc(&sk->sk_drops);
88597+ atomic_inc_unchecked(&sk->sk_drops);
88598 kfree_skb(skb);
88599 return -1;
88600 }
88601@@ -715,7 +719,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
88602 if (likely(skb1 == NULL))
88603 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
88604 if (!skb1) {
88605- atomic_inc(&sk->sk_drops);
88606+ atomic_inc_unchecked(&sk->sk_drops);
88607 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
88608 IS_UDPLITE(sk));
88609 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
88610@@ -852,6 +856,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
88611 goto discard;
88612
88613 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
88614+#ifdef CONFIG_GRKERNSEC_BLACKHOLE
88615+ if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
88616+#endif
88617 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
88618
88619 kfree_skb(skb);
88620@@ -1377,7 +1384,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
88621 0,
88622 sock_i_ino(sp),
88623 atomic_read(&sp->sk_refcnt), sp,
88624- atomic_read(&sp->sk_drops));
88625+ atomic_read_unchecked(&sp->sk_drops));
88626 }
88627
88628 int udp6_seq_show(struct seq_file *seq, void *v)
88629diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
88630index 23ed03d..465a71d 100644
88631--- a/net/ipv6/xfrm6_policy.c
88632+++ b/net/ipv6/xfrm6_policy.c
88633@@ -324,19 +324,19 @@ static struct ctl_table xfrm6_policy_table[] = {
88634
88635 static int __net_init xfrm6_net_init(struct net *net)
88636 {
88637- struct ctl_table *table;
88638+ ctl_table_no_const *table = NULL;
88639 struct ctl_table_header *hdr;
88640
88641- table = xfrm6_policy_table;
88642 if (!net_eq(net, &init_net)) {
88643- table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88644+ table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
88645 if (!table)
88646 goto err_alloc;
88647
88648 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
88649- }
88650+ hdr = register_net_sysctl(net, "net/ipv6", table);
88651+ } else
88652+ hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
88653
88654- hdr = register_net_sysctl(net, "net/ipv6", table);
88655 if (!hdr)
88656 goto err_reg;
88657
88658@@ -344,8 +344,7 @@ static int __net_init xfrm6_net_init(struct net *net)
88659 return 0;
88660
88661 err_reg:
88662- if (!net_eq(net, &init_net))
88663- kfree(table);
88664+ kfree(table);
88665 err_alloc:
88666 return -ENOMEM;
88667 }
88668diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
88669index 362ba47..66196f4 100644
88670--- a/net/irda/ircomm/ircomm_tty.c
88671+++ b/net/irda/ircomm/ircomm_tty.c
88672@@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88673 add_wait_queue(&port->open_wait, &wait);
88674
88675 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
88676- __FILE__, __LINE__, tty->driver->name, port->count);
88677+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88678
88679 spin_lock_irqsave(&port->lock, flags);
88680 if (!tty_hung_up_p(filp))
88681- port->count--;
88682+ atomic_dec(&port->count);
88683 port->blocked_open++;
88684 spin_unlock_irqrestore(&port->lock, flags);
88685
88686@@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88687 }
88688
88689 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
88690- __FILE__, __LINE__, tty->driver->name, port->count);
88691+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88692
88693 schedule();
88694 }
88695@@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
88696
88697 spin_lock_irqsave(&port->lock, flags);
88698 if (!tty_hung_up_p(filp))
88699- port->count++;
88700+ atomic_inc(&port->count);
88701 port->blocked_open--;
88702 spin_unlock_irqrestore(&port->lock, flags);
88703
88704 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
88705- __FILE__, __LINE__, tty->driver->name, port->count);
88706+ __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
88707
88708 if (!retval)
88709 port->flags |= ASYNC_NORMAL_ACTIVE;
88710@@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
88711
88712 /* ++ is not atomic, so this should be protected - Jean II */
88713 spin_lock_irqsave(&self->port.lock, flags);
88714- self->port.count++;
88715+ atomic_inc(&self->port.count);
88716 spin_unlock_irqrestore(&self->port.lock, flags);
88717 tty_port_tty_set(&self->port, tty);
88718
88719 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
88720- self->line, self->port.count);
88721+ self->line, atomic_read(&self->port.count));
88722
88723 /* Not really used by us, but lets do it anyway */
88724 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
88725@@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
88726 tty_kref_put(port->tty);
88727 }
88728 port->tty = NULL;
88729- port->count = 0;
88730+ atomic_set(&port->count, 0);
88731 spin_unlock_irqrestore(&port->lock, flags);
88732
88733 wake_up_interruptible(&port->open_wait);
88734@@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
88735 seq_putc(m, '\n');
88736
88737 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
88738- seq_printf(m, "Open count: %d\n", self->port.count);
88739+ seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
88740 seq_printf(m, "Max data size: %d\n", self->max_data_size);
88741 seq_printf(m, "Max header size: %d\n", self->max_header_size);
88742
88743diff --git a/net/irda/irlap_frame.c b/net/irda/irlap_frame.c
88744index 8c00416..9ea0c93 100644
88745--- a/net/irda/irlap_frame.c
88746+++ b/net/irda/irlap_frame.c
88747@@ -544,7 +544,7 @@ static void irlap_recv_discovery_xid_cmd(struct irlap_cb *self,
88748 /*
88749 * We now have some discovery info to deliver!
88750 */
88751- discovery = kmalloc(sizeof(discovery_t), GFP_ATOMIC);
88752+ discovery = kzalloc(sizeof(discovery_t), GFP_ATOMIC);
88753 if (!discovery) {
88754 IRDA_WARNING("%s: unable to malloc!\n", __func__);
88755 return;
88756diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
88757index 206ce6d..cfb27cd 100644
88758--- a/net/iucv/af_iucv.c
88759+++ b/net/iucv/af_iucv.c
88760@@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
88761
88762 write_lock_bh(&iucv_sk_list.lock);
88763
88764- sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
88765+ sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88766 while (__iucv_get_sock_by_name(name)) {
88767 sprintf(name, "%08x",
88768- atomic_inc_return(&iucv_sk_list.autobind_name));
88769+ atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
88770 }
88771
88772 write_unlock_bh(&iucv_sk_list.lock);
88773diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
88774index 4fe76ff..426a904 100644
88775--- a/net/iucv/iucv.c
88776+++ b/net/iucv/iucv.c
88777@@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
88778 return NOTIFY_OK;
88779 }
88780
88781-static struct notifier_block __refdata iucv_cpu_notifier = {
88782+static struct notifier_block iucv_cpu_notifier = {
88783 .notifier_call = iucv_cpu_notify,
88784 };
88785
88786diff --git a/net/key/af_key.c b/net/key/af_key.c
88787index 5b1e5af..1b929e7 100644
88788--- a/net/key/af_key.c
88789+++ b/net/key/af_key.c
88790@@ -1710,6 +1710,7 @@ static int key_notify_sa_flush(const struct km_event *c)
88791 hdr->sadb_msg_version = PF_KEY_V2;
88792 hdr->sadb_msg_errno = (uint8_t) 0;
88793 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
88794+ hdr->sadb_msg_reserved = 0;
88795
88796 pfkey_broadcast(skb, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net);
88797
88798@@ -2695,6 +2696,7 @@ static int key_notify_policy_flush(const struct km_event *c)
88799 hdr->sadb_msg_errno = (uint8_t) 0;
88800 hdr->sadb_msg_satype = SADB_SATYPE_UNSPEC;
88801 hdr->sadb_msg_len = (sizeof(struct sadb_msg) / sizeof(uint64_t));
88802+ hdr->sadb_msg_reserved = 0;
88803 pfkey_broadcast(skb_out, GFP_ATOMIC, BROADCAST_ALL, NULL, c->net);
88804 return 0;
88805
88806@@ -3041,10 +3043,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
88807 static u32 get_acqseq(void)
88808 {
88809 u32 res;
88810- static atomic_t acqseq;
88811+ static atomic_unchecked_t acqseq;
88812
88813 do {
88814- res = atomic_inc_return(&acqseq);
88815+ res = atomic_inc_return_unchecked(&acqseq);
88816 } while (!res);
88817 return res;
88818 }
88819diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
88820index 843d8c4..cb04fa1 100644
88821--- a/net/mac80211/cfg.c
88822+++ b/net/mac80211/cfg.c
88823@@ -799,7 +799,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
88824 ret = ieee80211_vif_use_channel(sdata, chandef,
88825 IEEE80211_CHANCTX_EXCLUSIVE);
88826 }
88827- } else if (local->open_count == local->monitors) {
88828+ } else if (local_read(&local->open_count) == local->monitors) {
88829 local->_oper_channel = chandef->chan;
88830 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
88831 ieee80211_hw_config(local, 0);
88832@@ -2834,7 +2834,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
88833 else
88834 local->probe_req_reg--;
88835
88836- if (!local->open_count)
88837+ if (!local_read(&local->open_count))
88838 break;
88839
88840 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
88841@@ -3297,8 +3297,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
88842 if (chanctx_conf) {
88843 *chandef = chanctx_conf->def;
88844 ret = 0;
88845- } else if (local->open_count > 0 &&
88846- local->open_count == local->monitors &&
88847+ } else if (local_read(&local->open_count) > 0 &&
88848+ local_read(&local->open_count) == local->monitors &&
88849 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
88850 if (local->use_chanctx)
88851 *chandef = local->monitor_chandef;
88852diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
88853index 5672533..6738c93 100644
88854--- a/net/mac80211/ieee80211_i.h
88855+++ b/net/mac80211/ieee80211_i.h
88856@@ -28,6 +28,7 @@
88857 #include <net/ieee80211_radiotap.h>
88858 #include <net/cfg80211.h>
88859 #include <net/mac80211.h>
88860+#include <asm/local.h>
88861 #include "key.h"
88862 #include "sta_info.h"
88863 #include "debug.h"
88864@@ -897,7 +898,7 @@ struct ieee80211_local {
88865 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
88866 spinlock_t queue_stop_reason_lock;
88867
88868- int open_count;
88869+ local_t open_count;
88870 int monitors, cooked_mntrs;
88871 /* number of interfaces with corresponding FIF_ flags */
88872 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
88873diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
88874index 9cbebc2..14879bb 100644
88875--- a/net/mac80211/iface.c
88876+++ b/net/mac80211/iface.c
88877@@ -495,7 +495,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88878 break;
88879 }
88880
88881- if (local->open_count == 0) {
88882+ if (local_read(&local->open_count) == 0) {
88883 res = drv_start(local);
88884 if (res)
88885 goto err_del_bss;
88886@@ -540,7 +540,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88887 break;
88888 }
88889
88890- if (local->monitors == 0 && local->open_count == 0) {
88891+ if (local->monitors == 0 && local_read(&local->open_count) == 0) {
88892 res = ieee80211_add_virtual_monitor(local);
88893 if (res)
88894 goto err_stop;
88895@@ -649,7 +649,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88896 atomic_inc(&local->iff_promiscs);
88897
88898 if (coming_up)
88899- local->open_count++;
88900+ local_inc(&local->open_count);
88901
88902 if (hw_reconf_flags)
88903 ieee80211_hw_config(local, hw_reconf_flags);
88904@@ -663,7 +663,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
88905 err_del_interface:
88906 drv_remove_interface(local, sdata);
88907 err_stop:
88908- if (!local->open_count)
88909+ if (!local_read(&local->open_count))
88910 drv_stop(local);
88911 err_del_bss:
88912 sdata->bss = NULL;
88913@@ -806,7 +806,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88914 }
88915
88916 if (going_down)
88917- local->open_count--;
88918+ local_dec(&local->open_count);
88919
88920 switch (sdata->vif.type) {
88921 case NL80211_IFTYPE_AP_VLAN:
88922@@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88923
88924 ieee80211_recalc_ps(local, -1);
88925
88926- if (local->open_count == 0) {
88927+ if (local_read(&local->open_count) == 0) {
88928 if (local->ops->napi_poll)
88929 napi_disable(&local->napi);
88930 ieee80211_clear_tx_pending(local);
88931@@ -897,7 +897,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
88932 }
88933 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
88934
88935- if (local->monitors == local->open_count && local->monitors > 0)
88936+ if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
88937 ieee80211_add_virtual_monitor(local);
88938 }
88939
88940diff --git a/net/mac80211/main.c b/net/mac80211/main.c
88941index 1a8591b..ef5db54 100644
88942--- a/net/mac80211/main.c
88943+++ b/net/mac80211/main.c
88944@@ -180,7 +180,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
88945 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
88946 IEEE80211_CONF_CHANGE_POWER);
88947
88948- if (changed && local->open_count) {
88949+ if (changed && local_read(&local->open_count)) {
88950 ret = drv_config(local, changed);
88951 /*
88952 * Goal:
88953diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
88954index 835584c..be46e67 100644
88955--- a/net/mac80211/pm.c
88956+++ b/net/mac80211/pm.c
88957@@ -33,7 +33,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88958 struct sta_info *sta;
88959 struct ieee80211_chanctx *ctx;
88960
88961- if (!local->open_count)
88962+ if (!local_read(&local->open_count))
88963 goto suspend;
88964
88965 ieee80211_scan_cancel(local);
88966@@ -75,7 +75,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88967 cancel_work_sync(&local->dynamic_ps_enable_work);
88968 del_timer_sync(&local->dynamic_ps_timer);
88969
88970- local->wowlan = wowlan && local->open_count;
88971+ local->wowlan = wowlan && local_read(&local->open_count);
88972 if (local->wowlan) {
88973 int err = drv_suspend(local, wowlan);
88974 if (err < 0) {
88975@@ -214,7 +214,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
88976 mutex_unlock(&local->chanctx_mtx);
88977
88978 /* stop hardware - this must stop RX */
88979- if (local->open_count)
88980+ if (local_read(&local->open_count))
88981 ieee80211_stop_device(local);
88982
88983 suspend:
88984diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
88985index dd88381..eef4dd6 100644
88986--- a/net/mac80211/rate.c
88987+++ b/net/mac80211/rate.c
88988@@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
88989
88990 ASSERT_RTNL();
88991
88992- if (local->open_count)
88993+ if (local_read(&local->open_count))
88994 return -EBUSY;
88995
88996 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
88997diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
88998index c97a065..ff61928 100644
88999--- a/net/mac80211/rc80211_pid_debugfs.c
89000+++ b/net/mac80211/rc80211_pid_debugfs.c
89001@@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
89002
89003 spin_unlock_irqrestore(&events->lock, status);
89004
89005- if (copy_to_user(buf, pb, p))
89006+ if (p > sizeof(pb) || copy_to_user(buf, pb, p))
89007 return -EFAULT;
89008
89009 return p;
89010diff --git a/net/mac80211/util.c b/net/mac80211/util.c
89011index 0f38f43..e53d4a8 100644
89012--- a/net/mac80211/util.c
89013+++ b/net/mac80211/util.c
89014@@ -1388,7 +1388,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
89015 }
89016 #endif
89017 /* everything else happens only if HW was up & running */
89018- if (!local->open_count)
89019+ if (!local_read(&local->open_count))
89020 goto wake_up;
89021
89022 /*
89023diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
89024index 56d22ca..87c778f 100644
89025--- a/net/netfilter/Kconfig
89026+++ b/net/netfilter/Kconfig
89027@@ -958,6 +958,16 @@ config NETFILTER_XT_MATCH_ESP
89028
89029 To compile it as a module, choose M here. If unsure, say N.
89030
89031+config NETFILTER_XT_MATCH_GRADM
89032+ tristate '"gradm" match support'
89033+ depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
89034+ depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
89035+ ---help---
89036+ The gradm match allows to match on grsecurity RBAC being enabled.
89037+ It is useful when iptables rules are applied early on bootup to
89038+ prevent connections to the machine (except from a trusted host)
89039+ while the RBAC system is disabled.
89040+
89041 config NETFILTER_XT_MATCH_HASHLIMIT
89042 tristate '"hashlimit" match support'
89043 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
89044diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
89045index a1abf87..dbcb7ee 100644
89046--- a/net/netfilter/Makefile
89047+++ b/net/netfilter/Makefile
89048@@ -112,6 +112,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
89049 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
89050 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
89051 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
89052+obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
89053 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
89054 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
89055 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
89056diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
89057index 1ba9dbc..e39f4ca 100644
89058--- a/net/netfilter/ipset/ip_set_core.c
89059+++ b/net/netfilter/ipset/ip_set_core.c
89060@@ -1801,7 +1801,7 @@ done:
89061 return ret;
89062 }
89063
89064-static struct nf_sockopt_ops so_set __read_mostly = {
89065+static struct nf_sockopt_ops so_set = {
89066 .pf = PF_INET,
89067 .get_optmin = SO_IP_SET,
89068 .get_optmax = SO_IP_SET + 1,
89069diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
89070index 704e514..d644cc2 100644
89071--- a/net/netfilter/ipvs/ip_vs_conn.c
89072+++ b/net/netfilter/ipvs/ip_vs_conn.c
89073@@ -551,7 +551,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
89074 /* Increase the refcnt counter of the dest */
89075 atomic_inc(&dest->refcnt);
89076
89077- conn_flags = atomic_read(&dest->conn_flags);
89078+ conn_flags = atomic_read_unchecked(&dest->conn_flags);
89079 if (cp->protocol != IPPROTO_UDP)
89080 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
89081 flags = cp->flags;
89082@@ -895,7 +895,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
89083 atomic_set(&cp->refcnt, 1);
89084
89085 atomic_set(&cp->n_control, 0);
89086- atomic_set(&cp->in_pkts, 0);
89087+ atomic_set_unchecked(&cp->in_pkts, 0);
89088
89089 atomic_inc(&ipvs->conn_count);
89090 if (flags & IP_VS_CONN_F_NO_CPORT)
89091@@ -1174,7 +1174,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
89092
89093 /* Don't drop the entry if its number of incoming packets is not
89094 located in [0, 8] */
89095- i = atomic_read(&cp->in_pkts);
89096+ i = atomic_read_unchecked(&cp->in_pkts);
89097 if (i > 8 || i < 0) return 0;
89098
89099 if (!todrop_rate[i]) return 0;
89100diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
89101index 61f49d2..6c8c5bc 100644
89102--- a/net/netfilter/ipvs/ip_vs_core.c
89103+++ b/net/netfilter/ipvs/ip_vs_core.c
89104@@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
89105 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
89106 /* do not touch skb anymore */
89107
89108- atomic_inc(&cp->in_pkts);
89109+ atomic_inc_unchecked(&cp->in_pkts);
89110 ip_vs_conn_put(cp);
89111 return ret;
89112 }
89113@@ -1689,7 +1689,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
89114 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
89115 pkts = sysctl_sync_threshold(ipvs);
89116 else
89117- pkts = atomic_add_return(1, &cp->in_pkts);
89118+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89119
89120 if (ipvs->sync_state & IP_VS_STATE_MASTER)
89121 ip_vs_sync_conn(net, cp, pkts);
89122diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
89123index 9e2d1cc..6ed0748 100644
89124--- a/net/netfilter/ipvs/ip_vs_ctl.c
89125+++ b/net/netfilter/ipvs/ip_vs_ctl.c
89126@@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
89127 ip_vs_rs_hash(ipvs, dest);
89128 write_unlock_bh(&ipvs->rs_lock);
89129 }
89130- atomic_set(&dest->conn_flags, conn_flags);
89131+ atomic_set_unchecked(&dest->conn_flags, conn_flags);
89132
89133 /* bind the service */
89134 if (!dest->svc) {
89135@@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
89136 * align with netns init in ip_vs_control_net_init()
89137 */
89138
89139-static struct ctl_table vs_vars[] = {
89140+static ctl_table_no_const vs_vars[] __read_only = {
89141 {
89142 .procname = "amemthresh",
89143 .maxlen = sizeof(int),
89144@@ -2087,7 +2087,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89145 " %-7s %-6d %-10d %-10d\n",
89146 &dest->addr.in6,
89147 ntohs(dest->port),
89148- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89149+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89150 atomic_read(&dest->weight),
89151 atomic_read(&dest->activeconns),
89152 atomic_read(&dest->inactconns));
89153@@ -2098,7 +2098,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
89154 "%-7s %-6d %-10d %-10d\n",
89155 ntohl(dest->addr.ip),
89156 ntohs(dest->port),
89157- ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
89158+ ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
89159 atomic_read(&dest->weight),
89160 atomic_read(&dest->activeconns),
89161 atomic_read(&dest->inactconns));
89162@@ -2562,13 +2562,14 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
89163 struct ip_vs_dest *dest;
89164 struct ip_vs_dest_entry entry;
89165
89166+ memset(&entry, 0, sizeof(entry));
89167 list_for_each_entry(dest, &svc->destinations, n_list) {
89168 if (count >= get->num_dests)
89169 break;
89170
89171 entry.addr = dest->addr.ip;
89172 entry.port = dest->port;
89173- entry.conn_flags = atomic_read(&dest->conn_flags);
89174+ entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
89175 entry.weight = atomic_read(&dest->weight);
89176 entry.u_threshold = dest->u_threshold;
89177 entry.l_threshold = dest->l_threshold;
89178@@ -3104,7 +3105,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
89179 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
89180 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
89181 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
89182- (atomic_read(&dest->conn_flags) &
89183+ (atomic_read_unchecked(&dest->conn_flags) &
89184 IP_VS_CONN_F_FWD_MASK)) ||
89185 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
89186 atomic_read(&dest->weight)) ||
89187@@ -3694,7 +3695,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
89188 {
89189 int idx;
89190 struct netns_ipvs *ipvs = net_ipvs(net);
89191- struct ctl_table *tbl;
89192+ ctl_table_no_const *tbl;
89193
89194 atomic_set(&ipvs->dropentry, 0);
89195 spin_lock_init(&ipvs->dropentry_lock);
89196diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
89197index fdd89b9..bd96aa9 100644
89198--- a/net/netfilter/ipvs/ip_vs_lblc.c
89199+++ b/net/netfilter/ipvs/ip_vs_lblc.c
89200@@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
89201 * IPVS LBLC sysctl table
89202 */
89203 #ifdef CONFIG_SYSCTL
89204-static ctl_table vs_vars_table[] = {
89205+static ctl_table_no_const vs_vars_table[] __read_only = {
89206 {
89207 .procname = "lblc_expiration",
89208 .data = NULL,
89209diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
89210index c03b6a3..8ce3681 100644
89211--- a/net/netfilter/ipvs/ip_vs_lblcr.c
89212+++ b/net/netfilter/ipvs/ip_vs_lblcr.c
89213@@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
89214 * IPVS LBLCR sysctl table
89215 */
89216
89217-static ctl_table vs_vars_table[] = {
89218+static ctl_table_no_const vs_vars_table[] __read_only = {
89219 {
89220 .procname = "lblcr_expiration",
89221 .data = NULL,
89222diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
89223index 44fd10c..2a163b3 100644
89224--- a/net/netfilter/ipvs/ip_vs_sync.c
89225+++ b/net/netfilter/ipvs/ip_vs_sync.c
89226@@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
89227 cp = cp->control;
89228 if (cp) {
89229 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89230- pkts = atomic_add_return(1, &cp->in_pkts);
89231+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89232 else
89233 pkts = sysctl_sync_threshold(ipvs);
89234 ip_vs_sync_conn(net, cp->control, pkts);
89235@@ -758,7 +758,7 @@ control:
89236 if (!cp)
89237 return;
89238 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
89239- pkts = atomic_add_return(1, &cp->in_pkts);
89240+ pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
89241 else
89242 pkts = sysctl_sync_threshold(ipvs);
89243 goto sloop;
89244@@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
89245
89246 if (opt)
89247 memcpy(&cp->in_seq, opt, sizeof(*opt));
89248- atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89249+ atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
89250 cp->state = state;
89251 cp->old_state = cp->state;
89252 /*
89253diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
89254index ee6b7a9..f9a89f6 100644
89255--- a/net/netfilter/ipvs/ip_vs_xmit.c
89256+++ b/net/netfilter/ipvs/ip_vs_xmit.c
89257@@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
89258 else
89259 rc = NF_ACCEPT;
89260 /* do not touch skb anymore */
89261- atomic_inc(&cp->in_pkts);
89262+ atomic_inc_unchecked(&cp->in_pkts);
89263 goto out;
89264 }
89265
89266@@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
89267 else
89268 rc = NF_ACCEPT;
89269 /* do not touch skb anymore */
89270- atomic_inc(&cp->in_pkts);
89271+ atomic_inc_unchecked(&cp->in_pkts);
89272 goto out;
89273 }
89274
89275diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
89276index 2d3030a..7ba1c0a 100644
89277--- a/net/netfilter/nf_conntrack_acct.c
89278+++ b/net/netfilter/nf_conntrack_acct.c
89279@@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
89280 #ifdef CONFIG_SYSCTL
89281 static int nf_conntrack_acct_init_sysctl(struct net *net)
89282 {
89283- struct ctl_table *table;
89284+ ctl_table_no_const *table;
89285
89286 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
89287 GFP_KERNEL);
89288diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
89289index c8e001a..f842a8b 100644
89290--- a/net/netfilter/nf_conntrack_core.c
89291+++ b/net/netfilter/nf_conntrack_core.c
89292@@ -1594,6 +1594,10 @@ void nf_conntrack_init_end(void)
89293 #define DYING_NULLS_VAL ((1<<30)+1)
89294 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
89295
89296+#ifdef CONFIG_GRKERNSEC_HIDESYM
89297+static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
89298+#endif
89299+
89300 int nf_conntrack_init_net(struct net *net)
89301 {
89302 int ret;
89303@@ -1608,7 +1612,11 @@ int nf_conntrack_init_net(struct net *net)
89304 goto err_stat;
89305 }
89306
89307+#ifdef CONFIG_GRKERNSEC_HIDESYM
89308+ net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
89309+#else
89310 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
89311+#endif
89312 if (!net->ct.slabname) {
89313 ret = -ENOMEM;
89314 goto err_slabname;
89315diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
89316index b5d2eb8..61ef19a 100644
89317--- a/net/netfilter/nf_conntrack_ecache.c
89318+++ b/net/netfilter/nf_conntrack_ecache.c
89319@@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
89320 #ifdef CONFIG_SYSCTL
89321 static int nf_conntrack_event_init_sysctl(struct net *net)
89322 {
89323- struct ctl_table *table;
89324+ ctl_table_no_const *table;
89325
89326 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
89327 GFP_KERNEL);
89328diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
89329index 94b4b98..97cf0ad 100644
89330--- a/net/netfilter/nf_conntrack_helper.c
89331+++ b/net/netfilter/nf_conntrack_helper.c
89332@@ -56,7 +56,7 @@ static struct ctl_table helper_sysctl_table[] = {
89333
89334 static int nf_conntrack_helper_init_sysctl(struct net *net)
89335 {
89336- struct ctl_table *table;
89337+ ctl_table_no_const *table;
89338
89339 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
89340 GFP_KERNEL);
89341diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
89342index 58ab405..50eb8d3 100644
89343--- a/net/netfilter/nf_conntrack_proto.c
89344+++ b/net/netfilter/nf_conntrack_proto.c
89345@@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
89346
89347 static void
89348 nf_ct_unregister_sysctl(struct ctl_table_header **header,
89349- struct ctl_table **table,
89350+ ctl_table_no_const **table,
89351 unsigned int users)
89352 {
89353 if (users > 0)
89354diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
89355index ba65b20..2a4d937 100644
89356--- a/net/netfilter/nf_conntrack_proto_dccp.c
89357+++ b/net/netfilter/nf_conntrack_proto_dccp.c
89358@@ -456,7 +456,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
89359
89360 out_invalid:
89361 if (LOG_INVALID(net, IPPROTO_DCCP))
89362- nf_log_packet(nf_ct_l3num(ct), 0, skb, NULL, NULL, NULL, msg);
89363+ nf_log_packet(nf_ct_l3num(ct), 0, skb, NULL, NULL, NULL, "%s", msg);
89364 return false;
89365 }
89366
89367@@ -613,7 +613,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
89368
89369 out_invalid:
89370 if (LOG_INVALID(net, IPPROTO_DCCP))
89371- nf_log_packet(pf, 0, skb, NULL, NULL, NULL, msg);
89372+ nf_log_packet(pf, 0, skb, NULL, NULL, NULL, "%s", msg);
89373 return -NF_ACCEPT;
89374 }
89375
89376diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
89377index fedee39..d62a93d 100644
89378--- a/net/netfilter/nf_conntrack_standalone.c
89379+++ b/net/netfilter/nf_conntrack_standalone.c
89380@@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
89381
89382 static int nf_conntrack_standalone_init_sysctl(struct net *net)
89383 {
89384- struct ctl_table *table;
89385+ ctl_table_no_const *table;
89386
89387 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
89388 GFP_KERNEL);
89389diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
89390index 902fb0a..87f7fdb 100644
89391--- a/net/netfilter/nf_conntrack_timestamp.c
89392+++ b/net/netfilter/nf_conntrack_timestamp.c
89393@@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
89394 #ifdef CONFIG_SYSCTL
89395 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
89396 {
89397- struct ctl_table *table;
89398+ ctl_table_no_const *table;
89399
89400 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
89401 GFP_KERNEL);
89402diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
89403index 9e31269..bc4c1b7 100644
89404--- a/net/netfilter/nf_log.c
89405+++ b/net/netfilter/nf_log.c
89406@@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
89407
89408 #ifdef CONFIG_SYSCTL
89409 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
89410-static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
89411+static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
89412 static struct ctl_table_header *nf_log_dir_header;
89413
89414 static int nf_log_proc_dostring(ctl_table *table, int write,
89415@@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
89416 rcu_assign_pointer(nf_loggers[tindex], logger);
89417 mutex_unlock(&nf_log_mutex);
89418 } else {
89419+ ctl_table_no_const nf_log_table = *table;
89420+
89421 mutex_lock(&nf_log_mutex);
89422 logger = rcu_dereference_protected(nf_loggers[tindex],
89423 lockdep_is_held(&nf_log_mutex));
89424 if (!logger)
89425- table->data = "NONE";
89426+ nf_log_table.data = "NONE";
89427 else
89428- table->data = logger->name;
89429- r = proc_dostring(table, write, buffer, lenp, ppos);
89430+ nf_log_table.data = logger->name;
89431+ r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
89432 mutex_unlock(&nf_log_mutex);
89433 }
89434
89435diff --git a/net/netfilter/nf_nat_sip.c b/net/netfilter/nf_nat_sip.c
89436index 96ccdf7..dac11f7 100644
89437--- a/net/netfilter/nf_nat_sip.c
89438+++ b/net/netfilter/nf_nat_sip.c
89439@@ -230,9 +230,10 @@ static unsigned int nf_nat_sip(struct sk_buff *skb, unsigned int protoff,
89440 &ct->tuplehash[!dir].tuple.src.u3,
89441 false);
89442 if (!mangle_packet(skb, protoff, dataoff, dptr, datalen,
89443- poff, plen, buffer, buflen))
89444+ poff, plen, buffer, buflen)) {
89445 nf_ct_helper_log(skb, ct, "cannot mangle received");
89446 return NF_DROP;
89447+ }
89448 }
89449
89450 /* The rport= parameter (RFC 3581) contains the port number
89451diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
89452index f042ae5..30ea486 100644
89453--- a/net/netfilter/nf_sockopt.c
89454+++ b/net/netfilter/nf_sockopt.c
89455@@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
89456 }
89457 }
89458
89459- list_add(&reg->list, &nf_sockopts);
89460+ pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
89461 out:
89462 mutex_unlock(&nf_sockopt_mutex);
89463 return ret;
89464@@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
89465 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
89466 {
89467 mutex_lock(&nf_sockopt_mutex);
89468- list_del(&reg->list);
89469+ pax_list_del((struct list_head *)&reg->list);
89470 mutex_unlock(&nf_sockopt_mutex);
89471 }
89472 EXPORT_SYMBOL(nf_unregister_sockopt);
89473diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
89474index f248db5..3778ad9 100644
89475--- a/net/netfilter/nfnetlink_log.c
89476+++ b/net/netfilter/nfnetlink_log.c
89477@@ -72,7 +72,7 @@ struct nfulnl_instance {
89478 };
89479
89480 static DEFINE_SPINLOCK(instances_lock);
89481-static atomic_t global_seq;
89482+static atomic_unchecked_t global_seq;
89483
89484 #define INSTANCE_BUCKETS 16
89485 static struct hlist_head instance_table[INSTANCE_BUCKETS];
89486@@ -536,7 +536,7 @@ __build_packet_message(struct nfulnl_instance *inst,
89487 /* global sequence number */
89488 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
89489 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
89490- htonl(atomic_inc_return(&global_seq))))
89491+ htonl(atomic_inc_return_unchecked(&global_seq))))
89492 goto nla_put_failure;
89493
89494 if (data_len) {
89495diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
89496new file mode 100644
89497index 0000000..c566332
89498--- /dev/null
89499+++ b/net/netfilter/xt_gradm.c
89500@@ -0,0 +1,51 @@
89501+/*
89502+ * gradm match for netfilter
89503